Skip to content

Commit 73cda0c

Browse files
authored
Merge pull request #14794 from lampepfl/parametricity-for-safe-init-enums
Allow non-hot values in SeqLiterals
2 parents 566eb5e + 6ff1edd commit 73cda0c

File tree

6 files changed

+14
-29
lines changed

6 files changed

+14
-29
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,9 +1234,9 @@ object Semantic {
12341234

12351235
case SeqLiteral(elems, elemtpt) =>
12361236
val ress = elems.map { elem =>
1237-
eval(elem, thisV, klass).ensureHot("May only use initialized value as method arguments", elem)
1237+
eval(elem, thisV, klass)
12381238
}
1239-
Result(Hot, ress.flatMap(_.errors))
1239+
Result(ress.map(_.value).join, ress.flatMap(_.errors))
12401240

12411241
case Inlined(call, bindings, expansion) =>
12421242
val trace1 = trace.add(expr)

tests/init/neg/enum-desugared.check

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
1-
-- Error: tests/init/neg/enum-desugared.scala:17:15 --------------------------------------------------------------------
2-
17 | Array(this.LazyErrorId, this.NoExplanationID) // error // error
3-
| ^^^^^^^^^^^^^^^^
4-
| Cannot prove that the value is fully initialized. May only use initialized value as method arguments.
1+
-- Error: tests/init/neg/enum-desugared.scala:17:10 --------------------------------------------------------------------
2+
17 | Array(this.LazyErrorId, this.NoExplanationID) // error
3+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
| Cannot prove that the value is fully initialized. Only initialized values may be used as arguments.
55
|
66
| The unsafe promotion may cause the following problem:
77
| Calling the external method method name may cause initialization errors. Calling trace:
8-
| -> Array(this.LazyErrorId, this.NoExplanationID) // error // error [ enum-desugared.scala:17 ]
9-
| ^^^^^^^^^^^^^^^^
8+
| -> Array(this.LazyErrorId, this.NoExplanationID) // error [ enum-desugared.scala:17 ]
9+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1010
| -> override def productPrefix: String = this.name() [ enum-desugared.scala:29 ]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12-
-- Error: tests/init/neg/enum-desugared.scala:17:33 --------------------------------------------------------------------
13-
17 | Array(this.LazyErrorId, this.NoExplanationID) // error // error
14-
| ^^^^^^^^^^^^^^^^^^^^
15-
| Cannot prove that the value is fully initialized. May only use initialized value as method arguments.
16-
|
17-
| The unsafe promotion may cause the following problem:
18-
| Calling the external method method ordinal may cause initialization errors. Calling trace:
19-
| -> Array(this.LazyErrorId, this.NoExplanationID) // error // error [ enum-desugared.scala:17 ]
20-
| ^^^^^^^^^^^^^^^^^^^^
21-
| -> def errorNumber: Int = this.ordinal() - 2 [ enum-desugared.scala:8 ]
22-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/init/neg/enum-desugared.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ object ErrorMessageID {
1414
final val NoExplanationID = $new(1, "NoExplanationID")
1515

1616
private[this] val $values: Array[ErrorMessageID] =
17-
Array(this.LazyErrorId, this.NoExplanationID) // error // error
17+
Array(this.LazyErrorId, this.NoExplanationID) // error
1818

1919
def values: Array[ErrorMessageID] = $values.clone()
2020

tests/init/neg/enum.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-- Error: tests/init/neg/enum.scala:4:8 --------------------------------------------------------------------------------
22
4 | NoExplanationID // error
33
| ^
4-
| Cannot prove that the value is fully initialized. May only use initialized value as method arguments.
4+
| Cannot prove that the value is fully initialized. Only initialized values may be used as arguments.
55
|
66
| The unsafe promotion may cause the following problem:
77
| Calling the external method method name may cause initialization errors. Calling trace:

tests/init/neg/leak-warm.check

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
-- Error: tests/init/neg/leak-warm.scala:18:26 -------------------------------------------------------------------------
2-
18 | val l: List[A] = List(c, d) // error // error
3-
| ^
4-
| Cannot prove that the value is 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-
| Cannot prove that the value is fully initialized. May only use initialized value as method arguments.
2+
18 | val l: List[A] = List(c, d) // error
3+
| ^^^^
4+
| Cannot prove that the value is fully initialized. Only initialized values may be used as 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) // error // error
18+
val l: List[A] = List(c, d) // error
1919
val l2 = l.map(_.m())
2020
}

0 commit comments

Comments
 (0)