Skip to content

Commit

Permalink
Fixes for init tests
Browse files Browse the repository at this point in the history
  • Loading branch information
szymon-rd committed Nov 17, 2023
1 parent 544ff54 commit 9dbd8aa
Show file tree
Hide file tree
Showing 85 changed files with 541 additions and 533 deletions.
4 changes: 2 additions & 2 deletions compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class CompilationTests {
implicit val testGroup: TestGroup = TestGroup("checkInitGlobal")
val options = defaultOptions.and("-Ysafe-init-global", "-Xfatal-warnings")
compileFilesInDir("tests/init-global/neg", options).checkExpectedErrors()
compileFilesInDir("tests/init-global/warn", options).checkWarnings()
compileFilesInDir("tests/init-global/warn", defaultOptions.and("-Ysafe-init-global")).checkWarnings()
compileFilesInDir("tests/init-global/pos", options).checkCompile()
}

Expand All @@ -223,7 +223,7 @@ class CompilationTests {
implicit val testGroup: TestGroup = TestGroup("checkInit")
val options = defaultOptions.and("-Ysafe-init", "-Xfatal-warnings")
compileFilesInDir("tests/init/neg", options).checkExpectedErrors()
compileFilesInDir("tests/init/warn", options).checkWarnings()
compileFilesInDir("tests/init/warn", defaultOptions.and("-Ysafe-init")).checkWarnings()
compileFilesInDir("tests/init/pos", options).checkCompile()
compileFilesInDir("tests/init/crash", options.without("-Xfatal-warnings")).checkCompile()
// The regression test for i12128 has some atypical classpath requirements.
Expand Down
14 changes: 7 additions & 7 deletions tests/init-global/neg/context-sensitivity.check
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
-- Warning: tests/init-global/neg/context-sensitivity.scala:9:21 -------------------------------------------------------
9 | def foo(): Int = A.m
| ^^^
| Access uninitialized field value m. Call trace:
| -> object A: [ context-sensitivity.scala:14 ]
| ^
| -> val m: Int = box1.value.foo() [ context-sensitivity.scala:17 ]
| ^^^^^^^^^^^^^^^^
| -> def foo(): Int = A.m [ context-sensitivity.scala:9 ]
| ^^^
| Access uninitialized field value m. Calling trace:
| ├── object A: [ context-sensitivity.scala:14 ]
| ^
| ├── val m: Int = box1.value.foo() [ context-sensitivity.scala:17 ]
| ^^^^^^^^^^^^^^^^
| └── def foo(): Int = A.m [ context-sensitivity.scala:9 ]
| ^^^
No warnings can be incurred under -Werror.
26 changes: 13 additions & 13 deletions tests/init-global/neg/global-cycle14.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
8 |object A {
| ^
| Cyclic initialization: object A -> object B -> object A. Calling trace:
| -> object A { [ global-cycle14.scala:8 ]
| ^
| -> val n: Int = B.m [ global-cycle14.scala:9 ]
| ^
| -> object B { [ global-cycle14.scala:12 ]
| ^
| -> val m: Int = A.n [ global-cycle14.scala:13 ]
| ^
| ├── object A { [ global-cycle14.scala:8 ]
| ^
| ├── val n: Int = B.m [ global-cycle14.scala:9 ]
| ^
| ├── object B { [ global-cycle14.scala:12 ]
| ^
| └── val m: Int = A.n [ global-cycle14.scala:13 ]
| ^
-- Warning: tests/init-global/neg/global-cycle14.scala:13:17 -----------------------------------------------------------
13 | val m: Int = A.n
| ^^^
| Access uninitialized field value n. Call trace:
| -> object B { [ global-cycle14.scala:12 ]
| ^
| -> val m: Int = A.n [ global-cycle14.scala:13 ]
| ^^^
| Access uninitialized field value n. Calling trace:
| ├── object B { [ global-cycle14.scala:12 ]
| ^
| └── val m: Int = A.n [ global-cycle14.scala:13 ]
| ^^^
No warnings can be incurred under -Werror.
14 changes: 7 additions & 7 deletions tests/init-global/neg/global-cycle2.check
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
-- Warning: tests/init-global/neg/global-cycle2.scala:6:21 -------------------------------------------------------------
6 | def foo(): Int = A.a * 2
| ^^^
| Access uninitialized field value a. Call trace:
| -> object A { [ global-cycle2.scala:1 ]
| ^
| -> val a: Int = B.foo() [ global-cycle2.scala:2 ]
| ^^^^^^^
| -> def foo(): Int = A.a * 2 [ global-cycle2.scala:6 ]
| ^^^
| Access uninitialized field value a. Calling trace:
| ├── object A { [ global-cycle2.scala:1 ]
| ^
| ├── val a: Int = B.foo() [ global-cycle2.scala:2 ]
| ^^^^^^^
| └── def foo(): Int = A.a * 2 [ global-cycle2.scala:6 ]
| ^^^
No warnings can be incurred under -Werror.
14 changes: 7 additions & 7 deletions tests/init-global/neg/global-cycle3.check
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
-- Warning: tests/init-global/neg/global-cycle3.scala:2:21 -------------------------------------------------------------
2 | def foo(): Int = B.a + 10
| ^^^
| Access uninitialized field value a. Call trace:
| -> object B { [ global-cycle3.scala:5 ]
| ^
| -> val a: Int = A(4).foo() [ global-cycle3.scala:6 ]
| ^^^^^^^^^^
| -> def foo(): Int = B.a + 10 [ global-cycle3.scala:2 ]
| ^^^
| Access uninitialized field value a. Calling trace:
| ├── object B { [ global-cycle3.scala:5 ]
| ^
| ├── val a: Int = A(4).foo() [ global-cycle3.scala:6 ]
| ^^^^^^^^^^
| └── def foo(): Int = B.a + 10 [ global-cycle3.scala:2 ]
| ^^^
No warnings can be incurred under -Werror.
14 changes: 7 additions & 7 deletions tests/init-global/neg/global-cycle4.check
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
-- Warning: tests/init-global/neg/global-cycle4.scala:10:21 ------------------------------------------------------------
10 | def foo(): Int = O.a + 10
| ^^^
| Access uninitialized field value a. Call trace:
| -> object O { [ global-cycle4.scala:17 ]
| ^
| -> val a: Int = D(5).bar().foo() [ global-cycle4.scala:18 ]
| ^^^^^^^^^^^^^^^^
| -> def foo(): Int = O.a + 10 [ global-cycle4.scala:10 ]
| ^^^
| Access uninitialized field value a. Calling trace:
| ├── object O { [ global-cycle4.scala:17 ]
| ^
| ├── val a: Int = D(5).bar().foo() [ global-cycle4.scala:18 ]
| ^^^^^^^^^^^^^^^^
| └── def foo(): Int = O.a + 10 [ global-cycle4.scala:10 ]
| ^^^
No warnings can be incurred under -Werror.
10 changes: 5 additions & 5 deletions tests/init-global/neg/global-cycle5.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
10 | val b: Int = A.a.foo()
| ^^^
|Reading mutable state of object A during initialization of object B.
|Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace:
|-> object B { [ global-cycle5.scala:9 ]
| ^
|-> val b: Int = A.a.foo() [ global-cycle5.scala:10 ]
| ^^^
|Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace:
|├── object B { [ global-cycle5.scala:9 ]
| ^
|└── val b: Int = A.a.foo() [ global-cycle5.scala:10 ]
| ^^^
No warnings can be incurred under -Werror.
42 changes: 21 additions & 21 deletions tests/init-global/neg/global-cycle6.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@
1 |object A {
| ^
| Cyclic initialization: object A -> object B -> object A. Calling trace:
| -> object A { [ global-cycle6.scala:1 ]
| ^
| -> val n: Int = B.m [ global-cycle6.scala:2 ]
| ^
| -> object B { [ global-cycle6.scala:8 ]
| ^
| -> val a = new A.Inner [ global-cycle6.scala:9 ]
| ^^^^^^^^^^^
| -> class Inner { [ global-cycle6.scala:3 ]
| ^
| -> println(n) [ global-cycle6.scala:4 ]
| ^
| ├── object A { [ global-cycle6.scala:1 ]
| ^
| ├── val n: Int = B.m [ global-cycle6.scala:2 ]
| ^
| ├── object B { [ global-cycle6.scala:8 ]
| ^
| ├── val a = new A.Inner [ global-cycle6.scala:9 ]
| ^^^^^^^^^^^
| ├── class Inner { [ global-cycle6.scala:3 ]
| ^
| └── println(n) [ global-cycle6.scala:4 ]
| ^
-- Warning: tests/init-global/neg/global-cycle6.scala:4:12 -------------------------------------------------------------
4 | println(n)
| ^
| Access uninitialized field value n. Call trace:
| -> object B { [ global-cycle6.scala:8 ]
| ^
| -> val a = new A.Inner [ global-cycle6.scala:9 ]
| ^^^^^^^^^^^
| -> class Inner { [ global-cycle6.scala:3 ]
| ^
| -> println(n) [ global-cycle6.scala:4 ]
| ^
| Access uninitialized field value n. Calling trace:
| ├── object B { [ global-cycle6.scala:8 ]
| ^
| ├── val a = new A.Inner [ global-cycle6.scala:9 ]
| ^^^^^^^^^^^
| ├── class Inner { [ global-cycle6.scala:3 ]
| ^
| └── println(n) [ global-cycle6.scala:4 ]
| ^
No warnings can be incurred under -Werror.
26 changes: 13 additions & 13 deletions tests/init-global/neg/global-cycle7.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
1 |object A {
| ^
| Cyclic initialization: object A -> object B -> object A. Calling trace:
| -> object A { [ global-cycle7.scala:1 ]
| ^
| -> val n: Int = B.m [ global-cycle7.scala:2 ]
| ^
| -> object B { [ global-cycle7.scala:5 ]
| ^
| -> val m: Int = A.n [ global-cycle7.scala:6 ]
| ^
| ├── object A { [ global-cycle7.scala:1 ]
| ^
| ├── val n: Int = B.m [ global-cycle7.scala:2 ]
| ^
| ├── object B { [ global-cycle7.scala:5 ]
| ^
| └── val m: Int = A.n [ global-cycle7.scala:6 ]
| ^
-- Warning: tests/init-global/neg/global-cycle7.scala:6:17 -------------------------------------------------------------
6 | val m: Int = A.n
| ^^^
| Access uninitialized field value n. Call trace:
| -> object B { [ global-cycle7.scala:5 ]
| ^
| -> val m: Int = A.n [ global-cycle7.scala:6 ]
| ^^^
| Access uninitialized field value n. Calling trace:
| ├── object B { [ global-cycle7.scala:5 ]
| ^
| └── val m: Int = A.n [ global-cycle7.scala:6 ]
| ^^^
No warnings can be incurred under -Werror.
24 changes: 12 additions & 12 deletions tests/init-global/neg/global-cycle8.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
9 |object O {
| ^
| Cyclic initialization: object O -> object P -> object O. Calling trace:
| -> object O { [ global-cycle8.scala:9 ]
| ^
| -> println(P.m) [ global-cycle8.scala:11 ]
| ^
| -> object P { [ global-cycle8.scala:14 ]
| ^
| -> val m = Q.bar(new B) [ global-cycle8.scala:15 ]
| ^^^^^^^^^^^^
| -> def bar(b: B) = b.a.foo() [ global-cycle8.scala:19 ]
| ^^^^^^^^^
| -> def foo() = println(O.n) [ global-cycle8.scala:2 ]
| ^
| ├── object O { [ global-cycle8.scala:9 ]
| ^
| ├── println(P.m) [ global-cycle8.scala:11 ]
| ^
| ├── object P { [ global-cycle8.scala:14 ]
| ^
| ├── val m = Q.bar(new B) [ global-cycle8.scala:15 ]
| ^^^^^^^^^^^^
| ├── def bar(b: B) = b.a.foo() [ global-cycle8.scala:19 ]
| ^^^^^^^^^
| └── def foo() = println(O.n) [ global-cycle8.scala:2 ]
| ^
No warnings can be incurred under -Werror.
10 changes: 5 additions & 5 deletions tests/init-global/neg/global-irrelevance1.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
5 | var y = A.x * 2
| ^^^
|Reading mutable state of object A during initialization of object B.
|Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace:
|-> object B: [ global-irrelevance1.scala:4 ]
| ^
|-> var y = A.x * 2 [ global-irrelevance1.scala:5 ]
| ^^^
|Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace:
|├── object B: [ global-irrelevance1.scala:4 ]
| ^
|└── var y = A.x * 2 [ global-irrelevance1.scala:5 ]
| ^^^
No warnings can be incurred under -Werror.
17 changes: 8 additions & 9 deletions tests/init-global/neg/global-irrelevance2.check
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
| ^^^^^^^^^^^^
| Mutating object A during initialization of object B.
| Mutating other static objects during the initialization of one static object is forbidden. Calling trace:
|
| -> object B: [ global-irrelevance2.scala:7 ]
| ^
| -> new B(10) [ global-irrelevance2.scala:8 ]
| ^^^^^^^^^
| -> class B(b: Int): [ global-irrelevance2.scala:4 ]
| ^
| -> A.x = b * 2 [ global-irrelevance2.scala:5 ]
| ^^^^^^^^^^^^
| ├── object B: [ global-irrelevance2.scala:7 ]
| │ ^
| ├── new B(10) [ global-irrelevance2.scala:8 ]
| │ ^^^^^^^^^
| ├── class B(b: Int): [ global-irrelevance2.scala:4 ]
| │ ^
| └── A.x = b * 2 [ global-irrelevance2.scala:5 ]
| ^^^^^^^^^^^^
No warnings can be incurred under -Werror.
14 changes: 7 additions & 7 deletions tests/init-global/neg/global-irrelevance3.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
9 | (() => x)
| ^
|Reading mutable state of object A during initialization of object B.
|Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace:
|-> object B: [ global-irrelevance3.scala:13 ]
| ^
|-> var y = A.p.g() [ global-irrelevance3.scala:14 ]
| ^^^^^^^
|-> (() => x) [ global-irrelevance3.scala:9 ]
| ^
|Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace:
|├── object B: [ global-irrelevance3.scala:13 ]
| ^
|├── var y = A.p.g() [ global-irrelevance3.scala:14 ]
| ^^^^^^^
|└── (() => x) [ global-irrelevance3.scala:9 ]
| ^
No warnings can be incurred under -Werror.
13 changes: 6 additions & 7 deletions tests/init-global/neg/global-irrelevance4.check
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
| ^^^^^^^^^^
| Mutating object A during initialization of object B.
| Mutating other static objects during the initialization of one static object is forbidden. Calling trace:
|
| -> object B: [ global-irrelevance4.scala:12 ]
| ^
| -> A.p.f(10) [ global-irrelevance4.scala:13 ]
| ^^^^^^^^^
| -> (y => x = y), [ global-irrelevance4.scala:8 ]
| ^^^^^^^^^^
| ├── object B: [ global-irrelevance4.scala:12 ]
| │ ^
| ├── A.p.f(10) [ global-irrelevance4.scala:13 ]
| │ ^^^^^^^^^
| └── (y => x = y), [ global-irrelevance4.scala:8 ]
| ^^^^^^^^^^
No warnings can be incurred under -Werror.
10 changes: 5 additions & 5 deletions tests/init-global/neg/global-irrelevance5.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
6 | var y = A.array(0) * 2
| ^^^^^^^^^^
|Reading mutable state of object A during initialization of object B.
|Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace:
|-> object B: [ global-irrelevance5.scala:5 ]
| ^
|-> var y = A.array(0) * 2 [ global-irrelevance5.scala:6 ]
| ^^^^^^^^^^
|Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace:
|├── object B: [ global-irrelevance5.scala:5 ]
| ^
|└── var y = A.array(0) * 2 [ global-irrelevance5.scala:6 ]
| ^^^^^^^^^^
No warnings can be incurred under -Werror.
10 changes: 5 additions & 5 deletions tests/init-global/neg/global-irrelevance6.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
9 | var y = A.array(0).foo() * 2
| ^^^^^^^^^^
|Reading mutable state of object A during initialization of object B.
|Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace:
|-> object B: [ global-irrelevance6.scala:8 ]
| ^
|-> var y = A.array(0).foo() * 2 [ global-irrelevance6.scala:9 ]
| ^^^^^^^^^^
|Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace:
|├── object B: [ global-irrelevance6.scala:8 ]
| ^
|└── var y = A.array(0).foo() * 2 [ global-irrelevance6.scala:9 ]
| ^^^^^^^^^^
No warnings can be incurred under -Werror.
10 changes: 5 additions & 5 deletions tests/init-global/neg/global-irrelevance7.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
10 | var y = A.array(0).foo() * 2
| ^^^^^^^^^^
|Reading mutable state of object A during initialization of object B.
|Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace:
|-> object B: [ global-irrelevance7.scala:9 ]
| ^
|-> var y = A.array(0).foo() * 2 [ global-irrelevance7.scala:10 ]
| ^^^^^^^^^^
|Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace:
|├── object B: [ global-irrelevance7.scala:9 ]
| ^
|└── var y = A.array(0).foo() * 2 [ global-irrelevance7.scala:10 ]
| ^^^^^^^^^^
No warnings can be incurred under -Werror.
Loading

0 comments on commit 9dbd8aa

Please sign in to comment.