diff --git a/compiler/src/dotty/tools/dotc/transform/init/Objects.scala b/compiler/src/dotty/tools/dotc/transform/init/Objects.scala index 9d6c3020d406..30a6b1000e3f 100644 --- a/compiler/src/dotty/tools/dotc/transform/init/Objects.scala +++ b/compiler/src/dotty/tools/dotc/transform/init/Objects.scala @@ -1020,7 +1020,16 @@ object Objects: 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 => + evalType(thisTp, thisV, klass) + case AndType(thisTp: ThisType, _) => + evalType(thisTp, thisV, klass) + case _ => + report.warning("[Internal error] Unexpected type " + thisTp.show + ", trace:\n" + Trace.show, ref) + Bottom + } withTrace(trace2) { call(thisValue2, ref.symbol, args, thisTp, superTp) } case Select(qual, _) => diff --git a/tests/init-global/pos/i17997-2.scala b/tests/init-global/pos/i17997-2.scala new file mode 100644 index 000000000000..370e7887c06b --- /dev/null +++ b/tests/init-global/pos/i17997-2.scala @@ -0,0 +1,23 @@ +abstract class FunSuite: + def foo(): Unit = println("FunSuite") + + foo() + +trait MySelfType + +trait MyTrait extends FunSuite { this: MySelfType => +} + +abstract class MyAbstractClass extends FunSuite { this: MySelfType & MyTrait => + + override def foo() = { + println("MyAbstractClass") + super.foo() + } +} + +final class MyFinalClass extends MyAbstractClass with MyTrait with MySelfType: + val n: Int = 100 + +object Main: + (new MyFinalClass).foo() diff --git a/tests/init-global/pos/i17997.scala b/tests/init-global/pos/i17997.scala new file mode 100644 index 000000000000..73372bf239eb --- /dev/null +++ b/tests/init-global/pos/i17997.scala @@ -0,0 +1,23 @@ +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 + +object Main: + (new MyFinalClass).foo()