Skip to content

Commit

Permalink
add test for issue #17997 affecting the global object initialization …
Browse files Browse the repository at this point in the history
…checker (#18141)

Issue #17997 reported a minimized example that crashed the object
instance initialization checker. That checker was fixed in #18069.
However, a similar example also crashes the global object initialization
checker. This PR adds a test that exhibits this crash in the global
object initialization checker.
  • Loading branch information
olhotak committed Jul 27, 2023
2 parents d903d35 + cb73f0b commit ac69c66
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
11 changes: 10 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/init/Objects.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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, _) =>
Expand Down
23 changes: 23 additions & 0 deletions tests/init-global/pos/i17997-2.scala
Original file line number Diff line number Diff line change
@@ -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()
23 changes: 23 additions & 0 deletions tests/init-global/pos/i17997.scala
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit ac69c66

Please sign in to comment.