Skip to content

Commit b43fd9a

Browse files
committed
Update Desugar.scala
Update InteractiveDriver.scala Update closureLeak.scala Update default-this.scala Update enum.scala Update leak-this-inner.scala Update leak-this.scala Update leak-warm.scala Update local-warm.scala updated test cases updated-default-this updated tests
1 parent f55d373 commit b43fd9a

18 files changed

+64
-10
lines changed

tests/init/neg/Desugar.check

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- Error: tests/init/neg/Desugar.scala:12:61 ---------------------------------------------------------------------------
2+
12 | val f: PartialFunction[A, Int] = {case C(_, rhs) => rhs.x} // error
3+
| ^
4+
| Calling the external method constructor $anon may cause initialization errors. Calling trace:
5+
| -> val f: PartialFunction[A, Int] = {case C(_, rhs) => rhs.x} // error [ Desugar.scala:12 ]

tests/init/neg/Desugar.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ case class C[-T >: Int] (lhs: Int, rhs: Tree[T]) extends A {
99
}
1010

1111
object DesugarError {
12-
val f: PartialFunction[A, Int] = {case C(_, rhs) => rhs.x}
12+
val f: PartialFunction[A, Int] = {case C(_, rhs) => rhs.x} // error
1313
}
1414

1515

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- Error: tests/init/neg/InteractiveDriver.scala:22:71 -----------------------------------------------------------------
2+
22 | val l2: Seq[C[?]] = l.collect{ case x: InteractiveDriver[?] => h(x) } // error
3+
| ^
4+
|Calling the external method constructor $anon may cause initialization errors. Calling trace:
5+
| -> val l2: Seq[C[?]] = l.collect{ case x: InteractiveDriver[?] => h(x) } // error [ InteractiveDriver.scala:22 ]

tests/init/neg/InteractiveDriver.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ object InteractiveDriver {
1919
case _ => new C[Int]
2020
}
2121
val l: Seq[Any] = Seq(1, 2, new C[Double], new D[Int])
22-
val l2: Seq[C[?]] = l.collect{ case x: InteractiveDriver[?] => h(x) }
22+
val l2: Seq[C[?]] = l.collect{ case x: InteractiveDriver[?] => h(x) } // error
2323
}

tests/init/neg/closureLeak.check

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- Error: tests/init/neg/closureLeak.scala:11:14 -----------------------------------------------------------------------
2+
11 | l.foreach(a => a.addX(this)) // error
3+
| ^^^^^^^^^^^^^^^^^
4+
| Promoting the value to fully-initialized is unsafe. May only use initialized value as arguments
5+
|
6+
| The unsafe promotion may cause the following problem(s):
7+
|
8+
| 1. Promote the value under initialization to fully-initialized. May only use initialized value as arguments

tests/init/neg/closureLeak.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ class Outer {
88
}
99

1010
val l: List[A] = List(new A(5), new A(10))
11-
l.foreach(a => a.addX(this))
11+
l.foreach(a => a.addX(this)) // error
12+
val y = 10
1213
}

tests/init/neg/default-this.check

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- Error: tests/init/neg/default-this.scala:9:8 ------------------------------------------------------------------------
2+
9 | compare() // error
3+
| ^^^^^^^
4+
|Promote the value under initialization to fully-initialized. May only use initialized value as arguments Calling trace:
5+
| -> val result = updateThenCompare(5) [ default-this.scala:11 ]

tests/init/neg/default-this.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class A {
66
class B extends A {
77
def updateThenCompare(c: Int): Boolean = {
88
x = c
9-
compare()
9+
compare() // error
1010
}
1111
val result = updateThenCompare(5)
1212
}

tests/init/neg/enum.check

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- Error: tests/init/neg/enum.scala:4:8 --------------------------------------------------------------------------------
2+
4 | NoExplanationID // error
3+
| ^
4+
| Promoting the value to fully-initialized is unsafe. May only use initialized value as method arguments
5+
|
6+
| The unsafe promotion may cause the following problem(s):
7+
|
8+
| 1. Calling the external method method name may cause initialization errors. Calling trace:
9+
| -> NoExplanationID // error [ enum.scala:4 ]

tests/init/neg/enum.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
enum ErrorMessageID extends java.lang.Enum[ErrorMessageID] {
22
case
3-
LazyErrorId, // // errorNumber: -2
4-
NoExplanationID
3+
LazyErrorId,
4+
NoExplanationID // error
55
def errorNumber = ordinal - 2
66
}

tests/init/neg/leak-this-inner.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Error: tests/init/neg/leak-this-inner.scala:6:14 --------------------------------------------------------------------
2+
6 | val b = B(this) // error
3+
| ^^^^
4+
| Promote the value under initialization to fully-initialized. May only use initialized value as arguments

tests/init/neg/leak-this-inner.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ class A {
33
class B(a: A) {
44
val anotherX = A.this.x
55
}
6-
val b = B(this)
6+
val b = B(this) // error
77
val xAgain = b.anotherX
88
}

tests/init/neg/leak-this.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Error: tests/init/neg/leak-this.scala:2:33 --------------------------------------------------------------------------
2+
2 | val child: Child = new Child(this) // error
3+
| ^^^^
4+
| Promote the value under initialization to fully-initialized. May only use initialized value as arguments

tests/init/neg/leak-this.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class Parent {
2-
val child: Child = new Child(this)
2+
val child: Child = new Child(this) // error
33
}
44

55
class Child(parent: Parent) {

tests/init/neg/leak-warm.check

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- Error: tests/init/neg/leak-warm.scala:18:26 -------------------------------------------------------------------------
2+
18 | val l: List[A] = List(c, d) // error // error
3+
| ^
4+
| Promote the value under initialization to fully-initialized. May only use initialized value as method arguments
5+
-- Error: tests/init/neg/leak-warm.scala:18:29 -------------------------------------------------------------------------
6+
18 | val l: List[A] = List(c, d) // error // error
7+
| ^
8+
| Promote the value under initialization to fully-initialized. May only use initialized value as method arguments

tests/init/neg/leak-warm.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ object leakWarm {
1515
}
1616
val c = new C(1, 2)
1717
val d = new D(3, 4)
18-
val l: List[A] = List(c, d)
18+
val l: List[A] = List(c, d) // error // error
1919
val l2 = l.map(_.m())
2020
}

tests/init/neg/local-warm.check

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- Error: tests/init/neg/local-warm.scala:12:12 ------------------------------------------------------------------------
2+
12 | val t = m1() // error
3+
| ^^^^^^^^^^^^
4+
|Promote the value under initialization to fully-initialized. Local definitions may only hold initialized values Calling trace:
5+
| -> val x = g() [ local-warm.scala:15 ]

tests/init/neg/local-warm.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ abstract class A {
99

1010
class C extends A {
1111
def g() = {
12-
val t = m1()
12+
val t = m1() // error
1313
t.x
1414
}
1515
val x = g()

0 commit comments

Comments
 (0)