Skip to content

Commit

Permalink
fix issue 20901: etaCollapse context bound type (#20910)
Browse files Browse the repository at this point in the history
fixes #20901
  • Loading branch information
sjrd authored Jul 1, 2024
2 parents 923a837 + 62605a6 commit d68b645
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 5 deletions.
7 changes: 4 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2401,13 +2401,14 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer

def typedContextBoundTypeTree(tree: untpd.ContextBoundTypeTree)(using Context): Tree =
val tycon = typedType(tree.tycon)
val tyconSplice = untpd.TypedSplice(tycon)
def spliced(tree: Tree) = untpd.TypedSplice(tree)
val tparam = untpd.Ident(tree.paramName).withSpan(tree.span)
if tycon.tpe.typeParams.nonEmpty then
typed(untpd.AppliedTypeTree(tyconSplice, tparam :: Nil))
val tycon0 = tycon.withType(tycon.tpe.etaCollapse)
typed(untpd.AppliedTypeTree(spliced(tycon0), tparam :: Nil))
else if Feature.enabled(modularity) && tycon.tpe.member(tpnme.Self).symbol.isAbstractOrParamType then
val tparamSplice = untpd.TypedSplice(typedExpr(tparam))
typed(untpd.RefinedTypeTree(tyconSplice, List(untpd.TypeDef(tpnme.Self, tparamSplice))))
typed(untpd.RefinedTypeTree(spliced(tycon), List(untpd.TypeDef(tpnme.Self, tparamSplice))))
else
def selfNote =
if Feature.enabled(modularity) then
Expand Down
6 changes: 6 additions & 0 deletions tests/pos/i20901/Foo.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//> using options -Ytest-pickler-check

import reflect.ClassTag

class Foo:
def mkArray[T: ClassTag] = ???
124 changes: 124 additions & 0 deletions tests/pos/i20901/Foo.tastycheck
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
Header:
version: <elided>
tooling: <elided>
UUID: <elided>

Names (276 bytes, starting from <elided base index>):
0: ASTs
1: <empty>
2: scala
3: reflect
4: scala[Qualified . reflect]
5: ClassTag
6: Foo
7: <init>
8: java
9: lang
10: java[Qualified . lang]
11: Object
12: java[Qualified . lang][Qualified . Object]
13: <init>[Signed Signature(List(),java.lang.Object) @<init>]
14: Unit
15: mkArray
16: T
17: Nothing
18: Any
19: evidence$
20: [Unique evidence$ 1]
21: ???
22: Predef
23: SourceFile
24: annotation
25: scala[Qualified . annotation]
26: internal
27: scala[Qualified . annotation][Qualified . internal]
28: scala[Qualified . annotation][Qualified . internal][Qualified . SourceFile]
29: String
30: java[Qualified . lang][Qualified . String]
31: <init>[Signed Signature(List(java.lang.String),scala.annotation.internal.SourceFile) @<init>]
32: <elided source file name>
33: Positions
34: Comments
35: Attributes

Trees (94 bytes, starting from <elided base index>):
0: PACKAGE(92)
2: TERMREFpkg 1 [<empty>]
4: IMPORT(4)
6: TERMREFpkg 4 [scala[Qualified . reflect]]
8: IMPORTED 5 [ClassTag]
10: TYPEDEF(82) 6 [Foo]
13: TEMPLATE(61)
15: APPLY(10)
17: SELECTin(8) 13 [<init>[Signed Signature(List(),java.lang.Object) @<init>]]
20: NEW
21: TYPEREF 11 [Object]
23: TERMREFpkg 10 [java[Qualified . lang]]
25: SHAREDtype 21
27: DEFDEF(7) 7 [<init>]
30: EMPTYCLAUSE
31: TYPEREF 14 [Unit]
33: TERMREFpkg 2 [scala]
35: STABLE
36: DEFDEF(38) 15 [mkArray]
39: TYPEPARAM(11) 16 [T]
42: TYPEBOUNDStpt(8)
44: TYPEREF 17 [Nothing]
46: SHAREDtype 33
48: TYPEREF 18 [Any]
50: SHAREDtype 33
52: PARAM(14) 20 [[Unique evidence$ 1]]
55: APPLIEDtpt(10)
57: IDENTtpt 5 [ClassTag]
59: TYPEREF 5 [ClassTag]
61: SHAREDtype 6
63: IDENTtpt 16 [T]
65: TYPEREFdirect 39
67: IMPLICIT
68: SHAREDtype 44
70: TERMREF 21 [???]
72: TERMREF 22 [Predef]
74: SHAREDtype 33
76: ANNOTATION(16)
78: TYPEREF 23 [SourceFile]
80: TERMREFpkg 27 [scala[Qualified . annotation][Qualified . internal]]
82: APPLY(10)
84: SELECTin(6) 31 [<init>[Signed Signature(List(java.lang.String),scala.annotation.internal.SourceFile) @<init>]]
87: NEW
88: SHAREDtype 78
90: SHAREDtype 78
92: STRINGconst 32 [<elided source file name>]
94:

Positions (72 bytes, starting from <elided base index>):
lines: 7
line sizes:
38, 0, 23, 0, 10, 32, 0
positions:
0: 40 .. 108
4: 40 .. 63
6: 47 .. 54
8: 55 .. 63
10: 65 .. 108
13: 78 .. 108
21: 71 .. 71
27: 78 .. 78
31: 78 .. 78
36: 78 .. 108
39: 90 .. 101
44: 93 .. 93
48: 93 .. 93
52: 93 .. 101
57: 93 .. 101
63: 93 .. 101
68: 102 .. 102
70: 105 .. 108
82: 65 .. 108
88: 65 .. 65
92: 65 .. 65

source paths:
0: 32 [<elided source file name>]

Attributes (2 bytes, starting from <elided base index>):
SOURCEFILEattr 32 [<elided source file name>]
2 changes: 1 addition & 1 deletion tests/semanticdb/expect/Methods.expect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Methods/*<-example::Methods#*/[T/*<-example::Methods#[T]*/] {
def m6/*<-example::Methods#m6().*/(x/*<-example::Methods#m6().(x)*/: Int/*->scala::Int#*/) = ???/*->scala::Predef.`???`().*/
def m6/*<-example::Methods#m6(+1).*/(x/*<-example::Methods#m6(+1).(x)*/: List/*->example::Methods#List#*/[T/*->example::Methods#[T]*/]) = ???/*->scala::Predef.`???`().*/
def m6/*<-example::Methods#m6(+2).*/(x/*<-example::Methods#m6(+2).(x)*/: scala.List/*->scala::package.List#*/[T/*->example::Methods#[T]*/]) = ???/*->scala::Predef.`???`().*/
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.`???`().*/
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.`???`().*/
def `m8()./*<-example::Methods#`m8().`().*/`() = ???/*->scala::Predef.`???`().*/
class `m9()./*<-example::Methods#`m9().`#*/`
def m9/*<-example::Methods#m9().*/(x/*<-example::Methods#m9().(x)*/: `m9().`/*->example::Methods#`m9().`#*/) = ???/*->scala::Predef.`???`().*/
Expand Down
3 changes: 2 additions & 1 deletion tests/semanticdb/metac.expect
Original file line number Diff line number Diff line change
Expand Up @@ -2588,7 +2588,7 @@ Uri => Methods.scala
Text => empty
Language => Scala
Symbols => 82 entries
Occurrences => 156 entries
Occurrences => 157 entries

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

0 comments on commit d68b645

Please sign in to comment.