diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index 7d5b26a7be85..60cf13d46f5f 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -1487,6 +1487,15 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) { super.ensureAccessible(tpe, superAccess, pos) } + /** Enter implicits in scope so that they can be found in implicit search. + * This is important for non-transparent inlines + */ + override def index(trees: List[untpd.Tree])(using Context): Context = + for case tree: untpd.MemberDef <- trees do + if tree.symbol.isOneOf(Flags.GivenOrImplicit) then + ctx.scope.openForMutations.enter(tree.symbol) + ctx + override def typedIdent(tree: untpd.Ident, pt: Type)(using Context): Tree = inlineIfNeeded(tryInlineArg(tree.asInstanceOf[tpd.Tree]) `orElse` super.typedIdent(tree, pt)) diff --git a/tests/pos/i12997.scala b/tests/pos/i12997.scala new file mode 100644 index 000000000000..288dcc6f4164 --- /dev/null +++ b/tests/pos/i12997.scala @@ -0,0 +1,15 @@ +import scala.compiletime._ + +// works +val a = { + given Int = 0 + summon[Int] +} + +// doesn't +inline def summonInt = { + given Int = 0 + summonInline[Int] +} + +val b = summonInt