Skip to content

Commit

Permalink
Fixed warn tests for init-global
Browse files Browse the repository at this point in the history
  • Loading branch information
szymon-rd committed Jan 26, 2024
1 parent 3ecbcfd commit d344430
Show file tree
Hide file tree
Showing 99 changed files with 299 additions and 383 deletions.
1 change: 0 additions & 1 deletion compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ class CompilationTests {
@Test def checkInitGlobal: Unit = {
implicit val testGroup: TestGroup = TestGroup("checkInitGlobal")
val options = defaultOptions.and("-Ysafe-init-global", "-Xfatal-warnings")
compileFilesInDir("tests/init-global/neg", options, FileFilter.exclude(TestSources.negInitGlobalScala2LibraryTastyBlacklisted)).checkExpectedErrors()
compileFilesInDir("tests/init-global/warn", defaultOptions.and("-Ysafe-init-global"), FileFilter.exclude(TestSources.negInitGlobalScala2LibraryTastyBlacklisted)).checkWarnings()
compileFilesInDir("tests/init-global/pos", options, FileFilter.exclude(TestSources.posInitGlobalScala2LibraryTastyBlacklisted)).checkCompile()
}
Expand Down
15 changes: 7 additions & 8 deletions tests/init-global/warn/global-cycle1.check
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
-- Warning: tests/init-global/neg/global-cycle1.scala:1:7 --------------------------------------------------------------
1 |object A {
-- Warning: tests/init-global/warn/global-cycle1.scala:1:7 -------------------------------------------------------------
1 |object A { // warn
| ^
| Cyclic initialization: object A -> object B -> object A. Calling trace:
| ├── object A { [ global-cycle1.scala:1 ]
| ├── object A { // warn [ global-cycle1.scala:1 ]
| │ ^
| ├── val a: Int = B.b [ global-cycle1.scala:2 ]
| │ ^
| ├── object B { [ global-cycle1.scala:5 ]
| │ ^
| └── val b: Int = A.a [ global-cycle1.scala:6 ]
| └── val b: Int = A.a // warn [ global-cycle1.scala:6 ]
| ^
-- Warning: tests/init-global/neg/global-cycle1.scala:6:17 -------------------------------------------------------------
6 | val b: Int = A.a
-- Warning: tests/init-global/warn/global-cycle1.scala:6:17 ------------------------------------------------------------
6 | val b: Int = A.a // warn
| ^^^
| Access uninitialized field value a. Calling trace:
| ├── object B { [ global-cycle1.scala:5 ]
| │ ^
| └── val b: Int = A.a [ global-cycle1.scala:6 ]
| └── val b: Int = A.a // warn [ global-cycle1.scala:6 ]
| ^^^
No warnings can be incurred under -Werror.
5 changes: 2 additions & 3 deletions tests/init-global/warn/global-cycle1.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
object A {
object A { // warn
val a: Int = B.b
}

object B {
val b: Int = A.a
val b: Int = A.a // warn
}

@main
def Test = print(A.a)

15 changes: 7 additions & 8 deletions tests/init-global/warn/global-cycle14.check
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
-- Warning: tests/init-global/neg/global-cycle14.scala:8:7 -------------------------------------------------------------
8 |object A {
-- Warning: tests/init-global/warn/global-cycle14.scala:8:7 ------------------------------------------------------------
8 |object A { // warn
| ^
| Cyclic initialization: object A -> object B -> object A. Calling trace:
| ├── object A { [ global-cycle14.scala:8 ]
| ├── object A { // warn [ 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 ]
| └── val m: Int = A.n // warn [ global-cycle14.scala:13 ]
| ^
-- Warning: tests/init-global/neg/global-cycle14.scala:13:17 -----------------------------------------------------------
13 | val m: Int = A.n
-- Warning: tests/init-global/warn/global-cycle14.scala:13:17 ----------------------------------------------------------
13 | val m: Int = A.n // warn
| ^^^
| Access uninitialized field value n. Calling trace:
| ├── object B { [ global-cycle14.scala:12 ]
| │ ^
| └── val m: Int = A.n [ global-cycle14.scala:13 ]
| └── val m: Int = A.n // warn [ global-cycle14.scala:13 ]
| ^^^
No warnings can be incurred under -Werror.
5 changes: 2 additions & 3 deletions tests/init-global/warn/global-cycle14.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ object O {
val d = Data(3)
}

object A {
object A { // warn
val n: Int = B.m
}

object B {
val m: Int = A.n
val m: Int = A.n // warn
}

7 changes: 3 additions & 4 deletions tests/init-global/warn/global-cycle2.check
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
-- Warning: tests/init-global/neg/global-cycle2.scala:6:21 -------------------------------------------------------------
6 | def foo(): Int = A.a * 2
-- Warning: tests/init-global/warn/global-cycle2.scala:6:21 ------------------------------------------------------------
6 | def foo(): Int = A.a * 2 // warn
| ^^^
| 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 ]
| └── def foo(): Int = A.a * 2 // warn [ global-cycle2.scala:6 ]
| ^^^
No warnings can be incurred under -Werror.
3 changes: 1 addition & 2 deletions tests/init-global/warn/global-cycle2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ object A {
}

object B {
def foo(): Int = A.a * 2
def foo(): Int = A.a * 2 // warn
}

7 changes: 3 additions & 4 deletions tests/init-global/warn/global-cycle3.check
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
-- Warning: tests/init-global/neg/global-cycle3.scala:2:21 -------------------------------------------------------------
2 | def foo(): Int = B.a + 10
-- Warning: tests/init-global/warn/global-cycle3.scala:2:21 ------------------------------------------------------------
2 | def foo(): Int = B.a + 10 // warn
| ^^^
| 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 ]
| └── def foo(): Int = B.a + 10 // warn [ global-cycle3.scala:2 ]
| ^^^
No warnings can be incurred under -Werror.
3 changes: 1 addition & 2 deletions tests/init-global/warn/global-cycle3.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
class A(x: Int) {
def foo(): Int = B.a + 10
def foo(): Int = B.a + 10 // warn
}

object B {
val a: Int = A(4).foo()
}

7 changes: 3 additions & 4 deletions tests/init-global/warn/global-cycle4.check
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
-- Warning: tests/init-global/neg/global-cycle4.scala:10:21 ------------------------------------------------------------
10 | def foo(): Int = O.a + 10
-- Warning: tests/init-global/warn/global-cycle4.scala:10:21 -----------------------------------------------------------
10 | def foo(): Int = O.a + 10 // warn
| ^^^
| 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 ]
| └── def foo(): Int = O.a + 10 // warn [ global-cycle4.scala:10 ]
| ^^^
No warnings can be incurred under -Werror.
3 changes: 1 addition & 2 deletions tests/init-global/warn/global-cycle4.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class B extends A {
}

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

class D(x: Int) {
Expand All @@ -17,4 +17,3 @@ class D(x: Int) {
object O {
val a: Int = D(5).bar().foo()
}

7 changes: 3 additions & 4 deletions tests/init-global/warn/global-cycle5.check
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
-- Warning: tests/init-global/neg/global-cycle5.scala:10:17 ------------------------------------------------------------
10 | val b: Int = A.a.foo()
-- Warning: tests/init-global/warn/global-cycle5.scala:10:17 -----------------------------------------------------------
10 | val b: Int = A.a.foo() // warn
| ^^^
|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 ]
|└── val b: Int = A.a.foo() // warn [ global-cycle5.scala:10 ]
| ^^^
No warnings can be incurred under -Werror.
4 changes: 2 additions & 2 deletions tests/init-global/warn/global-cycle5.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ object A {
}

object B {
val b: Int = A.a.foo()
val b: Int = A.a.foo() // warn
}

class Y extends X {
Expand All @@ -20,4 +20,4 @@ object C {

def main = {
A.a = new Y(); C
}
}
15 changes: 7 additions & 8 deletions tests/init-global/warn/global-cycle6.check
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
-- Warning: tests/init-global/neg/global-cycle6.scala:1:7 --------------------------------------------------------------
1 |object A {
-- Warning: tests/init-global/warn/global-cycle6.scala:1:7 -------------------------------------------------------------
1 |object A { // warn
| ^
| Cyclic initialization: object A -> object B -> object A. Calling trace:
| ├── object A { [ global-cycle6.scala:1 ]
| ├── object A { // warn [ global-cycle6.scala:1 ]
| │ ^
| ├── val n: Int = B.m [ global-cycle6.scala:2 ]
| │ ^
Expand All @@ -12,10 +12,10 @@
| │ ^^^^^^^^^^^
| ├── class Inner { [ global-cycle6.scala:3 ]
| │ ^
| └── println(n) [ global-cycle6.scala:4 ]
| └── println(n) // warn [ global-cycle6.scala:4 ]
| ^
-- Warning: tests/init-global/neg/global-cycle6.scala:4:12 -------------------------------------------------------------
4 | println(n)
-- Warning: tests/init-global/warn/global-cycle6.scala:4:12 ------------------------------------------------------------
4 | println(n) // warn
| ^
| Access uninitialized field value n. Calling trace:
| ├── object B { [ global-cycle6.scala:8 ]
Expand All @@ -24,6 +24,5 @@
| │ ^^^^^^^^^^^
| ├── class Inner { [ global-cycle6.scala:3 ]
| │ ^
| └── println(n) [ global-cycle6.scala:4 ]
| └── println(n) // warn [ global-cycle6.scala:4 ]
| ^
No warnings can be incurred under -Werror.
6 changes: 3 additions & 3 deletions tests/init-global/warn/global-cycle6.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
object A {
object A { // warn
val n: Int = B.m
class Inner {
println(n)
println(n) // warn
}
}

Expand All @@ -22,4 +22,4 @@ object O {
val a = new A.Inner
val m: Int = 10
}
}
}
15 changes: 7 additions & 8 deletions tests/init-global/warn/global-cycle7.check
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
-- Warning: tests/init-global/neg/global-cycle7.scala:1:7 --------------------------------------------------------------
1 |object A {
-- Warning: tests/init-global/warn/global-cycle7.scala:1:7 -------------------------------------------------------------
1 |object A { // warn
| ^
| Cyclic initialization: object A -> object B -> object A. Calling trace:
| ├── object A { [ global-cycle7.scala:1 ]
| ├── object A { // warn [ 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 ]
| └── val m: Int = A.n // warn [ global-cycle7.scala:6 ]
| ^
-- Warning: tests/init-global/neg/global-cycle7.scala:6:17 -------------------------------------------------------------
6 | val m: Int = A.n
-- Warning: tests/init-global/warn/global-cycle7.scala:6:17 ------------------------------------------------------------
6 | val m: Int = A.n // warn
| ^^^
| Access uninitialized field value n. Calling trace:
| ├── object B { [ global-cycle7.scala:5 ]
| │ ^
| └── val m: Int = A.n [ global-cycle7.scala:6 ]
| └── val m: Int = A.n // warn [ global-cycle7.scala:6 ]
| ^^^
No warnings can be incurred under -Werror.
5 changes: 2 additions & 3 deletions tests/init-global/warn/global-cycle7.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
object A {
object A { // warn
val n: Int = B.m
}

object B {
val m: Int = A.n
val m: Int = A.n // warn
}

abstract class TokensCommon {
Expand All @@ -16,4 +16,3 @@ object JavaTokens extends TokensCommon {
final def maxToken: Int = DOUBLE
final val DOUBLE = 188
}

7 changes: 3 additions & 4 deletions tests/init-global/warn/global-cycle8.check
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
-- Warning: tests/init-global/neg/global-cycle8.scala:9:7 --------------------------------------------------------------
9 |object O {
-- Warning: tests/init-global/warn/global-cycle8.scala:9:7 -------------------------------------------------------------
9 |object O { // warn
| ^
| Cyclic initialization: object O -> object P -> object O. Calling trace:
| ├── object O { [ global-cycle8.scala:9 ]
| ├── object O { // warn [ global-cycle8.scala:9 ]
| │ ^
| ├── println(P.m) [ global-cycle8.scala:11 ]
| │ ^
Expand All @@ -14,4 +14,3 @@
| │ ^^^^^^^^^
| └── def foo() = println(O.n) [ global-cycle8.scala:2 ]
| ^
No warnings can be incurred under -Werror.
3 changes: 1 addition & 2 deletions tests/init-global/warn/global-cycle8.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class B {
val a = new A
}

object O {
object O { // warn
val n: Int = 10
println(P.m)
}
Expand All @@ -18,4 +18,3 @@ object P {
object Q {
def bar(b: B) = b.a.foo()
}

7 changes: 3 additions & 4 deletions tests/init-global/warn/global-irrelevance1.check
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
-- Warning: tests/init-global/neg/global-irrelevance1.scala:5:12 -------------------------------------------------------
5 | var y = A.x * 2
-- Warning: tests/init-global/warn/global-irrelevance1.scala:5:12 ------------------------------------------------------
5 | var y = A.x * 2 // warn
| ^^^
|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 ]
|└── var y = A.x * 2 // warn [ global-irrelevance1.scala:5 ]
| ^^^
No warnings can be incurred under -Werror.
2 changes: 1 addition & 1 deletion tests/init-global/warn/global-irrelevance1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ object A:
var x = 6

object B:
var y = A.x * 2
var y = A.x * 2 // warn
7 changes: 3 additions & 4 deletions tests/init-global/warn/global-irrelevance2.check
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Warning: tests/init-global/neg/global-irrelevance2.scala:5:6 --------------------------------------------------------
5 | A.x = b * 2
-- Warning: tests/init-global/warn/global-irrelevance2.scala:5:6 -------------------------------------------------------
5 | A.x = b * 2 // warn
| ^^^^^^^^^^^^
| Mutating object A during initialization of object B.
| Mutating other static objects during the initialization of one static object is forbidden. Calling trace:
Expand All @@ -9,6 +9,5 @@
| │ ^^^^^^^^^
| ├── class B(b: Int): [ global-irrelevance2.scala:4 ]
| │ ^
| └── A.x = b * 2 [ global-irrelevance2.scala:5 ]
| └── A.x = b * 2 // warn [ global-irrelevance2.scala:5 ]
| ^^^^^^^^^^^^
No warnings can be incurred under -Werror.
3 changes: 1 addition & 2 deletions tests/init-global/warn/global-irrelevance2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ object A:
var x = 6

class B(b: Int):
A.x = b * 2
A.x = b * 2 // warn

object B:
new B(10)

7 changes: 3 additions & 4 deletions tests/init-global/warn/global-irrelevance3.check
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
-- Warning: tests/init-global/neg/global-irrelevance3.scala:9:13 -------------------------------------------------------
9 | (() => x)
-- Warning: tests/init-global/warn/global-irrelevance3.scala:9:13 ------------------------------------------------------
9 | (() => x) // warn
| ^
|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 ]
|└── (() => x) // warn [ global-irrelevance3.scala:9 ]
| ^
No warnings can be incurred under -Werror.
Loading

0 comments on commit d344430

Please sign in to comment.