scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
230 stars 21 forks source link

Compiler crash with interaction between -Xasync, string switch and BoxedUnit #12758

Closed retronym closed 1 year ago

retronym commented 1 year ago

Reproduction steps

Scala version: (Is the bug only in Scala 3.x? If so, report it at https://github.com/lampepfl/dotty/issues/new/choose instead.)

test/async/run/string-switch-bug.scala

// 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
    })
  }
}

Problem

?! 1 - run/string-switch-bug.scala               [caught Types$TypeError - type mismatch;
 found   : Unit
 required: scala.runtime.BoxedUnit]