diff --git a/compiler/src/dotty/tools/dotc/core/ContextOps.scala b/compiler/src/dotty/tools/dotc/core/ContextOps.scala index 427cfa47c7c1..760e239cb434 100644 --- a/compiler/src/dotty/tools/dotc/core/ContextOps.scala +++ b/compiler/src/dotty/tools/dotc/core/ContextOps.scala @@ -135,7 +135,7 @@ object ContextOps: } def packageContext(tree: untpd.PackageDef, pkg: Symbol): Context = inContext(ctx) { - if (pkg.is(Package)) ctx.fresh.setOwner(pkg.moduleClass).setTree(tree) + if (pkg.is(Package)) ctx.fresh.setOwner(pkg.moduleClass).setTree(tree).setNewScope else ctx } end ContextOps diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 3e4d740c87ac..c9ce8a894ac8 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -387,7 +387,7 @@ class Namer { typer: Typer => def recur(stat: Tree): Context = stat match { case pcl: PackageDef => val pkg = createPackageSymbol(pcl.pid) - index(pcl.stats)(using ctx.fresh.setOwner(pkg.moduleClass)) + index(pcl.stats)(using ctx.packageContext(pcl, pkg)) invalidateCompanions(pkg, Trees.flatten(pcl.stats map expanded)) setDocstring(pkg, stat) ctx diff --git a/language-server/test/dotty/tools/languageserver/CompletionTest.scala b/language-server/test/dotty/tools/languageserver/CompletionTest.scala index de963926cc4e..b71552fe5e92 100644 --- a/language-server/test/dotty/tools/languageserver/CompletionTest.scala +++ b/language-server/test/dotty/tools/languageserver/CompletionTest.scala @@ -987,7 +987,7 @@ class CompletionTest { @Test def importAnnotationAfterImport : Unit = code"""import java.lang.annotation; import annot${m1}""" - .completion(("annotation", Module, "scala.annotation")) + .completion(("annotation", Module, "java.lang.annotation")) @Test def completeTemplateConstrArgType: Unit = { code"""import scala.concurrent.Future diff --git a/tests/pos/i21405.scala b/tests/pos/i21405.scala new file mode 100644 index 000000000000..4fcc1302882b --- /dev/null +++ b/tests/pos/i21405.scala @@ -0,0 +1,7 @@ +package o { class IO } +package p { class IO } +import o._ +package q { + import p._ + class D extends IO +}