Skip to content

Commit 43553ea

Browse files
committed
Improve error message
1 parent c1595c5 commit 43553ea

File tree

8 files changed

+24
-24
lines changed

8 files changed

+24
-24
lines changed

compiler/src/dotty/tools/dotc/transform/init/Semantic.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,7 @@ object Semantic {
10941094

10951095
/** Utility definition used for better error-reporting of argument errors */
10961096
case class ArgInfo(value: Value, source: Tree) {
1097-
def promote: Contextual[Unit] = value.promote("Cannot prove the argument is fully initialized.", source)
1097+
def promote: Contextual[Unit] = value.promote("Cannot prove the argument is fully initialized. Only fully initialized values are safe to leak.", source)
10981098
}
10991099

11001100
/** Evaluate an expression with the given value for `this` in a given class `klass`
@@ -1223,9 +1223,9 @@ object Semantic {
12231223
lhs match
12241224
case Select(qual, _) =>
12251225
eval(qual, thisV, klass)
1226-
eval(rhs, thisV, klass).ensureHot("May only assign fully initialized value.", rhs)
1226+
eval(rhs, thisV, klass).ensureHot("The RHS of an assignment to a field must be fully initialized.", rhs)
12271227
case id: Ident =>
1228-
eval(rhs, thisV, klass).ensureHot("May only assign fully initialized value.", rhs)
1228+
eval(rhs, thisV, klass).ensureHot("The RHS of an assignment to a field must be fully initialized.", rhs)
12291229

12301230
case closureDef(ddef) =>
12311231
Fun(ddef.rhs, thisV, klass, env)
@@ -1249,7 +1249,7 @@ object Semantic {
12491249
eval(cases.map(_.body), thisV, klass).join
12501250

12511251
case Return(expr, from) =>
1252-
eval(expr, thisV, klass).ensureHot("return expression may only be initialized value.", expr)
1252+
eval(expr, thisV, klass).ensureHot("return expression must be fully initialized.", expr)
12531253

12541254
case WhileDo(cond, body) =>
12551255
eval(cond :: body :: Nil, thisV, klass)

tests/init/neg/closureLeak.check

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
-- Error: tests/init/neg/closureLeak.scala:11:14 -----------------------------------------------------------------------
22
11 | l.foreach(a => a.addX(this)) // error
33
| ^^^^^^^^^^^^^^^^^
4-
| Cannot prove the argument is fully initialized.
5-
| Promoting the value to fully initialized failed due to the following problem:
6-
| Cannot prove the argument is fully initialized. Calling trace:
7-
| -> l.foreach(a => a.addX(this)) // error [ closureLeak.scala:11 ]
8-
| ^^^^
4+
| Cannot prove the argument is fully initialized. Only fully initialized values are safe to leak.
5+
| Promoting the value to fully initialized failed due to the following problem:
6+
| Cannot prove the argument is fully initialized. Only fully initialized values are safe to leak. Calling trace:
7+
| -> l.foreach(a => a.addX(this)) // error [ closureLeak.scala:11 ]
8+
| ^^^^

tests/init/neg/default-this.check

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
-- Error: tests/init/neg/default-this.scala:9:8 ------------------------------------------------------------------------
22
9 | compare() // error
33
| ^^^^^^^
4-
| Cannot prove the argument is fully initialized. Calling trace:
5-
| -> val result = updateThenCompare(5) [ default-this.scala:11 ]
6-
| ^^^^^^^^^^^^^^^^^^^^
7-
| -> compare() // error [ default-this.scala:9 ]
8-
| ^^^^^^^
4+
| Cannot prove the argument is fully initialized. Only fully initialized values are safe to leak. Calling trace:
5+
| -> val result = updateThenCompare(5) [ default-this.scala:11 ]
6+
| ^^^^^^^^^^^^^^^^^^^^
7+
| -> compare() // error [ default-this.scala:9 ]
8+
| ^^^^^^^

tests/init/neg/inherit-non-hot.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- Error: tests/init/neg/inherit-non-hot.scala:6:34 --------------------------------------------------------------------
22
6 | if b == null then b = new B(this) // error
33
| ^^^^^^^^^^^
4-
| May only assign fully initialized value. Calling trace:
4+
| The RHS of an assignment to a field must be fully initialized. Calling trace:
55
| -> val c = new C [ inherit-non-hot.scala:19 ]
66
| ^^^^^
77
| -> class C extends A { [ inherit-non-hot.scala:15 ]

tests/init/neg/inlined-method.check

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
-- Error: tests/init/neg/inlined-method.scala:8:45 ---------------------------------------------------------------------
22
8 | scala.runtime.Scala3RunTime.assertFailed(message) // error
33
| ^^^^^^^
4-
| Cannot prove the argument is fully initialized. Calling trace:
5-
| -> Assertion.failAssert(this) [ inlined-method.scala:2 ]
6-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
7-
| -> scala.runtime.Scala3RunTime.assertFailed(message) // error [ inlined-method.scala:8 ]
8-
| ^^^^^^^
4+
| Cannot prove the argument is fully initialized. Only fully initialized values are safe to leak. Calling trace:
5+
| -> Assertion.failAssert(this) [ inlined-method.scala:2 ]
6+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
7+
| -> scala.runtime.Scala3RunTime.assertFailed(message) // error [ inlined-method.scala:8 ]
8+
| ^^^^^^^

tests/init/neg/local-warm4.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- Error: tests/init/neg/local-warm4.scala:18:20 -----------------------------------------------------------------------
22
18 | a = newA // error
33
| ^^^^
4-
| May only assign fully initialized value. Calling trace:
4+
| The RHS of an assignment to a field must be fully initialized. Calling trace:
55
| -> val a = new A(5) [ local-warm4.scala:26 ]
66
| ^^^^^^^^
77
| -> class A(x: Int) extends Foo(x) { [ local-warm4.scala:6 ]

tests/init/neg/promotion-loop.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- Error: tests/init/neg/promotion-loop.scala:16:10 --------------------------------------------------------------------
22
16 | println(b) // error
33
| ^
4-
| Cannot prove the argument is fully initialized.
4+
| Cannot prove the argument is fully initialized. Only fully initialized values are safe to leak.
55
| Promoting the value to fully initialized failed due to the following problem:
66
| Cannot prove that the field val outer is fully initialized. Calling trace:
77
| -> println(b) // error [ promotion-loop.scala:16 ]

tests/init/neg/t3273.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
-- Error: tests/init/neg/t3273.scala:4:42 ------------------------------------------------------------------------------
22
4 | val num1: LazyList[Int] = 1 #:: num1.map(_ + 1) // error
33
| ^^^^^^^^^^^^^^^
4-
| Cannot prove the argument is fully initialized.
4+
| Cannot prove the argument is fully initialized. Only fully initialized values are safe to leak.
55
| Promoting the value to fully initialized failed due to the following problem:
66
| Access non-initialized value num1. Calling trace:
77
| -> val num1: LazyList[Int] = 1 #:: num1.map(_ + 1) // error [ t3273.scala:4 ]
88
| ^^^^
99
-- Error: tests/init/neg/t3273.scala:5:61 ------------------------------------------------------------------------------
1010
5 | val num2: LazyList[Int] = 1 #:: num2.iterator.map(_ + 1).to(LazyList) // error
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12-
| Cannot prove the argument is fully initialized.
12+
| Cannot prove the argument is fully initialized. Only fully initialized values are safe to leak.
1313
| Promoting the value to fully initialized failed due to the following problem:
1414
| Access non-initialized value num2. Calling trace:
1515
| -> val num2: LazyList[Int] = 1 #:: num2.iterator.map(_ + 1).to(LazyList) // error [ t3273.scala:5 ]

0 commit comments

Comments
 (0)