Skip to content

Commit ac69c66

Browse files
authored
add test for issue #17997 affecting the global object initialization 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.
2 parents d903d35 + cb73f0b commit ac69c66

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,16 @@ object Objects:
10201020
ref match
10211021
case Select(supert: Super, _) =>
10221022
val SuperType(thisTp, superTp) = supert.tpe: @unchecked
1023-
val thisValue2 = extendTrace(ref) { resolveThis(thisTp.classSymbol.asClass, thisV, klass) }
1023+
val thisValue2 = extendTrace(ref) {
1024+
thisTp match
1025+
case thisTp: ThisType =>
1026+
evalType(thisTp, thisV, klass)
1027+
case AndType(thisTp: ThisType, _) =>
1028+
evalType(thisTp, thisV, klass)
1029+
case _ =>
1030+
report.warning("[Internal error] Unexpected type " + thisTp.show + ", trace:\n" + Trace.show, ref)
1031+
Bottom
1032+
}
10241033
withTrace(trace2) { call(thisValue2, ref.symbol, args, thisTp, superTp) }
10251034

10261035
case Select(qual, _) =>

tests/init-global/pos/i17997-2.scala

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 & MyTrait =>
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
21+
22+
object Main:
23+
(new MyFinalClass).foo()

tests/init-global/pos/i17997.scala

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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
21+
22+
object Main:
23+
(new MyFinalClass).foo()

0 commit comments

Comments
 (0)