Skip to content

Commit d437649

Browse files
committed
Add top-level definitions to scope in TreeMapWithImplicits
Fixes #11479
1 parent 6eddfe9 commit d437649

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

compiler/src/dotty/tools/dotc/ast/TreeMapWithImplicits.scala

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Trees._
55
import core.Contexts._
66
import core.ContextOps.enter
77
import core.Flags._
8+
import core.NameOps._
89
import core.Symbols._
910
import core.TypeError
1011

@@ -69,8 +70,17 @@ class TreeMapWithImplicits extends tpd.TreeMap {
6970
importScopeCtx(stats)(using nestedCtx)
7071
}
7172

72-
private def nestedPackageScopeCtx(tree: PackageDef)(using Context): Context =
73-
importScopeCtx(tree.stats)(using ctx.withOwner(tree.symbol))
73+
private def nestedPackageScopeCtx(tree: PackageDef)(using Context): Context = {
74+
val nestedCtx = ctx.withOwner(tree.symbol).fresh.setNewScope
75+
for
76+
packageDecl <- tree.symbol.moduleClass.asClass.info.decls.toList
77+
if packageDecl.isTerm && packageDecl.name.isPackageObjectName
78+
decl <- packageDecl.info.decls.toList
79+
if decl.isTerm && decl.isOneOf(GivenOrImplicit)
80+
do
81+
nestedCtx.enter(decl)
82+
importScopeCtx(tree.stats)(using nestedCtx)
83+
}
7484

7585
private def importScopeCtx(stats: List[Tree])(using Context): Context =
7686
stats.foldLeft(ctx) {

tests/pos-macros/i11479/Macro_1.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
trait Foo
2+
given Foo: Foo with {}
3+
inline def summonFoo(): Foo = scala.compiletime.summonInline[Foo]

tests/pos-macros/i11479/Test_2.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def test: Unit = summonFoo()

0 commit comments

Comments
 (0)