diff --git a/compiler/src/dotty/tools/dotc/core/ContextOps.scala b/compiler/src/dotty/tools/dotc/core/ContextOps.scala index 57c369a08de6..c307b6ac569e 100644 --- a/compiler/src/dotty/tools/dotc/core/ContextOps.scala +++ b/compiler/src/dotty/tools/dotc/core/ContextOps.scala @@ -132,7 +132,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 0849e57b8c7d..0587ccfa6380 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -395,7 +395,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 8034b4c8d40b..38deb4c40c0f 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 +}