Skip to content

Commit 1591ac9

Browse files
bishaboshaWojciechMazur
authored andcommitted
fix issue 20901: etaCollapse context bound type
1 parent edc8cbc commit 1591ac9

File tree

3 files changed

+134
-3
lines changed

3 files changed

+134
-3
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2366,13 +2366,14 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
23662366

23672367
def typedContextBoundTypeTree(tree: untpd.ContextBoundTypeTree)(using Context): Tree =
23682368
val tycon = typedType(tree.tycon)
2369-
val tyconSplice = untpd.TypedSplice(tycon)
2369+
def spliced(tree: Tree) = untpd.TypedSplice(tree)
23702370
val tparam = untpd.Ident(tree.paramName).withSpan(tree.span)
23712371
if tycon.tpe.typeParams.nonEmpty then
2372-
typed(untpd.AppliedTypeTree(tyconSplice, tparam :: Nil))
2372+
val tycon0 = tycon.withType(tycon.tpe.etaCollapse)
2373+
typed(untpd.AppliedTypeTree(spliced(tycon0), tparam :: Nil))
23732374
else if Feature.enabled(modularity) && tycon.tpe.member(tpnme.Self).symbol.isAbstractOrParamType then
23742375
val tparamSplice = untpd.TypedSplice(typedExpr(tparam))
2375-
typed(untpd.RefinedTypeTree(tyconSplice, List(untpd.TypeDef(tpnme.Self, tparamSplice))))
2376+
typed(untpd.RefinedTypeTree(spliced(tycon), List(untpd.TypeDef(tpnme.Self, tparamSplice))))
23762377
else
23772378
def selfNote =
23782379
if Feature.enabled(modularity) then

tests/pos/i20901/Foo.scala

Lines changed: 6 additions & 0 deletions
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] = ???

tests/pos/i20901/Foo.tastycheck

Lines changed: 124 additions & 0 deletions
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>]

0 commit comments

Comments
 (0)