Skip to content

Commit 541ddac

Browse files
committed
Add test
1 parent 634c580 commit 541ddac

File tree

3 files changed

+88
-1
lines changed

3 files changed

+88
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,9 @@ object Semantic:
11481148
params.forall(param => obj.field(param).isHot)
11491149
}
11501150

1151-
// check invariant: subClassSegmentHot => isHotSegment
1151+
// Check invariant: subClassSegmentHot ==> isHotSegment
1152+
//
1153+
// This invariant holds because of the Scala/Java/JVM restriction that we cannot use `this` in super constructor calls.
11521154
if subClassSegmentHot && !isHotSegment then
11531155
report.error("[Internal error] Expect current segment to hot in promotion, current klass = " + klass.show +
11541156
", subclass = " + subClass.show + Trace.show, Trace.position)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
-- Error: tests/init/neg/super-resolution3.scala:27:6 ------------------------------------------------------------------
2+
27 | val n = 40 // error
3+
| ^
4+
| Access non-initialized value n. Calling trace:
5+
| -> class C extends A with M with N: [ super-resolution3.scala:22 ]
6+
| ^
7+
| -> new Inner() [ super-resolution3.scala:23 ]
8+
| ^^^^^^^^^^^
9+
| -> class Inner: [ super-resolution3.scala:17 ]
10+
| ^
11+
| -> N.super[A].foo() [ super-resolution3.scala:18 ]
12+
| ^^^^^^^^^^^^^^^^
13+
| -> def foo(): Int = n [ super-resolution3.scala:3 ]
14+
| ^
15+
-- Error: tests/init/neg/super-resolution3.scala:26:6 ------------------------------------------------------------------
16+
26 | val m = 30 // error
17+
| ^
18+
| Access non-initialized value m. Calling trace:
19+
| -> class C extends A with M with N: [ super-resolution3.scala:22 ]
20+
| ^
21+
| -> new Inner() [ super-resolution3.scala:23 ]
22+
| ^^^^^^^^^^^
23+
| -> class Inner: [ super-resolution3.scala:17 ]
24+
| ^
25+
| -> N.super.foo() [ super-resolution3.scala:19 ]
26+
| ^^^^^^^^^^^^^
27+
| -> override def foo(): Int = a + super.foo() [ super-resolution3.scala:11 ]
28+
| ^^^^^^^^^^^
29+
| -> def foo(): Int = m [ super-resolution3.scala:7 ]
30+
| ^
31+
-- Error: tests/init/neg/super-resolution3.scala:24:6 ------------------------------------------------------------------
32+
24 | val a = 10 // error
33+
| ^
34+
| Access non-initialized value a. Calling trace:
35+
| -> class C extends A with M with N: [ super-resolution3.scala:22 ]
36+
| ^
37+
| -> new Inner() [ super-resolution3.scala:23 ]
38+
| ^^^^^^^^^^^
39+
| -> class Inner: [ super-resolution3.scala:17 ]
40+
| ^
41+
| -> N.super.foo() [ super-resolution3.scala:19 ]
42+
| ^^^^^^^^^^^^^
43+
| -> override def foo(): Int = a + super.foo() [ super-resolution3.scala:11 ]
44+
| ^
45+
-- Error: tests/init/neg/super-resolution3.scala:25:6 ------------------------------------------------------------------
46+
25 | val b = 20 // error
47+
| ^
48+
| Access non-initialized value b. Calling trace:
49+
| -> class C extends A with M with N: [ super-resolution3.scala:22 ]
50+
| ^
51+
| -> new Inner() [ super-resolution3.scala:23 ]
52+
| ^^^^^^^^^^^
53+
| -> class Inner: [ super-resolution3.scala:17 ]
54+
| ^
55+
| -> foo() [ super-resolution3.scala:20 ]
56+
| ^^^^^
57+
| -> override def foo(): Int = b * super.foo() [ super-resolution3.scala:15 ]
58+
| ^
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
abstract class A:
2+
val n: Int
3+
def foo(): Int = n
4+
5+
trait B:
6+
val m: Int
7+
def foo(): Int = m
8+
9+
trait M extends A with B:
10+
val a: Int
11+
override def foo(): Int = a + super.foo()
12+
13+
trait N extends A with B:
14+
val b: Int
15+
override def foo(): Int = b * super.foo()
16+
17+
class Inner:
18+
N.super[A].foo()
19+
N.super.foo()
20+
foo()
21+
22+
class C extends A with M with N:
23+
new Inner()
24+
val a = 10 // error
25+
val b = 20 // error
26+
val m = 30 // error
27+
val n = 40 // error

0 commit comments

Comments
 (0)