Skip to content

compiletime.testing.typeCheckErrors doesn't report macro errors #11825

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

Closed
japgolly opened this issue Mar 19, 2021 · 2 comments
Closed

compiletime.testing.typeCheckErrors doesn't report macro errors #11825

japgolly opened this issue Mar 19, 2021 · 2 comments

Comments

@japgolly
Copy link
Contributor

Compiler version

3.0.0-RC1

Minimized code

a.scala:

object X:
  import scala.quoted.*

  inline def f: Int = ${ g }
  private def g(using Quotes): Expr[Int] = quotes.reflect.report.throwError("nope")

b.scala:

def test() =
  println(scala.compiletime.testing.typeCheckErrors("X.f")) // prints List()
  X.f // compilation error as expected

Output

  • The typeCheckErrors line prints List()
  • The X.f line fails to compile (as expected)

Expectation

typeCheckErrors should return List("nope") because that's the compilation error emitted by X.f.

Context

I came across this because I'm adding Scala 3 support to a Scala 2 library with macros. There are unit tests and ensure that the macros fail in certain cases and with Scala 2, it was enough to wrap the code in uTest's compileError(). It works fine for Scala 2 but when I try to run the shared tests against the Scala 3 code, uTest's compileError() reports failed-macro-calls as having no errors.

Looking at how compileError in implemented in uTest 0.7.7 / Scala 3.0.0-RC1, it uses typeCheckErrors. If typeCheckErrors isn't supposed to catch macro algorithms, then is there an alternative? There needs to be some kind of way because metaprogramming needs to be tested for all the same reasons that direct programming needs testing.

@smarter
Copy link
Member

smarter commented Mar 19, 2021

Have you tried with a nightly? I believe #11656 fixed that.

@japgolly
Copy link
Contributor Author

You're right! Just tried with a nightly and it works as expected. Thanks!

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

No branches or pull requests

2 participants