Skip to content

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

Merged
merged 1 commit into from
Mar 15, 2018

Conversation

nicolasstucki
Copy link
Contributor

No description provided.

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")
Copy link
Contributor

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.

Copy link
Contributor Author

@nicolasstucki nicolasstucki Mar 12, 2018

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

Copy link
Contributor

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()
          ^

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@nicolasstucki nicolasstucki force-pushed the quote-error-reporting branch from 649cda8 to a4a6c28 Compare March 13, 2018 18:05
@nicolasstucki nicolasstucki merged commit 222516a into scala:master Mar 15, 2018
@allanrenucci allanrenucci deleted the quote-error-reporting branch March 15, 2018 16:12
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

Successfully merging this pull request may close these issues.

3 participants