Skip to content

Commit

Permalink
Merge pull request #10351 from retronym/ticket/12758-string-switch-as…
Browse files Browse the repository at this point in the history
…ync-boxedunit

Fix crasher with `-Xasync`, string switch + boxed `Unit`
  • Loading branch information
lrytz committed Mar 31, 2023
2 parents 5327194 + 9f978bc commit 2fa3ee2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,10 @@ private[async] trait AnfTransform extends TransformUtils {
if (isPatMatGeneratedJump(tree)) assignUnitType(tree)

if (!needsResultVar || isUnitType(tree.tpe) || (tree.tpe =:= definitions.NothingTpe)) {
core(NoSymbol)
if (tree.tpe =:= definitions.BoxedUnitTpe) {
currentStats += assignUnitType(core(NoSymbol))
literalBoxedUnit
} else core(NoSymbol)
} else {
val varDef = defineVar(nameSource(), tree.tpe, tree.pos)
currentStats += varDef
Expand Down
29 changes: 29 additions & 0 deletions test/async/run/string-switch-bug.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// scalac: -Xasync
import scala.tools.partest.async.OptionAwait._
import org.junit.Assert._

// Scala.js compatible test suite for -Xasync that doesn't use Scala futures
object Test {
def main(args: Array[String]): Unit = {
stringSwitchBug()
}

private def stringSwitchBug() = {
assertEquals(Some(true), optionally {
val x: String = ""
val as = List("x")
val it = as.iterator
var okay = false
while (it.hasNext) {
val x = it.next()
val res = (x match {
case "x" =>
okay = value(Some(1)) == 1
()
case _ => ()
})
}
okay
})
}
}

0 comments on commit 2fa3ee2

Please sign in to comment.