From da09d3a39d1322b370d4167703d8b876e10f0767 Mon Sep 17 00:00:00 2001 From: Xavientois Date: Sun, 27 Mar 2022 16:42:58 -0400 Subject: [PATCH] Allow non-hot values in SeqLiterals Closes #14460, #14751 Do not ensure that elements in a SeqLiteral are Hot. Review by @liufengyun --- .../tools/dotc/transform/init/Semantic.scala | 4 ++-- tests/init/neg/enum-desugared.check | 19 +++++-------------- tests/init/neg/enum-desugared.scala | 2 +- tests/init/neg/enum.check | 2 +- tests/init/neg/leak-warm.check | 10 +++------- tests/init/neg/leak-warm.scala | 2 +- 6 files changed, 13 insertions(+), 26 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/transform/init/Semantic.scala b/compiler/src/dotty/tools/dotc/transform/init/Semantic.scala index 7e72e35089c6..25ea09c3ade4 100644 --- a/compiler/src/dotty/tools/dotc/transform/init/Semantic.scala +++ b/compiler/src/dotty/tools/dotc/transform/init/Semantic.scala @@ -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) diff --git a/tests/init/neg/enum-desugared.check b/tests/init/neg/enum-desugared.check index 6417b8c5cea7..a1b273387be3 100644 --- a/tests/init/neg/enum-desugared.check +++ b/tests/init/neg/enum-desugared.check @@ -1,18 +1,9 @@ --- 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 ] diff --git a/tests/init/neg/enum-desugared.scala b/tests/init/neg/enum-desugared.scala index eb80f112a06c..8c1f3662f926 100644 --- a/tests/init/neg/enum-desugared.scala +++ b/tests/init/neg/enum-desugared.scala @@ -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() diff --git a/tests/init/neg/enum.check b/tests/init/neg/enum.check index eb48920b47ea..d85e760890af 100644 --- a/tests/init/neg/enum.check +++ b/tests/init/neg/enum.check @@ -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: diff --git a/tests/init/neg/leak-warm.check b/tests/init/neg/leak-warm.check index 8219283b3c16..7eac95bf8de7 100644 --- a/tests/init/neg/leak-warm.check +++ b/tests/init/neg/leak-warm.check @@ -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. diff --git a/tests/init/neg/leak-warm.scala b/tests/init/neg/leak-warm.scala index f562ab4ec416..f12b22dce8d9 100644 --- a/tests/init/neg/leak-warm.scala +++ b/tests/init/neg/leak-warm.scala @@ -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()) }