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

Tests macro generates invalid code with Scala 3 and Scala.js #251

Open
japgolly opened this issue May 18, 2021 · 1 comment
Open

Tests macro generates invalid code with Scala 3 and Scala.js #251

japgolly opened this issue May 18, 2021 · 1 comment

Comments

@japgolly
Copy link
Collaborator

Add as utest/test/src/test/utest/MacroTest.scala:

package test.utest

import utest._

object MacroTest extends TestSuite {

  sealed trait Blah
  object Blah {
    case object X extends Blah
    case class Y(s: String) extends Blah
  }

  override def tests = Tests {
    "1" - {
      var b: Blah = Blah.X
      val x1 = b match {case Blah.Y(_) => true; case _ => false}
      println("Result: " + x1)
    }
  }
}

Then run ./mill all __.test:

X test.utest.MacroTest.1 0ms 
  org.scalajs.linker.runtime.UndefinedBehaviorError: java.lang.ClassCastException: X is not an instance of test.utest.MacroTest$Blah$Y
    java.lang.StackTrace$.captureState(StackTrace.scala:69)
    org.scalajs.linker.runtime.UndefinedBehaviorError.fillInStackTrace(Throwables.scala:48)
    java.lang.Throwable.<init>(Throwables.scala:36)
    java.lang.Error.<init>(Throwables.scala:259)
    java.lang.Error.<init>(Throwables.scala:260)
    java.lang.VirtualMachineError.<init>(Throwables.scala:331)
    org.scalajs.linker.runtime.UndefinedBehaviorError.<init>(UndefinedBehaviorError.scala:25)
    org.scalajs.linker.runtime.UndefinedBehaviorError.<init>(UndefinedBehaviorError.scala:30)
    <jscode>.$throwClassCastException(out.js:95)
    <jscode>.$as_Ltest_utest_MacroTest$Blah$Y(MacroTest.scala:9)
  java.lang.ClassCastException: X is not an instance of test.utest.MacroTest$Blah$Y
    java.lang.StackTrace$.captureState(StackTrace.scala:69)
    java.lang.ClassCastException.fillInStackTrace(Throwables.scala:48)
    java.lang.Throwable.<init>(Throwables.scala:36)
    java.lang.Exception.<init>(Throwables.scala:380)
    java.lang.RuntimeException.<init>(Throwables.scala:457)
    java.lang.RuntimeException.<init>(Throwables.scala:458)
    java.lang.RuntimeException.<init>(Throwables.scala:460)
    java.lang.ClassCastException.<init>(Throwables.scala:357)
    <jscode>.$throwClassCastException(out.js:95)
    <jscode>.$as_Ltest_utest_MacroTest$Blah$Y(MacroTest.scala:9)
...
1 targets failed
all 1 targets failed
utest.js[3.0.0,1.5.1].test.test 1 tests failed: 
  test.utest.MacroTest test.utest.MacroTest.1
@bwbecker
Copy link

I've noted the same issue but hadn't yet reduced it down to this succinct an example.

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

2 participants