Skip to content

Commit 3cc0660

Browse files
committed
Fix tests
1 parent e5d8ed5 commit 3cc0660

28 files changed

+60
-89
lines changed

compiler/src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ object Symbols {
8383
ctx.settings.YretainTrees.value ||
8484
denot.owner.isTerm || // no risk of leaking memory after a run for these
8585
denot.isOneOf(InlineOrProxy) || // need to keep inline info
86-
ctx.settings.YcheckInit.value // initialization check
86+
ctx.settings.YcheckInit.value || // initialization check
87+
ctx.settings.YcheckInitGlobal.value
8788

8889
/** The last denotation of this symbol */
8990
private var lastDenot: SymDenotation = _
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
import reflect.Selectable.reflectiveSelectable
1+
trait Foo:
2+
def foo(): Int
23

3-
class C(var x: Int) {
4+
class C(var x: Int) extends Foo {
45
def foo(): Int = 20
56
}
67

7-
class D(var y: Int) {
8-
def foo(): Int = A.m
8+
class D(var y: Int) extends Foo {
9+
def foo(): Int = A.m // error
910
}
1011

11-
class Box(var value: {
12-
def foo(): Int
13-
})
12+
class Box(var value: Foo)
1413

1514
object A:
1615
val box1: Box = new Box(new C(5))
1716
val box2: Box = new Box(new D(10))
18-
val m: Int = box1.value.foo() // error
17+
val m: Int = box1.value.foo()

tests/init-global/neg/global-by-name.scala

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- Error: tests/init/neg/global-cycle1.scala:1:7 -----------------------------------------------------------------------
1+
-- Error: tests/init-global/neg/global-cycle1.scala:1:7 ----------------------------------------------------------------
22
1 |object A { // error
33
|^
44
|Cyclic initialization: object A -> object B -> object A. Calling trace:
@@ -8,7 +8,15 @@
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 // error [ global-cycle1.scala:6 ]
1212
| ^
1313
2 | val a: Int = B.b
1414
3 |}
15+
-- Error: tests/init-global/neg/global-cycle1.scala:6:17 ---------------------------------------------------------------
16+
6 | val b: Int = A.a // error
17+
| ^^^
18+
| Access uninitialized field value a. Call trace:
19+
| -> object B { [ global-cycle1.scala:5 ]
20+
| ^
21+
| -> val b: Int = A.a // error [ global-cycle1.scala:6 ]
22+
| ^^^

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ object A { // error
33
}
44

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

99
@main
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object A {
2+
val a: Int = B.foo()
3+
}
4+
5+
object B {
6+
def foo(): Int = A.a * 2 // error
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class A(x: Int) {
2+
def foo(): Int = B.a + 10 // error
3+
}
4+
5+
object B {
6+
val a: Int = A(4).foo()
7+
}

tests/init-global/pos/global-cycle4.scala renamed to tests/init-global/neg/global-cycle4.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ 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 // error
1111
}
1212

1313
class D(x: Int) {
1414
def bar(): A = if x > 0 then new B else new C
1515
}
1616

17-
object O { // error
17+
object O {
1818
val a: Int = D(5).bar().foo()
1919
}

tests/init-global/neg/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() // error
1111
}
1212

1313
class Y extends X {
@@ -19,5 +19,5 @@ object C {
1919
}
2020

2121
def main = {
22-
A.a = new Y(); C // error
22+
A.a = new Y(); C
2323
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ object O { // error
1212
}
1313

1414
object P {
15-
val m = Q.bar(new B: @annotation.init.expose)
15+
val m = Q.bar(new B)
1616
}
1717

1818
object Q {

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

Lines changed: 0 additions & 12 deletions
This file was deleted.

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import scala.annotation.init
2-
31
object A:
42
class Pair(val f: Int => Unit, val g: () => Int)
53
val p: Pair = foo()
@@ -8,7 +6,7 @@ object A:
86
var x = 6
97
new Pair(
108
y => x = y,
11-
(() => x): @init.expose // error
9+
(() => x) // error
1210
)
1311

1412

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import scala.annotation.init
2-
31
object A:
42
class Pair(val f: Int => Unit, val g: () => Int)
53
val p: Pair = foo()
64

75
def foo(): Pair =
86
var x = 6
97
new Pair(
10-
(y => x = y): @init.expose, // error
8+
(y => x = y), // error
119
() => x
1210
)
1311

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import scala.annotation.init
2-
31
class Box(x: Int):
42
def foo(): Int = 100
53

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import scala.annotation.init
2-
31
class Box(x: Int):
42
def foo(): Int = 100
53

64
object A:
75
val array: Array[Box] = new Array(1)
8-
array(0) = new Box(10): @init.expose
6+
array(0) = new Box(10)
97
val n = array(0).foo() // ok
108

119
object B:
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
case class Foo(name: String)
22

3-
object O:
3+
object O: // error
44
val a = Foo("Apple")
55
val b = Foo("Banana")
66
val c = Foo("Cherry")
77

88
object Foo:
9-
val all: List[Foo] = List(O.a, O.b, O.c) // error
9+
val all: List[Foo] = List(O.a, O.b, O.c) // error // error // error

tests/init-global/pos/global-local-var.scala renamed to tests/init-global/neg/global-local-var.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class A(x: Int) {
77
sum += i
88
i += 1
99

10-
B.a + 10 + sum
10+
B.a + 10 + sum // error
1111
}
1212
}
1313

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import scala.annotation.init
2-
31
trait B { def foo(): Int }
42
class C(var x: Int) extends B { def foo(): Int = 20 }
53
class D(var y: Int) extends B { def foo(): Int = A.m } // error
64
class Box(var value: B)
75

86
object A:
9-
val box1: Box = new Box(new C(5): @init.expose)
10-
val box2: Box = new Box(new D(10): @init.expose)
7+
val box1: Box = new Box(new C(5))
8+
val box2: Box = new Box(new D(10))
119
val m: Int = box1.value.foo()

tests/init-global/neg/i11262.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
object A { val x: String = B.y } // error
2-
object B { val y: String = A.x }
2+
object B { val y: String = A.x } // error

tests/init-global/neg/i12544b.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ object Enum:
55
object nested: // error
66
val a: Enum = Case
77

8-
val b: Enum = f(nested.a)
8+
val b: Enum = f(nested.a) // error
99

1010
def f(e: Enum): Enum = e
1111

tests/init-global/neg/mutable-read3.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ object A:
33
val box: Box = new Box(0)
44

55
object B:
6-
val boxes: Array[A.Box] = Array(A.box)
6+
val boxes: Array[A.Box] = new Array(1)
7+
boxes(0) = A.box
78
val box: A.Box = boxes(0)
89
val x: Int = box.value // error
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
object Names:
1+
object Names: // error
22
val ctorString = "<init>"
33
val ctorName: MethodName = MethodName.apply(ctorString)
44

55
class MethodName(encoded: String)
66
object MethodName:
7-
val ctor: MethodName = new MethodName(Names.ctorString) // error
7+
val ctor: MethodName = new MethodName(Names.ctorString)
88
def apply(name: String): MethodName = new MethodName(name)
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import scala.annotation.init
2-
31
def time[A](f: => A): A =
42
val start = System.nanoTime
53
val res = f
@@ -9,5 +7,5 @@ def time[A](f: => A): A =
97
case class Foo(data: Int)
108

119
object o:
12-
val foo = time(Foo(3): @init.expose)
10+
val foo = time(Foo(3))
1311
println(foo.data)

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

Lines changed: 0 additions & 7 deletions
This file was deleted.

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

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
import scala.annotation.init
2-
31
class C:
42
def double(x: Int): Int = x * 2
53

64
object A:
75
val n: Int = 10
8-
val f: C => Int = foo(n: @init.expose)
6+
val f: C => Int = foo(n)
97

108
def foo(x: Int): C => Int =
11-
c => c.double(x: @init.expose)
9+
c => c.double(x)
1210

1311

1412
object B:
15-
var y = A.f(new C: @init.expose)
13+
var y = A.f(new C)

tests/init-global/pos/global-region1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ class D(var y: Int) extends B { def foo(): Int = A.m }
66
class Box(var value: B)
77

88
object A:
9-
val box1: Box = new Box(new C(5): @init.expose): @init.region
10-
val box2: Box = new Box(new D(10): @init.expose): @init.region
9+
val box1: Box = new Box(new C(5)): @init.region
10+
val box2: Box = new Box(new D(10)): @init.region
1111
val m: Int = box1.value.foo() // ok

tests/init-global/neg/global-this.scala renamed to tests/init-global/pos/global-this.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ object NameKinds:
33
class Info
44
class QualifiedNameKind(tag: Int, val separator: String) extends NameKind(tag):
55
qualifiedNameKinds(tag) = this // error
6-
76

87
val MAX_TAG = 8
98
val qualifiedNameKinds = new Array[QualifiedNameKind](MAX_TAG)
109

1110
val QualifiedName: QualifiedNameKind = new QualifiedNameKind(0, ".")
12-
val FlatName: QualifiedNameKind = new QualifiedNameKind(1, "$")
11+
val FlatName: QualifiedNameKind = new QualifiedNameKind(1, "$")

0 commit comments

Comments
 (0)