com-lihaoyi / utest

A simple testing framework for Scala
MIT License
487 stars 80 forks source link

ClassCastException under Scala 3 #233

Open jodersky opened 3 years ago

jodersky commented 3 years ago

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

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 commented 3 years ago

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