Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for macro annotation that resolves macro-based implicit crashing …
…the compiler (#20353) 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`](https://github.com/scala/scala3/blob/3.4.1/compiler/src/dotty/tools/dotc/inlines/Inliner.scala#L1067) 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 ...
- Loading branch information