-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add error reporter for inlined quotes #4101
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
Add error reporter for inlined quotes #4101
Conversation
048181d
to
c2af961
Compare
inline def foo(inline b: Boolean): Unit = ~fooImpl(b) | ||
def fooImpl(b: Boolean)(implicit reporter: Reporter): Expr[Unit] = | ||
if (b) '(println("foo(true)")) | ||
else reporter.error("foo cannot be called with false") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using exceptions instead?
else throw new QuoteExpansionError("foo cannot be called with false")
The compiler could catch this particular one and forward the message to it's reporter. The downside compared to what you did in this PR it wouldn't cover warning, but it would also be easier to document.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is the solution in the first commit (reverted in the third commit). It did not cover warnings or multiple errors. Though with exceptions it was simpler and more intuitive for the users IMO. On the other hand, the current implementation is more flexible.
WDYT? @OlivierBlanvillain, @biboudis @liufengyun
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think having a single error and no distinction between errors and warnings shouldn't be a problem, @implicitNotFound
and @ambiguiousImplicits
works this way seem to be sufficient.
scala> import annotation.{implicitNotFound => inf}
import annotation.{implicitNotFound=>inf}
scala> @inf("A") trait A
defined trait A
scala> @inf("B") trait B
defined trait B
scala> def foo()(implicit a: A, b: B) = ()
foo: ()(implicit a: A, implicit b: B)Unit
scala> foo()
<console>:14: error: A
foo()
^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also tend to favor exceptions. Gives a simpler API for macros.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I will rework that version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
649cda8
to
a4a6c28
Compare
a4a6c28
to
345a808
Compare
No description provided.