Skip to content

Commit 9dbd8aa

Browse files
committed
Fixes for init tests
1 parent 544ff54 commit 9dbd8aa

File tree

85 files changed

+541
-533
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+541
-533
lines changed

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class CompilationTests {
214214
implicit val testGroup: TestGroup = TestGroup("checkInitGlobal")
215215
val options = defaultOptions.and("-Ysafe-init-global", "-Xfatal-warnings")
216216
compileFilesInDir("tests/init-global/neg", options).checkExpectedErrors()
217-
compileFilesInDir("tests/init-global/warn", options).checkWarnings()
217+
compileFilesInDir("tests/init-global/warn", defaultOptions.and("-Ysafe-init-global")).checkWarnings()
218218
compileFilesInDir("tests/init-global/pos", options).checkCompile()
219219
}
220220

@@ -223,7 +223,7 @@ class CompilationTests {
223223
implicit val testGroup: TestGroup = TestGroup("checkInit")
224224
val options = defaultOptions.and("-Ysafe-init", "-Xfatal-warnings")
225225
compileFilesInDir("tests/init/neg", options).checkExpectedErrors()
226-
compileFilesInDir("tests/init/warn", options).checkWarnings()
226+
compileFilesInDir("tests/init/warn", defaultOptions.and("-Ysafe-init")).checkWarnings()
227227
compileFilesInDir("tests/init/pos", options).checkCompile()
228228
compileFilesInDir("tests/init/crash", options.without("-Xfatal-warnings")).checkCompile()
229229
// The regression test for i12128 has some atypical classpath requirements.
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
-- Warning: tests/init-global/neg/context-sensitivity.scala:9:21 -------------------------------------------------------
22
9 | def foo(): Int = A.m
33
| ^^^
4-
| Access uninitialized field value m. Call trace:
5-
| -> object A: [ context-sensitivity.scala:14 ]
6-
| ^
7-
| -> val m: Int = box1.value.foo() [ context-sensitivity.scala:17 ]
8-
| ^^^^^^^^^^^^^^^^
9-
| -> def foo(): Int = A.m [ context-sensitivity.scala:9 ]
10-
| ^^^
4+
| Access uninitialized field value m. Calling trace:
5+
| ├── object A: [ context-sensitivity.scala:14 ]
6+
| ^
7+
| ├── val m: Int = box1.value.foo() [ context-sensitivity.scala:17 ]
8+
| ^^^^^^^^^^^^^^^^
9+
| └── def foo(): Int = A.m [ context-sensitivity.scala:9 ]
10+
| ^^^
1111
No warnings can be incurred under -Werror.

tests/init-global/neg/global-cycle14.check

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
8 |object A {
33
| ^
44
| Cyclic initialization: object A -> object B -> object A. Calling trace:
5-
| -> object A { [ global-cycle14.scala:8 ]
6-
| ^
7-
| -> val n: Int = B.m [ global-cycle14.scala:9 ]
8-
| ^
9-
| -> object B { [ global-cycle14.scala:12 ]
10-
| ^
11-
| -> val m: Int = A.n [ global-cycle14.scala:13 ]
12-
| ^
5+
| ├── object A { [ global-cycle14.scala:8 ]
6+
| ^
7+
| ├── val n: Int = B.m [ global-cycle14.scala:9 ]
8+
| ^
9+
| ├── object B { [ global-cycle14.scala:12 ]
10+
| ^
11+
| └── val m: Int = A.n [ global-cycle14.scala:13 ]
12+
| ^
1313
-- Warning: tests/init-global/neg/global-cycle14.scala:13:17 -----------------------------------------------------------
1414
13 | val m: Int = A.n
1515
| ^^^
16-
| Access uninitialized field value n. Call trace:
17-
| -> object B { [ global-cycle14.scala:12 ]
18-
| ^
19-
| -> val m: Int = A.n [ global-cycle14.scala:13 ]
20-
| ^^^
16+
| Access uninitialized field value n. Calling trace:
17+
| ├── object B { [ global-cycle14.scala:12 ]
18+
| ^
19+
| └── val m: Int = A.n [ global-cycle14.scala:13 ]
20+
| ^^^
2121
No warnings can be incurred under -Werror.
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
-- Warning: tests/init-global/neg/global-cycle2.scala:6:21 -------------------------------------------------------------
22
6 | def foo(): Int = A.a * 2
33
| ^^^
4-
| Access uninitialized field value a. Call trace:
5-
| -> object A { [ global-cycle2.scala:1 ]
6-
| ^
7-
| -> val a: Int = B.foo() [ global-cycle2.scala:2 ]
8-
| ^^^^^^^
9-
| -> def foo(): Int = A.a * 2 [ global-cycle2.scala:6 ]
10-
| ^^^
4+
| Access uninitialized field value a. Calling trace:
5+
| ├── object A { [ global-cycle2.scala:1 ]
6+
| ^
7+
| ├── val a: Int = B.foo() [ global-cycle2.scala:2 ]
8+
| ^^^^^^^
9+
| └── def foo(): Int = A.a * 2 [ global-cycle2.scala:6 ]
10+
| ^^^
1111
No warnings can be incurred under -Werror.
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
-- Warning: tests/init-global/neg/global-cycle3.scala:2:21 -------------------------------------------------------------
22
2 | def foo(): Int = B.a + 10
33
| ^^^
4-
| Access uninitialized field value a. Call trace:
5-
| -> object B { [ global-cycle3.scala:5 ]
6-
| ^
7-
| -> val a: Int = A(4).foo() [ global-cycle3.scala:6 ]
8-
| ^^^^^^^^^^
9-
| -> def foo(): Int = B.a + 10 [ global-cycle3.scala:2 ]
10-
| ^^^
4+
| Access uninitialized field value a. Calling trace:
5+
| ├── object B { [ global-cycle3.scala:5 ]
6+
| ^
7+
| ├── val a: Int = A(4).foo() [ global-cycle3.scala:6 ]
8+
| ^^^^^^^^^^
9+
| └── def foo(): Int = B.a + 10 [ global-cycle3.scala:2 ]
10+
| ^^^
1111
No warnings can be incurred under -Werror.
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
-- Warning: tests/init-global/neg/global-cycle4.scala:10:21 ------------------------------------------------------------
22
10 | def foo(): Int = O.a + 10
33
| ^^^
4-
| Access uninitialized field value a. Call trace:
5-
| -> object O { [ global-cycle4.scala:17 ]
6-
| ^
7-
| -> val a: Int = D(5).bar().foo() [ global-cycle4.scala:18 ]
8-
| ^^^^^^^^^^^^^^^^
9-
| -> def foo(): Int = O.a + 10 [ global-cycle4.scala:10 ]
10-
| ^^^
4+
| Access uninitialized field value a. Calling trace:
5+
| ├── object O { [ global-cycle4.scala:17 ]
6+
| ^
7+
| ├── val a: Int = D(5).bar().foo() [ global-cycle4.scala:18 ]
8+
| ^^^^^^^^^^^^^^^^
9+
| └── def foo(): Int = O.a + 10 [ global-cycle4.scala:10 ]
10+
| ^^^
1111
No warnings can be incurred under -Werror.

tests/init-global/neg/global-cycle5.check

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
10 | val b: Int = A.a.foo()
33
| ^^^
44
|Reading mutable state of object A during initialization of object B.
5-
|Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace:
6-
|-> object B { [ global-cycle5.scala:9 ]
7-
| ^
8-
|-> val b: Int = A.a.foo() [ global-cycle5.scala:10 ]
9-
| ^^^
5+
|Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace:
6+
|├── object B { [ global-cycle5.scala:9 ]
7+
| ^
8+
|└── val b: Int = A.a.foo() [ global-cycle5.scala:10 ]
9+
| ^^^
1010
No warnings can be incurred under -Werror.

tests/init-global/neg/global-cycle6.check

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@
22
1 |object A {
33
| ^
44
| Cyclic initialization: object A -> object B -> object A. Calling trace:
5-
| -> object A { [ global-cycle6.scala:1 ]
6-
| ^
7-
| -> val n: Int = B.m [ global-cycle6.scala:2 ]
8-
| ^
9-
| -> object B { [ global-cycle6.scala:8 ]
10-
| ^
11-
| -> val a = new A.Inner [ global-cycle6.scala:9 ]
12-
| ^^^^^^^^^^^
13-
| -> class Inner { [ global-cycle6.scala:3 ]
14-
| ^
15-
| -> println(n) [ global-cycle6.scala:4 ]
16-
| ^
5+
| ├── object A { [ global-cycle6.scala:1 ]
6+
| ^
7+
| ├── val n: Int = B.m [ global-cycle6.scala:2 ]
8+
| ^
9+
| ├── object B { [ global-cycle6.scala:8 ]
10+
| ^
11+
| ├── val a = new A.Inner [ global-cycle6.scala:9 ]
12+
| ^^^^^^^^^^^
13+
| ├── class Inner { [ global-cycle6.scala:3 ]
14+
| ^
15+
| └── println(n) [ global-cycle6.scala:4 ]
16+
| ^
1717
-- Warning: tests/init-global/neg/global-cycle6.scala:4:12 -------------------------------------------------------------
1818
4 | println(n)
1919
| ^
20-
| Access uninitialized field value n. Call trace:
21-
| -> object B { [ global-cycle6.scala:8 ]
22-
| ^
23-
| -> val a = new A.Inner [ global-cycle6.scala:9 ]
24-
| ^^^^^^^^^^^
25-
| -> class Inner { [ global-cycle6.scala:3 ]
26-
| ^
27-
| -> println(n) [ global-cycle6.scala:4 ]
28-
| ^
20+
| Access uninitialized field value n. Calling trace:
21+
| ├── object B { [ global-cycle6.scala:8 ]
22+
| ^
23+
| ├── val a = new A.Inner [ global-cycle6.scala:9 ]
24+
| ^^^^^^^^^^^
25+
| ├── class Inner { [ global-cycle6.scala:3 ]
26+
| ^
27+
| └── println(n) [ global-cycle6.scala:4 ]
28+
| ^
2929
No warnings can be incurred under -Werror.

tests/init-global/neg/global-cycle7.check

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
1 |object A {
33
| ^
44
| Cyclic initialization: object A -> object B -> object A. Calling trace:
5-
| -> object A { [ global-cycle7.scala:1 ]
6-
| ^
7-
| -> val n: Int = B.m [ global-cycle7.scala:2 ]
8-
| ^
9-
| -> object B { [ global-cycle7.scala:5 ]
10-
| ^
11-
| -> val m: Int = A.n [ global-cycle7.scala:6 ]
12-
| ^
5+
| ├── object A { [ global-cycle7.scala:1 ]
6+
| ^
7+
| ├── val n: Int = B.m [ global-cycle7.scala:2 ]
8+
| ^
9+
| ├── object B { [ global-cycle7.scala:5 ]
10+
| ^
11+
| └── val m: Int = A.n [ global-cycle7.scala:6 ]
12+
| ^
1313
-- Warning: tests/init-global/neg/global-cycle7.scala:6:17 -------------------------------------------------------------
1414
6 | val m: Int = A.n
1515
| ^^^
16-
| Access uninitialized field value n. Call trace:
17-
| -> object B { [ global-cycle7.scala:5 ]
18-
| ^
19-
| -> val m: Int = A.n [ global-cycle7.scala:6 ]
20-
| ^^^
16+
| Access uninitialized field value n. Calling trace:
17+
| ├── object B { [ global-cycle7.scala:5 ]
18+
| ^
19+
| └── val m: Int = A.n [ global-cycle7.scala:6 ]
20+
| ^^^
2121
No warnings can be incurred under -Werror.

tests/init-global/neg/global-cycle8.check

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
9 |object O {
33
| ^
44
| Cyclic initialization: object O -> object P -> object O. Calling trace:
5-
| -> object O { [ global-cycle8.scala:9 ]
6-
| ^
7-
| -> println(P.m) [ global-cycle8.scala:11 ]
8-
| ^
9-
| -> object P { [ global-cycle8.scala:14 ]
10-
| ^
11-
| -> val m = Q.bar(new B) [ global-cycle8.scala:15 ]
12-
| ^^^^^^^^^^^^
13-
| -> def bar(b: B) = b.a.foo() [ global-cycle8.scala:19 ]
14-
| ^^^^^^^^^
15-
| -> def foo() = println(O.n) [ global-cycle8.scala:2 ]
16-
| ^
5+
| ├── object O { [ global-cycle8.scala:9 ]
6+
| ^
7+
| ├── println(P.m) [ global-cycle8.scala:11 ]
8+
| ^
9+
| ├── object P { [ global-cycle8.scala:14 ]
10+
| ^
11+
| ├── val m = Q.bar(new B) [ global-cycle8.scala:15 ]
12+
| ^^^^^^^^^^^^
13+
| ├── def bar(b: B) = b.a.foo() [ global-cycle8.scala:19 ]
14+
| ^^^^^^^^^
15+
| └── def foo() = println(O.n) [ global-cycle8.scala:2 ]
16+
| ^
1717
No warnings can be incurred under -Werror.

tests/init-global/neg/global-irrelevance1.check

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
5 | var y = A.x * 2
33
| ^^^
44
|Reading mutable state of object A during initialization of object B.
5-
|Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace:
6-
|-> object B: [ global-irrelevance1.scala:4 ]
7-
| ^
8-
|-> var y = A.x * 2 [ global-irrelevance1.scala:5 ]
9-
| ^^^
5+
|Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace:
6+
|├── object B: [ global-irrelevance1.scala:4 ]
7+
| ^
8+
|└── var y = A.x * 2 [ global-irrelevance1.scala:5 ]
9+
| ^^^
1010
No warnings can be incurred under -Werror.

tests/init-global/neg/global-irrelevance2.check

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
| ^^^^^^^^^^^^
44
| Mutating object A during initialization of object B.
55
| Mutating other static objects during the initialization of one static object is forbidden. Calling trace:
6-
|
7-
| -> object B: [ global-irrelevance2.scala:7 ]
8-
| ^
9-
| -> new B(10) [ global-irrelevance2.scala:8 ]
10-
| ^^^^^^^^^
11-
| -> class B(b: Int): [ global-irrelevance2.scala:4 ]
12-
| ^
13-
| -> A.x = b * 2 [ global-irrelevance2.scala:5 ]
14-
| ^^^^^^^^^^^^
6+
| ├── object B: [ global-irrelevance2.scala:7 ]
7+
| │ ^
8+
| ├── new B(10) [ global-irrelevance2.scala:8 ]
9+
| │ ^^^^^^^^^
10+
| ├── class B(b: Int): [ global-irrelevance2.scala:4 ]
11+
| │ ^
12+
| └── A.x = b * 2 [ global-irrelevance2.scala:5 ]
13+
| ^^^^^^^^^^^^
1514
No warnings can be incurred under -Werror.

tests/init-global/neg/global-irrelevance3.check

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
9 | (() => x)
33
| ^
44
|Reading mutable state of object A during initialization of object B.
5-
|Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace:
6-
|-> object B: [ global-irrelevance3.scala:13 ]
7-
| ^
8-
|-> var y = A.p.g() [ global-irrelevance3.scala:14 ]
9-
| ^^^^^^^
10-
|-> (() => x) [ global-irrelevance3.scala:9 ]
11-
| ^
5+
|Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace:
6+
|├── object B: [ global-irrelevance3.scala:13 ]
7+
| ^
8+
|├── var y = A.p.g() [ global-irrelevance3.scala:14 ]
9+
| ^^^^^^^
10+
|└── (() => x) [ global-irrelevance3.scala:9 ]
11+
| ^
1212
No warnings can be incurred under -Werror.

tests/init-global/neg/global-irrelevance4.check

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
| ^^^^^^^^^^
44
| Mutating object A during initialization of object B.
55
| Mutating other static objects during the initialization of one static object is forbidden. Calling trace:
6-
|
7-
| -> object B: [ global-irrelevance4.scala:12 ]
8-
| ^
9-
| -> A.p.f(10) [ global-irrelevance4.scala:13 ]
10-
| ^^^^^^^^^
11-
| -> (y => x = y), [ global-irrelevance4.scala:8 ]
12-
| ^^^^^^^^^^
6+
| ├── object B: [ global-irrelevance4.scala:12 ]
7+
| │ ^
8+
| ├── A.p.f(10) [ global-irrelevance4.scala:13 ]
9+
| │ ^^^^^^^^^
10+
| └── (y => x = y), [ global-irrelevance4.scala:8 ]
11+
| ^^^^^^^^^^
1312
No warnings can be incurred under -Werror.

tests/init-global/neg/global-irrelevance5.check

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
6 | var y = A.array(0) * 2
33
| ^^^^^^^^^^
44
|Reading mutable state of object A during initialization of object B.
5-
|Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace:
6-
|-> object B: [ global-irrelevance5.scala:5 ]
7-
| ^
8-
|-> var y = A.array(0) * 2 [ global-irrelevance5.scala:6 ]
9-
| ^^^^^^^^^^
5+
|Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace:
6+
|├── object B: [ global-irrelevance5.scala:5 ]
7+
| ^
8+
|└── var y = A.array(0) * 2 [ global-irrelevance5.scala:6 ]
9+
| ^^^^^^^^^^
1010
No warnings can be incurred under -Werror.

tests/init-global/neg/global-irrelevance6.check

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
9 | var y = A.array(0).foo() * 2
33
| ^^^^^^^^^^
44
|Reading mutable state of object A during initialization of object B.
5-
|Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace:
6-
|-> object B: [ global-irrelevance6.scala:8 ]
7-
| ^
8-
|-> var y = A.array(0).foo() * 2 [ global-irrelevance6.scala:9 ]
9-
| ^^^^^^^^^^
5+
|Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace:
6+
|├── object B: [ global-irrelevance6.scala:8 ]
7+
| ^
8+
|└── var y = A.array(0).foo() * 2 [ global-irrelevance6.scala:9 ]
9+
| ^^^^^^^^^^
1010
No warnings can be incurred under -Werror.

tests/init-global/neg/global-irrelevance7.check

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
10 | var y = A.array(0).foo() * 2
33
| ^^^^^^^^^^
44
|Reading mutable state of object A during initialization of object B.
5-
|Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace:
6-
|-> object B: [ global-irrelevance7.scala:9 ]
7-
| ^
8-
|-> var y = A.array(0).foo() * 2 [ global-irrelevance7.scala:10 ]
9-
| ^^^^^^^^^^
5+
|Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace:
6+
|├── object B: [ global-irrelevance7.scala:9 ]
7+
| ^
8+
|└── var y = A.array(0).foo() * 2 [ global-irrelevance7.scala:10 ]
9+
| ^^^^^^^^^^
1010
No warnings can be incurred under -Werror.

0 commit comments

Comments
 (0)