Skip to content

Allow non-hot values in SeqLiterals #14794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/init/Semantic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1234,9 +1234,9 @@ object Semantic {

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

case Inlined(call, bindings, expansion) =>
val trace1 = trace.add(expr)
Expand Down
23 changes: 6 additions & 17 deletions tests/init/neg/enum-desugared.check
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
-- Error: tests/init/neg/enum-desugared.scala:17:15 --------------------------------------------------------------------
17 | Array(this.LazyErrorId, this.NoExplanationID) // error // error
| ^^^^^^^^^^^^^^^^
| Cannot prove that the value is fully initialized. May only use initialized value as method arguments.
-- Error: tests/init/neg/enum-desugared.scala:17:10 --------------------------------------------------------------------
17 | Array(this.LazyErrorId, this.NoExplanationID) // error
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Cannot prove that the value is fully initialized. Only initialized values may be used as arguments.
|
| The unsafe promotion may cause the following problem:
| Calling the external method method name may cause initialization errors. Calling trace:
| -> Array(this.LazyErrorId, this.NoExplanationID) // error // error [ enum-desugared.scala:17 ]
| ^^^^^^^^^^^^^^^^
| -> Array(this.LazyErrorId, this.NoExplanationID) // error [ enum-desugared.scala:17 ]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| -> override def productPrefix: String = this.name() [ enum-desugared.scala:29 ]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-- Error: tests/init/neg/enum-desugared.scala:17:33 --------------------------------------------------------------------
17 | Array(this.LazyErrorId, this.NoExplanationID) // error // error
| ^^^^^^^^^^^^^^^^^^^^
| Cannot prove that the value is fully initialized. May only use initialized value as method arguments.
|
| The unsafe promotion may cause the following problem:
| Calling the external method method ordinal may cause initialization errors. Calling trace:
| -> Array(this.LazyErrorId, this.NoExplanationID) // error // error [ enum-desugared.scala:17 ]
| ^^^^^^^^^^^^^^^^^^^^
| -> def errorNumber: Int = this.ordinal() - 2 [ enum-desugared.scala:8 ]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 changes: 1 addition & 1 deletion tests/init/neg/enum-desugared.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ object ErrorMessageID {
final val NoExplanationID = $new(1, "NoExplanationID")

private[this] val $values: Array[ErrorMessageID] =
Array(this.LazyErrorId, this.NoExplanationID) // error // error
Array(this.LazyErrorId, this.NoExplanationID) // error

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

Expand Down
2 changes: 1 addition & 1 deletion tests/init/neg/enum.check
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- Error: tests/init/neg/enum.scala:4:8 --------------------------------------------------------------------------------
4 | NoExplanationID // error
| ^
| Cannot prove that the value is fully initialized. May only use initialized value as method arguments.
| Cannot prove that the value is fully initialized. Only initialized values may be used as arguments.
|
| The unsafe promotion may cause the following problem:
| Calling the external method method name may cause initialization errors. Calling trace:
Expand Down
10 changes: 3 additions & 7 deletions tests/init/neg/leak-warm.check
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
-- Error: tests/init/neg/leak-warm.scala:18:26 -------------------------------------------------------------------------
18 | val l: List[A] = List(c, d) // error // error
| ^
| Cannot prove that the value is fully initialized. May only use initialized value as method arguments.
-- Error: tests/init/neg/leak-warm.scala:18:29 -------------------------------------------------------------------------
18 | val l: List[A] = List(c, d) // error // error
| ^
| Cannot prove that the value is fully initialized. May only use initialized value as method arguments.
18 | val l: List[A] = List(c, d) // error
| ^^^^
| Cannot prove that the value is fully initialized. Only initialized values may be used as arguments.
2 changes: 1 addition & 1 deletion tests/init/neg/leak-warm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ object leakWarm {
}
val c = new C(1, 2)
val d = new D(3, 4)
val l: List[A] = List(c, d) // error // error
val l: List[A] = List(c, d) // error
val l2 = l.map(_.m())
}