Skip to content

Commit 156f685

Browse files
authored
Merge pull request #113 from scala/backport-lts-3.3-20353
Backport "Fix for macro annotation that resolves macro-based implicit crashing the compiler" to 3.3 LTS
2 parents ea6d866 + 4569bb4 commit 156f685

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

compiler/src/dotty/tools/dotc/inlines/Inliner.scala

+2
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,8 @@ class Inliner(val call: tpd.Tree)(using Context):
10651065
new TreeAccumulator[List[Symbol]] {
10661066
override def apply(syms: List[Symbol], tree: tpd.Tree)(using Context): List[Symbol] =
10671067
tree match {
1068+
case Closure(env, meth, tpt) if meth.symbol.isAnonymousFunction =>
1069+
this(syms, tpt :: env)
10681070
case tree: RefTree if tree.isTerm && level == -1 && tree.symbol.isDefinedInCurrentRun && !tree.symbol.isLocal =>
10691071
foldOver(tree.symbol :: syms, tree)
10701072
case _: This if level == -1 && tree.symbol.isDefinedInCurrentRun =>

tests/pos-macros/i20353/Macro_1.scala

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//> using options -experimental
2+
3+
import scala.annotation.{experimental, MacroAnnotation}
4+
import scala.quoted.*
5+
6+
class ImplicitValue
7+
8+
object ImplicitValue:
9+
inline given ImplicitValue =
10+
${ makeImplicitValue }
11+
12+
def makeImplicitValue(using Quotes) =
13+
import quotes.reflect.*
14+
'{ ImplicitValue() }
15+
end ImplicitValue
16+
17+
@experimental
18+
class Test extends MacroAnnotation:
19+
def transform(using Quotes)(definition: quotes.reflect.Definition, companion: Option[quotes.reflect.Definition]) =
20+
import quotes.reflect.*
21+
Implicits.search(TypeRepr.of[ImplicitValue])
22+
List(definition)

tests/pos-macros/i20353/Test_2.scala

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//> using options -experimental
2+
3+
class OuterClass:
4+
@Test
5+
class InnerClass
6+
7+
@Test
8+
object InnerObject
9+
end OuterClass
10+
11+
object OuterObject:
12+
@Test
13+
class InnerClass
14+
15+
@Test
16+
object InnerObject
17+
end OuterObject

0 commit comments

Comments
 (0)