Skip to content

Commit 21712d9

Browse files
committed
Enter implicit members in scope when inlining
Fixes #12997
1 parent b830af3 commit 21712d9

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,6 +1487,15 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
14871487
super.ensureAccessible(tpe, superAccess, pos)
14881488
}
14891489

1490+
/** Enter implicits in scope so that they can be found in implicit search.
1491+
* This is important for non-transparent inlines
1492+
*/
1493+
override def index(trees: List[untpd.Tree])(using Context): Context =
1494+
for case tree: untpd.MemberDef <- trees do
1495+
if tree.symbol.isOneOf(Flags.GivenOrImplicit) then
1496+
ctx.scope.openForMutations.enter(tree.symbol)
1497+
ctx
1498+
14901499
override def typedIdent(tree: untpd.Ident, pt: Type)(using Context): Tree =
14911500
inlineIfNeeded(tryInlineArg(tree.asInstanceOf[tpd.Tree]) `orElse` super.typedIdent(tree, pt))
14921501

tests/pos/i12997.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import scala.compiletime._
2+
3+
// works
4+
val a = {
5+
given Int = 0
6+
summon[Int]
7+
}
8+
9+
// doesn't
10+
inline def summonInt = {
11+
given Int = 0
12+
summonInline[Int]
13+
}
14+
15+
val b = summonInt

0 commit comments

Comments
 (0)