Skip to content
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

ClassCastException under Scala 3 #233

Open
jodersky opened this issue Feb 18, 2021 · 1 comment
Open

ClassCastException under Scala 3 #233

jodersky opened this issue Feb 18, 2021 · 1 comment

Comments

@jodersky
Copy link
Member

Matching on a None within a test leads to a ClassCastException under Scala 3.0.0-M3. A couple of notes:

  • this only happens when the match is defined directly in a test; it does not occur if the match is defined elsewhere (as can be seen in the "indirect" test below)
  • this type of error also manifests itself when matching on other wrapper types that extend some base type with a Nothing type parameter. E.g. matching Nil or Failure()
  • the error only occurs when matching None and the first case does not match (see snippet)
  • see this repository https://github.com/jodersky/utest-macro-bug for a self-contained project to reproduce the bug
import utest._
import scala.util.{
  Try, Success, Failure
}

object misc extends TestSuite {

  val tests = Tests {
    // this leads to a runtime error in utest under Scala 3.0.0-M3
    test("direct1") { // runtime error: java.lang.ClassCastException: class scala.None$ cannot be cast to class scala.Some
      (None: Option[Int]) match {
        case Some(a) =>
        case None =>
      }
    }
    test("direct2") { // works
      (None: Option[Int]) match {
        case None =>
        case Some(a) =>
      }
    }
    test("direct3") { // works
      (Some(1): Option[Int]) match {
        case Some(a) =>
        case None =>
      }
    }
    test("direct4") { // works
      (Some(1): Option[Int]) match {
        case None =>
        case Some(a) =>
      }
    }
    test("indirect") { // works
      runTest()
    }
  }

  def runTest() = {
    (None: Option[Int]) match {
      case Some(a) =>
      case None =>
    }
  }

}
@jodersky
Copy link
Member Author

jodersky commented Feb 18, 2021

one more thing to note, the same error occurs under Scala 3.0.0-M2 (with utest 0.7.4) and Scala 3.0.0-RC1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant