Skip to content

Commit a2fee42

Browse files
committed
Got most of tests to work
1 parent c018549 commit a2fee42

File tree

109 files changed

+814
-77
lines changed

Some content is hidden

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

109 files changed

+814
-77
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ class CompilationTests {
211211
implicit val testGroup: TestGroup = TestGroup("checkInitGlobal")
212212
val options = defaultOptions.and("-Ysafe-init-global", "-Xfatal-warnings")
213213
compileFilesInDir("tests/init-global/neg", options).checkExpectedErrors()
214+
compileFilesInDir("tests/init-global/warn", options).checkWarnings()
214215
compileFilesInDir("tests/init-global/pos", options).checkCompile()
215216
}
216217

@@ -219,6 +220,7 @@ class CompilationTests {
219220
implicit val testGroup: TestGroup = TestGroup("checkInit")
220221
val options = defaultOptions.and("-Ysafe-init", "-Xfatal-warnings")
221222
compileFilesInDir("tests/init/neg", options).checkExpectedErrors()
223+
compileFilesInDir("tests/init/warn", options).checkWarnings()
222224
compileFilesInDir("tests/init/pos", options).checkCompile()
223225
compileFilesInDir("tests/init/crash", options.without("-Xfatal-warnings")).checkCompile()
224226
// The regression test for i12128 has some atypical classpath requirements.

compiler/test/dotty/tools/vulpix/ParallelTesting.scala

+7-4
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
755755
end maybeFailureMessage
756756

757757
def getWarnMapAndExpectedCount(files: Seq[JFile]): (HashMap[String, Integer], Int) =
758-
val comment = raw"//( *)warn".r
758+
val comment = raw"//( *)(nopos-)?warn".r
759759
val map = new HashMap[String, Integer]()
760760
var count = 0
761761
def bump(key: String): Unit =
@@ -766,8 +766,11 @@ trait ParallelTesting extends RunnerOrchestration { self =>
766766
files.filter(isSourceFile).foreach { file =>
767767
Using(Source.fromFile(file, StandardCharsets.UTF_8.name)) { source =>
768768
source.getLines.zipWithIndex.foreach { case (line, lineNbr) =>
769-
comment.findAllMatchIn(line).foreach { _ =>
770-
bump(s"${file.getPath}:${lineNbr+1}")
769+
comment.findAllMatchIn(line).foreach { m =>
770+
m.group(2) match
771+
case "nopos-" =>
772+
bump("nopos")
773+
case _ => bump(s"${file.getPath}:${lineNbr+1}")
771774
}
772775
}
773776
}.get
@@ -788,7 +791,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
788791
val key = s"${relativize(srcpos.source.file.toString())}:${srcpos.line + 1}"
789792
if !seenAt(key) then unexpected += key
790793
else
791-
unpositioned += relativize(srcpos.source.file.toString())
794+
if(!seenAt("nopos")) unpositioned += relativize(srcpos.source.file.toString())
792795

793796
reporterWarnings.foreach(sawDiagnostic)
794797

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- Warning: tests/init-global/neg/context-sensitivity.scala:9:21 -------------------------------------------------------
2+
9 | def foo(): Int = A.m
3+
| ^^^
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+
| ^^^
11+
No warnings can be incurred under -Werror.

tests/init-global/neg/context-sensitivity.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class C(var x: Int) extends Foo {
66
}
77

88
class D(var y: Int) extends Foo {
9-
def foo(): Int = A.m // error
9+
def foo(): Int = A.m
1010
}
1111

1212
class Box(var value: Foo)
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-- Warning: tests/init-global/neg/global-cycle1.scala:1:7 --------------------------------------------------------------
2+
1 |object A {
3+
| ^
4+
| Cyclic initialization: object A -> object B -> object A. Calling trace:
5+
| -> object A { [ global-cycle1.scala:1 ]
6+
| ^
7+
| -> val a: Int = B.b [ global-cycle1.scala:2 ]
8+
| ^
9+
| -> object B { [ global-cycle1.scala:5 ]
10+
| ^
11+
| -> val b: Int = A.a [ global-cycle1.scala:6 ]
12+
| ^
13+
-- Warning: tests/init-global/neg/global-cycle1.scala:6:17 -------------------------------------------------------------
14+
6 | val b: Int = A.a
15+
| ^^^
16+
| Access uninitialized field value a. Call trace:
17+
| -> object B { [ global-cycle1.scala:5 ]
18+
| ^
19+
| -> val b: Int = A.a [ global-cycle1.scala:6 ]
20+
| ^^^
21+
No warnings can be incurred under -Werror.

tests/init-global/neg/global-cycle1.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
object A { // error
1+
object A {
22
val a: Int = B.b
33
}
44

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

99
@main
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-- Warning: tests/init-global/neg/global-cycle14.scala:8:7 -------------------------------------------------------------
2+
8 |object A {
3+
| ^
4+
| 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+
| ^
13+
-- Warning: tests/init-global/neg/global-cycle14.scala:13:17 -----------------------------------------------------------
14+
13 | val m: Int = A.n
15+
| ^^^
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+
| ^^^
21+
No warnings can be incurred under -Werror.

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ object O {
55
val d = Data(3)
66
}
77

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

1212
object B {
13-
val m: Int = A.n // error
13+
val m: Int = A.n
1414
}
1515

1616
// nopos-error: No warnings can be incurred under -Werror.
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- Warning: tests/init-global/neg/global-cycle2.scala:6:21 -------------------------------------------------------------
2+
6 | def foo(): Int = A.a * 2
3+
| ^^^
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+
| ^^^
11+
No warnings can be incurred under -Werror.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ object A {
33
}
44

55
object B {
6-
def foo(): Int = A.a * 2 // error
6+
def foo(): Int = A.a * 2
77
}
88

99
// nopos-error: No warnings can be incurred under -Werror.
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- Warning: tests/init-global/neg/global-cycle3.scala:2:21 -------------------------------------------------------------
2+
2 | def foo(): Int = B.a + 10
3+
| ^^^
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+
| ^^^
11+
No warnings can be incurred under -Werror.

tests/init-global/neg/global-cycle3.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class A(x: Int) {
2-
def foo(): Int = B.a + 10 // error
2+
def foo(): Int = B.a + 10
33
}
44

55
object B {
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- Warning: tests/init-global/neg/global-cycle4.scala:10:21 ------------------------------------------------------------
2+
10 | def foo(): Int = O.a + 10
3+
| ^^^
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+
| ^^^
11+
No warnings can be incurred under -Werror.

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

+1-1
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 // error
10+
def foo(): Int = O.a + 10
1111
}
1212

1313
class D(x: Int) {
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- Warning: tests/init-global/neg/global-cycle5.scala:10:17 ------------------------------------------------------------
2+
10 | val b: Int = A.a.foo()
3+
| ^^^
4+
|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+
| ^^^
10+
No warnings can be incurred under -Werror.

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

+1-1
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() // error
10+
val b: Int = A.a.foo()
1111
}
1212

1313
class Y extends X {
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
-- Warning: tests/init-global/neg/global-cycle6.scala:1:7 --------------------------------------------------------------
2+
1 |object A {
3+
| ^
4+
| 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+
| ^
17+
-- Warning: tests/init-global/neg/global-cycle6.scala:4:12 -------------------------------------------------------------
18+
4 | println(n)
19+
| ^
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+
| ^
29+
No warnings can be incurred under -Werror.

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
object A { // error
1+
object A {
22
val n: Int = B.m
33
class Inner {
4-
println(n) // error
4+
println(n)
55
}
66
}
77

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-- Warning: tests/init-global/neg/global-cycle7.scala:1:7 --------------------------------------------------------------
2+
1 |object A {
3+
| ^
4+
| 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+
| ^
13+
-- Warning: tests/init-global/neg/global-cycle7.scala:6:17 -------------------------------------------------------------
14+
6 | val m: Int = A.n
15+
| ^^^
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+
| ^^^
21+
No warnings can be incurred under -Werror.

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
object A { // error
1+
object A {
22
val n: Int = B.m
33
}
44

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

99
abstract class TokensCommon {
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-- Warning: tests/init-global/neg/global-cycle8.scala:9:7 --------------------------------------------------------------
2+
9 |object O {
3+
| ^
4+
| 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+
| ^
17+
No warnings can be incurred under -Werror.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class B {
66
val a = new A
77
}
88

9-
object O { // error
9+
object O {
1010
val n: Int = 10
1111
println(P.m)
1212
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- Warning: tests/init-global/neg/global-irrelevance1.scala:5:12 -------------------------------------------------------
2+
5 | var y = A.x * 2
3+
| ^^^
4+
|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+
| ^^^
10+
No warnings can be incurred under -Werror.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ object A:
22
var x = 6
33

44
object B:
5-
var y = A.x * 2 // error
5+
var y = A.x * 2
66
// nopos-error: No warnings can be incurred under -Werror.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- Warning: tests/init-global/neg/global-irrelevance2.scala:5:6 --------------------------------------------------------
2+
5 | A.x = b * 2
3+
| ^^^^^^^^^^^^
4+
| Mutating object A during initialization of object B.
5+
| 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+
| ^^^^^^^^^^^^
15+
No warnings can be incurred under -Werror.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ object A:
22
var x = 6
33

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

77
object B:
88
new B(10)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- Warning: tests/init-global/neg/global-irrelevance3.scala:9:13 -------------------------------------------------------
2+
9 | (() => x)
3+
| ^
4+
|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+
| ^
12+
No warnings can be incurred under -Werror.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ object A:
66
var x = 6
77
new Pair(
88
y => x = y,
9-
(() => x) // error
9+
(() => x)
1010
)
1111

1212

0 commit comments

Comments
 (0)