Skip to content

Commit 749fc3c

Browse files
committed
Fixed warn tests for init-global
1 parent a452a73 commit 749fc3c

File tree

99 files changed

+299
-383
lines changed

Some content is hidden

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

99 files changed

+299
-383
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ class CompilationTests {
216216
@Test def checkInitGlobal: Unit = {
217217
implicit val testGroup: TestGroup = TestGroup("checkInitGlobal")
218218
val options = defaultOptions.and("-Ysafe-init-global", "-Xfatal-warnings")
219-
compileFilesInDir("tests/init-global/neg", options, FileFilter.exclude(TestSources.negInitGlobalScala2LibraryTastyBlacklisted)).checkExpectedErrors()
220219
compileFilesInDir("tests/init-global/warn", defaultOptions.and("-Ysafe-init-global"), FileFilter.exclude(TestSources.negInitGlobalScala2LibraryTastyBlacklisted)).checkWarnings()
221220
compileFilesInDir("tests/init-global/pos", options, FileFilter.exclude(TestSources.posInitGlobalScala2LibraryTastyBlacklisted)).checkCompile()
222221
}
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
-- Warning: tests/init-global/neg/global-cycle1.scala:1:7 --------------------------------------------------------------
2-
1 |object A {
1+
-- Warning: tests/init-global/warn/global-cycle1.scala:1:7 -------------------------------------------------------------
2+
1 |object A { // warn
33
| ^
44
| Cyclic initialization: object A -> object B -> object A. Calling trace:
5-
| ├── object A { [ global-cycle1.scala:1 ]
5+
| ├── object A { // warn [ global-cycle1.scala:1 ]
66
| │ ^
77
| ├── val a: Int = B.b [ global-cycle1.scala:2 ]
88
| │ ^
99
| ├── object B { [ global-cycle1.scala:5 ]
1010
| │ ^
11-
| └── val b: Int = A.a [ global-cycle1.scala:6 ]
11+
| └── val b: Int = A.a // warn [ global-cycle1.scala:6 ]
1212
| ^
13-
-- Warning: tests/init-global/neg/global-cycle1.scala:6:17 -------------------------------------------------------------
14-
6 | val b: Int = A.a
13+
-- Warning: tests/init-global/warn/global-cycle1.scala:6:17 ------------------------------------------------------------
14+
6 | val b: Int = A.a // warn
1515
| ^^^
1616
| Access uninitialized field value a. Calling trace:
1717
| ├── object B { [ global-cycle1.scala:5 ]
1818
| │ ^
19-
| └── val b: Int = A.a [ global-cycle1.scala:6 ]
19+
| └── val b: Int = A.a // warn [ global-cycle1.scala:6 ]
2020
| ^^^
21-
No warnings can be incurred under -Werror.
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
object A {
1+
object A { // warn
22
val a: Int = B.b
33
}
44

55
object B {
6-
val b: Int = A.a
6+
val b: Int = A.a // warn
77
}
88

99
@main
1010
def Test = print(A.a)
11-
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
-- Warning: tests/init-global/neg/global-cycle14.scala:8:7 -------------------------------------------------------------
2-
8 |object A {
1+
-- Warning: tests/init-global/warn/global-cycle14.scala:8:7 ------------------------------------------------------------
2+
8 |object A { // warn
33
| ^
44
| Cyclic initialization: object A -> object B -> object A. Calling trace:
5-
| ├── object A { [ global-cycle14.scala:8 ]
5+
| ├── object A { // warn [ global-cycle14.scala:8 ]
66
| │ ^
77
| ├── val n: Int = B.m [ global-cycle14.scala:9 ]
88
| │ ^
99
| ├── object B { [ global-cycle14.scala:12 ]
1010
| │ ^
11-
| └── val m: Int = A.n [ global-cycle14.scala:13 ]
11+
| └── val m: Int = A.n // warn [ global-cycle14.scala:13 ]
1212
| ^
13-
-- Warning: tests/init-global/neg/global-cycle14.scala:13:17 -----------------------------------------------------------
14-
13 | val m: Int = A.n
13+
-- Warning: tests/init-global/warn/global-cycle14.scala:13:17 ----------------------------------------------------------
14+
13 | val m: Int = A.n // warn
1515
| ^^^
1616
| Access uninitialized field value n. Calling trace:
1717
| ├── object B { [ global-cycle14.scala:12 ]
1818
| │ ^
19-
| └── val m: Int = A.n [ global-cycle14.scala:13 ]
19+
| └── val m: Int = A.n // warn [ global-cycle14.scala:13 ]
2020
| ^^^
21-
No warnings can be incurred under -Werror.

tests/init-global/warn/global-cycle14.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ object O {
55
val d = Data(3)
66
}
77

8-
object A {
8+
object A { // warn
99
val n: Int = B.m
1010
}
1111

1212
object B {
13-
val m: Int = A.n
13+
val m: Int = A.n // warn
1414
}
15-
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
-- Warning: tests/init-global/neg/global-cycle2.scala:6:21 -------------------------------------------------------------
2-
6 | def foo(): Int = A.a * 2
1+
-- Warning: tests/init-global/warn/global-cycle2.scala:6:21 ------------------------------------------------------------
2+
6 | def foo(): Int = A.a * 2 // warn
33
| ^^^
44
| Access uninitialized field value a. Calling trace:
55
| ├── object A { [ global-cycle2.scala:1 ]
66
| │ ^
77
| ├── val a: Int = B.foo() [ global-cycle2.scala:2 ]
88
| │ ^^^^^^^
9-
| └── def foo(): Int = A.a * 2 [ global-cycle2.scala:6 ]
9+
| └── def foo(): Int = A.a * 2 // warn [ global-cycle2.scala:6 ]
1010
| ^^^
11-
No warnings can be incurred under -Werror.

tests/init-global/warn/global-cycle2.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ object A {
33
}
44

55
object B {
6-
def foo(): Int = A.a * 2
6+
def foo(): Int = A.a * 2 // warn
77
}
8-
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
-- Warning: tests/init-global/neg/global-cycle3.scala:2:21 -------------------------------------------------------------
2-
2 | def foo(): Int = B.a + 10
1+
-- Warning: tests/init-global/warn/global-cycle3.scala:2:21 ------------------------------------------------------------
2+
2 | def foo(): Int = B.a + 10 // warn
33
| ^^^
44
| Access uninitialized field value a. Calling trace:
55
| ├── object B { [ global-cycle3.scala:5 ]
66
| │ ^
77
| ├── val a: Int = A(4).foo() [ global-cycle3.scala:6 ]
88
| │ ^^^^^^^^^^
9-
| └── def foo(): Int = B.a + 10 [ global-cycle3.scala:2 ]
9+
| └── def foo(): Int = B.a + 10 // warn [ global-cycle3.scala:2 ]
1010
| ^^^
11-
No warnings can be incurred under -Werror.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
class A(x: Int) {
2-
def foo(): Int = B.a + 10
2+
def foo(): Int = B.a + 10 // warn
33
}
44

55
object B {
66
val a: Int = A(4).foo()
77
}
8-
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
-- Warning: tests/init-global/neg/global-cycle4.scala:10:21 ------------------------------------------------------------
2-
10 | def foo(): Int = O.a + 10
1+
-- Warning: tests/init-global/warn/global-cycle4.scala:10:21 -----------------------------------------------------------
2+
10 | def foo(): Int = O.a + 10 // warn
33
| ^^^
44
| Access uninitialized field value a. Calling trace:
55
| ├── object O { [ global-cycle4.scala:17 ]
66
| │ ^
77
| ├── val a: Int = D(5).bar().foo() [ global-cycle4.scala:18 ]
88
| │ ^^^^^^^^^^^^^^^^
9-
| └── def foo(): Int = O.a + 10 [ global-cycle4.scala:10 ]
9+
| └── def foo(): Int = O.a + 10 // warn [ global-cycle4.scala:10 ]
1010
| ^^^
11-
No warnings can be incurred under -Werror.

tests/init-global/warn/global-cycle4.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class B extends A {
77
}
88

99
class C extends A {
10-
def foo(): Int = O.a + 10
10+
def foo(): Int = O.a + 10 // warn
1111
}
1212

1313
class D(x: Int) {
@@ -17,4 +17,3 @@ class D(x: Int) {
1717
object O {
1818
val a: Int = D(5).bar().foo()
1919
}
20-
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
-- Warning: tests/init-global/neg/global-cycle5.scala:10:17 ------------------------------------------------------------
2-
10 | val b: Int = A.a.foo()
1+
-- Warning: tests/init-global/warn/global-cycle5.scala:10:17 -----------------------------------------------------------
2+
10 | val b: Int = A.a.foo() // warn
33
| ^^^
44
|Reading mutable state of object A during initialization of object B.
55
|Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace:
66
|├── object B { [ global-cycle5.scala:9 ]
77
|│ ^
8-
|└── val b: Int = A.a.foo() [ global-cycle5.scala:10 ]
8+
|└── val b: Int = A.a.foo() // warn [ global-cycle5.scala:10 ]
99
| ^^^
10-
No warnings can be incurred under -Werror.

tests/init-global/warn/global-cycle5.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ object A {
77
}
88

99
object B {
10-
val b: Int = A.a.foo()
10+
val b: Int = A.a.foo() // warn
1111
}
1212

1313
class Y extends X {
@@ -20,4 +20,4 @@ object C {
2020

2121
def main = {
2222
A.a = new Y(); C
23-
}
23+
}
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
-- Warning: tests/init-global/neg/global-cycle6.scala:1:7 --------------------------------------------------------------
2-
1 |object A {
1+
-- Warning: tests/init-global/warn/global-cycle6.scala:1:7 -------------------------------------------------------------
2+
1 |object A { // warn
33
| ^
44
| Cyclic initialization: object A -> object B -> object A. Calling trace:
5-
| ├── object A { [ global-cycle6.scala:1 ]
5+
| ├── object A { // warn [ global-cycle6.scala:1 ]
66
| │ ^
77
| ├── val n: Int = B.m [ global-cycle6.scala:2 ]
88
| │ ^
@@ -12,10 +12,10 @@
1212
| │ ^^^^^^^^^^^
1313
| ├── class Inner { [ global-cycle6.scala:3 ]
1414
| │ ^
15-
| └── println(n) [ global-cycle6.scala:4 ]
15+
| └── println(n) // warn [ global-cycle6.scala:4 ]
1616
| ^
17-
-- Warning: tests/init-global/neg/global-cycle6.scala:4:12 -------------------------------------------------------------
18-
4 | println(n)
17+
-- Warning: tests/init-global/warn/global-cycle6.scala:4:12 ------------------------------------------------------------
18+
4 | println(n) // warn
1919
| ^
2020
| Access uninitialized field value n. Calling trace:
2121
| ├── object B { [ global-cycle6.scala:8 ]
@@ -24,6 +24,5 @@
2424
| │ ^^^^^^^^^^^
2525
| ├── class Inner { [ global-cycle6.scala:3 ]
2626
| │ ^
27-
| └── println(n) [ global-cycle6.scala:4 ]
27+
| └── println(n) // warn [ global-cycle6.scala:4 ]
2828
| ^
29-
No warnings can be incurred under -Werror.

tests/init-global/warn/global-cycle6.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
object A {
1+
object A { // warn
22
val n: Int = B.m
33
class Inner {
4-
println(n)
4+
println(n) // warn
55
}
66
}
77

@@ -22,4 +22,4 @@ object O {
2222
val a = new A.Inner
2323
val m: Int = 10
2424
}
25-
}
25+
}
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
-- Warning: tests/init-global/neg/global-cycle7.scala:1:7 --------------------------------------------------------------
2-
1 |object A {
1+
-- Warning: tests/init-global/warn/global-cycle7.scala:1:7 -------------------------------------------------------------
2+
1 |object A { // warn
33
| ^
44
| Cyclic initialization: object A -> object B -> object A. Calling trace:
5-
| ├── object A { [ global-cycle7.scala:1 ]
5+
| ├── object A { // warn [ global-cycle7.scala:1 ]
66
| │ ^
77
| ├── val n: Int = B.m [ global-cycle7.scala:2 ]
88
| │ ^
99
| ├── object B { [ global-cycle7.scala:5 ]
1010
| │ ^
11-
| └── val m: Int = A.n [ global-cycle7.scala:6 ]
11+
| └── val m: Int = A.n // warn [ global-cycle7.scala:6 ]
1212
| ^
13-
-- Warning: tests/init-global/neg/global-cycle7.scala:6:17 -------------------------------------------------------------
14-
6 | val m: Int = A.n
13+
-- Warning: tests/init-global/warn/global-cycle7.scala:6:17 ------------------------------------------------------------
14+
6 | val m: Int = A.n // warn
1515
| ^^^
1616
| Access uninitialized field value n. Calling trace:
1717
| ├── object B { [ global-cycle7.scala:5 ]
1818
| │ ^
19-
| └── val m: Int = A.n [ global-cycle7.scala:6 ]
19+
| └── val m: Int = A.n // warn [ global-cycle7.scala:6 ]
2020
| ^^^
21-
No warnings can be incurred under -Werror.

tests/init-global/warn/global-cycle7.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
object A {
1+
object A { // warn
22
val n: Int = B.m
33
}
44

55
object B {
6-
val m: Int = A.n
6+
val m: Int = A.n // warn
77
}
88

99
abstract class TokensCommon {
@@ -16,4 +16,3 @@ object JavaTokens extends TokensCommon {
1616
final def maxToken: Int = DOUBLE
1717
final val DOUBLE = 188
1818
}
19-
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
-- Warning: tests/init-global/neg/global-cycle8.scala:9:7 --------------------------------------------------------------
2-
9 |object O {
1+
-- Warning: tests/init-global/warn/global-cycle8.scala:9:7 -------------------------------------------------------------
2+
9 |object O { // warn
33
| ^
44
| Cyclic initialization: object O -> object P -> object O. Calling trace:
5-
| ├── object O { [ global-cycle8.scala:9 ]
5+
| ├── object O { // warn [ global-cycle8.scala:9 ]
66
| │ ^
77
| ├── println(P.m) [ global-cycle8.scala:11 ]
88
| │ ^
@@ -14,4 +14,3 @@
1414
| │ ^^^^^^^^^
1515
| └── def foo() = println(O.n) [ global-cycle8.scala:2 ]
1616
| ^
17-
No warnings can be incurred under -Werror.

tests/init-global/warn/global-cycle8.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class B {
66
val a = new A
77
}
88

9-
object O {
9+
object O { // warn
1010
val n: Int = 10
1111
println(P.m)
1212
}
@@ -18,4 +18,3 @@ object P {
1818
object Q {
1919
def bar(b: B) = b.a.foo()
2020
}
21-
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
-- Warning: tests/init-global/neg/global-irrelevance1.scala:5:12 -------------------------------------------------------
2-
5 | var y = A.x * 2
1+
-- Warning: tests/init-global/warn/global-irrelevance1.scala:5:12 ------------------------------------------------------
2+
5 | var y = A.x * 2 // warn
33
| ^^^
44
|Reading mutable state of object A during initialization of object B.
55
|Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace:
66
|├── object B: [ global-irrelevance1.scala:4 ]
77
|│ ^
8-
|└── var y = A.x * 2 [ global-irrelevance1.scala:5 ]
8+
|└── var y = A.x * 2 // warn [ global-irrelevance1.scala:5 ]
99
| ^^^
10-
No warnings can be incurred under -Werror.

tests/init-global/warn/global-irrelevance1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ object A:
22
var x = 6
33

44
object B:
5-
var y = A.x * 2
5+
var y = A.x * 2 // warn
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
-- Warning: tests/init-global/neg/global-irrelevance2.scala:5:6 --------------------------------------------------------
2-
5 | A.x = b * 2
1+
-- Warning: tests/init-global/warn/global-irrelevance2.scala:5:6 -------------------------------------------------------
2+
5 | A.x = b * 2 // warn
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:
@@ -9,6 +9,5 @@
99
| │ ^^^^^^^^^
1010
| ├── class B(b: Int): [ global-irrelevance2.scala:4 ]
1111
| │ ^
12-
| └── A.x = b * 2 [ global-irrelevance2.scala:5 ]
12+
| └── A.x = b * 2 // warn [ global-irrelevance2.scala:5 ]
1313
| ^^^^^^^^^^^^
14-
No warnings can be incurred under -Werror.

tests/init-global/warn/global-irrelevance2.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ object A:
22
var x = 6
33

44
class B(b: Int):
5-
A.x = b * 2
5+
A.x = b * 2 // warn
66

77
object B:
88
new B(10)
9-
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
-- Warning: tests/init-global/neg/global-irrelevance3.scala:9:13 -------------------------------------------------------
2-
9 | (() => x)
1+
-- Warning: tests/init-global/warn/global-irrelevance3.scala:9:13 ------------------------------------------------------
2+
9 | (() => x) // warn
33
| ^
44
|Reading mutable state of object A during initialization of object B.
55
|Reading mutable state of other static objects is forbidden as it breaks initialization-time irrelevance. Calling trace:
66
|├── object B: [ global-irrelevance3.scala:13 ]
77
|│ ^
88
|├── var y = A.p.g() [ global-irrelevance3.scala:14 ]
99
|│ ^^^^^^^
10-
|└── (() => x) [ global-irrelevance3.scala:9 ]
10+
|└── (() => x) // warn [ global-irrelevance3.scala:9 ]
1111
| ^
12-
No warnings can be incurred under -Werror.

0 commit comments

Comments
 (0)