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

Wrapped typeCheckErrors is emitting compilation errors #12656

Closed
soronpo opened this issue May 31, 2021 · 2 comments · Fixed by #13543
Closed

Wrapped typeCheckErrors is emitting compilation errors #12656

soronpo opened this issue May 31, 2021 · 2 comments · Fixed by #13543
Assignees
Milestone

Comments

@soronpo
Copy link
Contributor

soronpo commented May 31, 2021

The typeCheckErrors when used inside another definition does not trap the error messages.
Affects munit.

Compiler version

v3.0.0 (also tested on nightly)

Minimized code

  transparent inline def expectCompileError(
      inline code: String,
      expectedMsg: String
  ) =
    val errors = compiletime.testing.typeCheckErrors(code)
    assert(errors.head.message == expectedMsg)

  expectCompileError("""compiletime.error("some error")""", "some error")

Output

error: some error

Expectation

No compilation error (the error should be trapped)

@soronpo
Copy link
Contributor Author

soronpo commented Sep 13, 2021

@nicolasstucki I want to try and tackle this, since there is no easy workaround and I'm currently avoiding creating tests because of this. Any suggestion where to begin?

@nicolasstucki
Copy link
Contributor

This test should catch what we need tests/run/i12656.scala

transparent inline def expectCompileError(
    inline code: String,
    expectedMsg: String
) =
  val errors = compiletime.testing.typeCheckErrors(code)
  assert(errors.head.message == expectedMsg, (errors.head.message, expectedMsg))

@main def Test = expectCompileError("""compiletime.error("some error")""", "some error")

We process compiletime.error here https://github.com/lampepfl/dotty/blob/master/compiler/src/dotty/tools/dotc/typer/Inliner.scala#L335-L349.
We should probably set a new reporter that does not propagate the errors to the outer context reporter. The reporter can be set on the TyperState, maybe when we do ctx.fresh.setNewTyperState().

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

Successfully merging a pull request may close this issue.

4 participants