Commit d86f44d
authored
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 ...File tree
3 files changed
+41
-0
lines changed- compiler/src/dotty/tools/dotc/inlines
- tests/pos-macros/i20353
3 files changed
+41
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1107 | 1107 | | |
1108 | 1108 | | |
1109 | 1109 | | |
| 1110 | + | |
| 1111 | + | |
1110 | 1112 | | |
1111 | 1113 | | |
1112 | 1114 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
0 commit comments