Skip to content

Commit d68b645

Browse files
authored
fix issue 20901: etaCollapse context bound type (#20910)
fixes #20901
2 parents 923a837 + 62605a6 commit d68b645

File tree

5 files changed

+137
-5
lines changed

5 files changed

+137
-5
lines changed

Diff for: compiler/src/dotty/tools/dotc/typer/Typer.scala

+4-3
Original file line numberDiff line numberDiff line change
@@ -2401,13 +2401,14 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
24012401

24022402
def typedContextBoundTypeTree(tree: untpd.ContextBoundTypeTree)(using Context): Tree =
24032403
val tycon = typedType(tree.tycon)
2404-
val tyconSplice = untpd.TypedSplice(tycon)
2404+
def spliced(tree: Tree) = untpd.TypedSplice(tree)
24052405
val tparam = untpd.Ident(tree.paramName).withSpan(tree.span)
24062406
if tycon.tpe.typeParams.nonEmpty then
2407-
typed(untpd.AppliedTypeTree(tyconSplice, tparam :: Nil))
2407+
val tycon0 = tycon.withType(tycon.tpe.etaCollapse)
2408+
typed(untpd.AppliedTypeTree(spliced(tycon0), tparam :: Nil))
24082409
else if Feature.enabled(modularity) && tycon.tpe.member(tpnme.Self).symbol.isAbstractOrParamType then
24092410
val tparamSplice = untpd.TypedSplice(typedExpr(tparam))
2410-
typed(untpd.RefinedTypeTree(tyconSplice, List(untpd.TypeDef(tpnme.Self, tparamSplice))))
2411+
typed(untpd.RefinedTypeTree(spliced(tycon), List(untpd.TypeDef(tpnme.Self, tparamSplice))))
24112412
else
24122413
def selfNote =
24132414
if Feature.enabled(modularity) then

Diff for: tests/pos/i20901/Foo.scala

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//> using options -Ytest-pickler-check
2+
3+
import reflect.ClassTag
4+
5+
class Foo:
6+
def mkArray[T: ClassTag] = ???

Diff for: tests/pos/i20901/Foo.tastycheck

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
Header:
2+
version: <elided>
3+
tooling: <elided>
4+
UUID: <elided>
5+
6+
Names (276 bytes, starting from <elided base index>):
7+
0: ASTs
8+
1: <empty>
9+
2: scala
10+
3: reflect
11+
4: scala[Qualified . reflect]
12+
5: ClassTag
13+
6: Foo
14+
7: <init>
15+
8: java
16+
9: lang
17+
10: java[Qualified . lang]
18+
11: Object
19+
12: java[Qualified . lang][Qualified . Object]
20+
13: <init>[Signed Signature(List(),java.lang.Object) @<init>]
21+
14: Unit
22+
15: mkArray
23+
16: T
24+
17: Nothing
25+
18: Any
26+
19: evidence$
27+
20: [Unique evidence$ 1]
28+
21: ???
29+
22: Predef
30+
23: SourceFile
31+
24: annotation
32+
25: scala[Qualified . annotation]
33+
26: internal
34+
27: scala[Qualified . annotation][Qualified . internal]
35+
28: scala[Qualified . annotation][Qualified . internal][Qualified . SourceFile]
36+
29: String
37+
30: java[Qualified . lang][Qualified . String]
38+
31: <init>[Signed Signature(List(java.lang.String),scala.annotation.internal.SourceFile) @<init>]
39+
32: <elided source file name>
40+
33: Positions
41+
34: Comments
42+
35: Attributes
43+
44+
Trees (94 bytes, starting from <elided base index>):
45+
0: PACKAGE(92)
46+
2: TERMREFpkg 1 [<empty>]
47+
4: IMPORT(4)
48+
6: TERMREFpkg 4 [scala[Qualified . reflect]]
49+
8: IMPORTED 5 [ClassTag]
50+
10: TYPEDEF(82) 6 [Foo]
51+
13: TEMPLATE(61)
52+
15: APPLY(10)
53+
17: SELECTin(8) 13 [<init>[Signed Signature(List(),java.lang.Object) @<init>]]
54+
20: NEW
55+
21: TYPEREF 11 [Object]
56+
23: TERMREFpkg 10 [java[Qualified . lang]]
57+
25: SHAREDtype 21
58+
27: DEFDEF(7) 7 [<init>]
59+
30: EMPTYCLAUSE
60+
31: TYPEREF 14 [Unit]
61+
33: TERMREFpkg 2 [scala]
62+
35: STABLE
63+
36: DEFDEF(38) 15 [mkArray]
64+
39: TYPEPARAM(11) 16 [T]
65+
42: TYPEBOUNDStpt(8)
66+
44: TYPEREF 17 [Nothing]
67+
46: SHAREDtype 33
68+
48: TYPEREF 18 [Any]
69+
50: SHAREDtype 33
70+
52: PARAM(14) 20 [[Unique evidence$ 1]]
71+
55: APPLIEDtpt(10)
72+
57: IDENTtpt 5 [ClassTag]
73+
59: TYPEREF 5 [ClassTag]
74+
61: SHAREDtype 6
75+
63: IDENTtpt 16 [T]
76+
65: TYPEREFdirect 39
77+
67: IMPLICIT
78+
68: SHAREDtype 44
79+
70: TERMREF 21 [???]
80+
72: TERMREF 22 [Predef]
81+
74: SHAREDtype 33
82+
76: ANNOTATION(16)
83+
78: TYPEREF 23 [SourceFile]
84+
80: TERMREFpkg 27 [scala[Qualified . annotation][Qualified . internal]]
85+
82: APPLY(10)
86+
84: SELECTin(6) 31 [<init>[Signed Signature(List(java.lang.String),scala.annotation.internal.SourceFile) @<init>]]
87+
87: NEW
88+
88: SHAREDtype 78
89+
90: SHAREDtype 78
90+
92: STRINGconst 32 [<elided source file name>]
91+
94:
92+
93+
Positions (72 bytes, starting from <elided base index>):
94+
lines: 7
95+
line sizes:
96+
38, 0, 23, 0, 10, 32, 0
97+
positions:
98+
0: 40 .. 108
99+
4: 40 .. 63
100+
6: 47 .. 54
101+
8: 55 .. 63
102+
10: 65 .. 108
103+
13: 78 .. 108
104+
21: 71 .. 71
105+
27: 78 .. 78
106+
31: 78 .. 78
107+
36: 78 .. 108
108+
39: 90 .. 101
109+
44: 93 .. 93
110+
48: 93 .. 93
111+
52: 93 .. 101
112+
57: 93 .. 101
113+
63: 93 .. 101
114+
68: 102 .. 102
115+
70: 105 .. 108
116+
82: 65 .. 108
117+
88: 65 .. 65
118+
92: 65 .. 65
119+
120+
source paths:
121+
0: 32 [<elided source file name>]
122+
123+
Attributes (2 bytes, starting from <elided base index>):
124+
SOURCEFILEattr 32 [<elided source file name>]

Diff for: tests/semanticdb/expect/Methods.expect.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Methods/*<-example::Methods#*/[T/*<-example::Methods#[T]*/] {
1515
def m6/*<-example::Methods#m6().*/(x/*<-example::Methods#m6().(x)*/: Int/*->scala::Int#*/) = ???/*->scala::Predef.`???`().*/
1616
def m6/*<-example::Methods#m6(+1).*/(x/*<-example::Methods#m6(+1).(x)*/: List/*->example::Methods#List#*/[T/*->example::Methods#[T]*/]) = ???/*->scala::Predef.`???`().*/
1717
def m6/*<-example::Methods#m6(+2).*/(x/*<-example::Methods#m6(+2).(x)*/: scala.List/*->scala::package.List#*/[T/*->example::Methods#[T]*/]) = ???/*->scala::Predef.`???`().*/
18-
def m7/*<-example::Methods#m7().*/[U/*<-example::Methods#m7().[U]*/: Ordering/*->example::Methods#m7().[U]*//*<-example::Methods#m7().(evidence$1)*/](c/*<-example::Methods#m7().(c)*/: Methods/*->example::Methods#*/[T/*->example::Methods#[T]*/], l/*<-example::Methods#m7().(l)*/: List/*->example::Methods#List#*/[U/*->example::Methods#m7().[U]*/]) = ???/*->scala::Predef.`???`().*/
18+
def m7/*<-example::Methods#m7().*/[U/*<-example::Methods#m7().[U]*/: Ordering/*->scala::math::Ordering#*//*->example::Methods#m7().[U]*//*<-example::Methods#m7().(evidence$1)*/](c/*<-example::Methods#m7().(c)*/: Methods/*->example::Methods#*/[T/*->example::Methods#[T]*/], l/*<-example::Methods#m7().(l)*/: List/*->example::Methods#List#*/[U/*->example::Methods#m7().[U]*/]) = ???/*->scala::Predef.`???`().*/
1919
def `m8()./*<-example::Methods#`m8().`().*/`() = ???/*->scala::Predef.`???`().*/
2020
class `m9()./*<-example::Methods#`m9().`#*/`
2121
def m9/*<-example::Methods#m9().*/(x/*<-example::Methods#m9().(x)*/: `m9().`/*->example::Methods#`m9().`#*/) = ???/*->scala::Predef.`???`().*/

Diff for: tests/semanticdb/metac.expect

+2-1
Original file line numberDiff line numberDiff line change
@@ -2588,7 +2588,7 @@ Uri => Methods.scala
25882588
Text => empty
25892589
Language => Scala
25902590
Symbols => 82 entries
2591-
Occurrences => 156 entries
2591+
Occurrences => 157 entries
25922592

25932593
Symbols:
25942594
example/Methods# => class Methods [typeparam T ] extends Object { self: Methods[T] => +44 decls }
@@ -2732,6 +2732,7 @@ Occurrences:
27322732
[16:29..16:32): ??? -> scala/Predef.`???`().
27332733
[17:6..17:8): m7 <- example/Methods#m7().
27342734
[17:9..17:10): U <- example/Methods#m7().[U]
2735+
[17:12..17:20): Ordering -> scala/math/Ordering#
27352736
[17:12..17:20): Ordering -> example/Methods#m7().[U]
27362737
[17:12..17:12): <- example/Methods#m7().(evidence$1)
27372738
[17:22..17:23): c <- example/Methods#m7().(c)

0 commit comments

Comments
 (0)