Skip to content

Commit 588a0b1

Browse files
authored
Fix #17997: Handle intersection type as this type of super type (#18069)
Fix #17997: Handle intersection type as this type of super type
2 parents 484be60 + 7d31ef2 commit 588a0b1

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

compiler/src/dotty/tools/dotc/transform/init/Semantic.scala

+14-1
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,20 @@ object Semantic:
12291229
ref match
12301230
case Select(supert: Super, _) =>
12311231
val SuperType(thisTp, superTp) = supert.tpe: @unchecked
1232-
val thisValue2 = extendTrace(ref) { resolveThis(thisTp.classSymbol.asClass, thisV, klass) }
1232+
val thisValue2 = extendTrace(ref) {
1233+
thisTp match
1234+
case thisTp: ThisType =>
1235+
cases(thisTp, thisV, klass)
1236+
1237+
case AndType(thisTp: ThisType, _) =>
1238+
// Self-type annotation will generate an intersection type for `this`.
1239+
// See examples/i17997.scala
1240+
cases(thisTp, thisV, klass)
1241+
1242+
case _ =>
1243+
report.warning("[Internal error] Unexpected type " + thisTp.show + ", trace:\n" + Trace.show, ref)
1244+
Hot
1245+
}
12331246
withTrace(trace2) { thisValue2.call(ref.symbol, args, thisTp, superTp) }
12341247

12351248
case Select(qual, _) =>

tests/init/pos/i17997.scala

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
abstract class FunSuite:
2+
def foo(): Unit = println("FunSuite")
3+
4+
foo()
5+
6+
trait MySelfType
7+
8+
trait MyTrait extends FunSuite { this: MySelfType =>
9+
}
10+
11+
abstract class MyAbstractClass extends FunSuite { this: MySelfType =>
12+
13+
override def foo() = {
14+
println("MyAbstractClass")
15+
super.foo()
16+
}
17+
}
18+
19+
final class MyFinalClass extends MyAbstractClass with MyTrait with MySelfType:
20+
val n: Int = 100

0 commit comments

Comments
 (0)