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

Fix for macro annotation that resolves macro-based implicit crashing the compiler #20353

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

pweisenburger
Copy link
Contributor

When (1) macro-annotating a class or object nested in another class or object and (2) the annotation macro tries to summon an implicit value using Implicits.search and (3) the implicit search needs to expand a given macro, the compiler crashes with:

Failed to evaluate macro.
  Caused by class dotty.tools.dotc.CompilationUnit$SuspendException

I found that the reason for the crash is macroDependencies returning locally defined variables, which, I believe, it should not. In particular it returns a list containing $anonfun for trees of the following shape that appear when resolving implicit macros:

{
  def $anonfun(using contextual$1: scala.quoted.Quotes): scala.quoted.Expr[<type for implicit search>] =
    <given macro for implicit value>(contextual$1)
  closure($anonfun)
}

This PR skips over such Closure nodes, which should be the correct behavior. Not sure if there are other cases that macroDependencies handles incorrectly and that should be fixed ...

@hamzaremmal
Copy link
Member

Hey, to fix the CI run, can you rebase your work on the latest commit in main ?

@pweisenburger
Copy link
Contributor Author

I rebased on the main branch.

@hamzaremmal
Copy link
Member

Hi, I've been investigating this for the past few days and I'm not sure why the closure is created. I wasn't able to reproduce the behavior with other constructs. I'm still looking into it and I will answer back here when I have a final answer.

@pweisenburger
Copy link
Contributor Author

Thanks! 🙂

I assumed this was normal behavior for expanding macro givens, as at some point you probably want a context function Quotes ?=> T (to inject the implicit Quotes argument), hence the given is eta-expanded, hence the closure. But this guess could be wrong ...

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.

None yet

2 participants