Skip to content

Commit

Permalink
Fix #17997: Handle intersection type as this type of super type (#18069)
Browse files Browse the repository at this point in the history
Fix #17997: Handle intersection type as this type of super type
  • Loading branch information
olhotak committed Jun 27, 2023
2 parents 484be60 + 7d31ef2 commit 588a0b1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
15 changes: 14 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/init/Semantic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,20 @@ object Semantic:
ref match
case Select(supert: Super, _) =>
val SuperType(thisTp, superTp) = supert.tpe: @unchecked
val thisValue2 = extendTrace(ref) { resolveThis(thisTp.classSymbol.asClass, thisV, klass) }
val thisValue2 = extendTrace(ref) {
thisTp match
case thisTp: ThisType =>
cases(thisTp, thisV, klass)

case AndType(thisTp: ThisType, _) =>
// Self-type annotation will generate an intersection type for `this`.
// See examples/i17997.scala
cases(thisTp, thisV, klass)

case _ =>
report.warning("[Internal error] Unexpected type " + thisTp.show + ", trace:\n" + Trace.show, ref)
Hot
}
withTrace(trace2) { thisValue2.call(ref.symbol, args, thisTp, superTp) }

case Select(qual, _) =>
Expand Down
20 changes: 20 additions & 0 deletions tests/init/pos/i17997.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
abstract class FunSuite:
def foo(): Unit = println("FunSuite")

foo()

trait MySelfType

trait MyTrait extends FunSuite { this: MySelfType =>
}

abstract class MyAbstractClass extends FunSuite { this: MySelfType =>

override def foo() = {
println("MyAbstractClass")
super.foo()
}
}

final class MyFinalClass extends MyAbstractClass with MyTrait with MySelfType:
val n: Int = 100

0 comments on commit 588a0b1

Please sign in to comment.