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

Merged
merged 3 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/inlines/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,8 @@ class Inliner(val call: tpd.Tree)(using Context):
new TreeAccumulator[List[Symbol]] {
override def apply(syms: List[Symbol], tree: tpd.Tree)(using Context): List[Symbol] =
tree match {
case Closure(env, meth, tpt) if meth.symbol.isAnonymousFunction =>
this(syms, tpt :: env)
case tree: RefTree if tree.isTerm && level == -1 && tree.symbol.isDefinedInCurrentRun && !tree.symbol.isLocal =>
foldOver(tree.symbol :: syms, tree)
case _: This if level == -1 && tree.symbol.isDefinedInCurrentRun =>
Expand Down
22 changes: 22 additions & 0 deletions tests/pos-macros/i20353/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//> using options -experimental -Yno-experimental
hamzaremmal marked this conversation as resolved.
Show resolved Hide resolved

import scala.annotation.{experimental, MacroAnnotation}
import scala.quoted.*

class ImplicitValue

object ImplicitValue:
inline given ImplicitValue =
${ makeImplicitValue }

def makeImplicitValue(using Quotes) =
import quotes.reflect.*
'{ ImplicitValue() }
end ImplicitValue

@experimental
class Test extends MacroAnnotation:
def transform(using Quotes)(definition: quotes.reflect.Definition, companion: Option[quotes.reflect.Definition]) =
import quotes.reflect.*
Implicits.search(TypeRepr.of[ImplicitValue])
List(definition)
17 changes: 17 additions & 0 deletions tests/pos-macros/i20353/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//> using options -experimental -Yno-experimental
hamzaremmal marked this conversation as resolved.
Show resolved Hide resolved

class OuterClass:
@Test
class InnerClass

@Test
object InnerObject
end OuterClass

object OuterObject:
@Test
class InnerClass

@Test
object InnerObject
end OuterObject
Loading