Skip to content

given swallows inline errors #9014

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
yilinwei opened this issue May 20, 2020 · 5 comments · Fixed by #9222
Closed

given swallows inline errors #9014

yilinwei opened this issue May 20, 2020 · 5 comments · Fixed by #9222
Labels
area:implicits related to implicits area:inline

Comments

@yilinwei
Copy link
Contributor

yilinwei commented May 20, 2020

Minimized example

trait Bar[T]

object Bar {

  import scala.quoted._

  inline given [T] as Bar[T] = ${ impl[T] }

  def impl[T](using qctx: QuoteContext, t: Type[T]): Expr[Bar[T]] = {
    import qctx.tasty._
    import util._

    t.unseal match {
      case _ =>
        qctx.error("Failed to expand!")
        '{ ??? }
    }
  }
}

object Foo {
  summon[Bar[String]]
}

Output

ala:9:21                                                                            
[error] 9 |  summon[Bar[String]]
[error]   |                     ^
[error]   |no implicit argument of type pprint.Bar[String] was found for parameter x 
of method summon in object DottyPredef.                                             
[error]   |I found:
[error]   |
[error]   |    {
[error]   |      {
[error]   |        ???
[error]   |      }:pprint.Bar[String]
[error]   |    }
[error]   |
[error]   |But method given_Bar_T in object Bar does not match type pprint.Bar[String
].                                                                                  

Expectation

Ideally, the macro expansion should show the qctx.error.

@yilinwei
Copy link
Contributor Author

yilinwei commented May 21, 2020

I would like to give this a go if at all possible?

I think the part which needs to be changed is Implicits.scala, where the error is dropped.

EDIT.

We do see an error in the Reporter which has the expected error from the quote context.

Since it feels as though it's a deliberate decision to drop the errors, I'm not entirely sure what to do.

@nicolasstucki
Copy link
Contributor

nicolasstucki commented May 22, 2020

Minimized to

trait Bar
inline given as Bar = compiletime.error("Failed to expand!")
val tests = summon[Bar]

The issue is that when looking for implicits, if an error is reported then implicit disregard this implicit and tries to find another one.

This leads to some interaction between error reporting in the Inliner and implicit search. It is not clear what the behavior should be in such cases.

@nicolasstucki nicolasstucki changed the title given swallows QuoteContext errors. given swallows inline errors May 22, 2020
@yilinwei
Copy link
Contributor Author

I see. Something I didn't quite understand is that the tree created by the macro appears in the error message (so I actually used that for debugging purposes). If there was another implicit it could try would that still be the case or does the implicit search just stop there?

@nicolasstucki
Copy link
Contributor

Interesting. Then it looks like this issue is mostly about reporting. The first step should be to track and understand which reporter receives the macro error and which prints the actual error.

@nicolasstucki
Copy link
Contributor

import scala.quoted._
trait Bar
inline given as Bar = ${ impl }
def impl(using qctx: QuoteContext): Expr[Bar] = qctx.throwError("Failed to expand!")
val tests = summon[Bar]

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jun 22, 2020
This it is possible to copy/paste the original call that failed and get the error message.
odersky added a commit that referenced this issue Jun 22, 2020
Fix #9014: On implicit search failure print original inline call
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:implicits related to implicits area:inline
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants