diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 23a63512d0da..289ec44c0a3c 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -251,9 +251,16 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit // context immediately nested in it. But for package contexts, it's // the opposite: the last context before the package changes. This distinction // is made so that top-level imports following a package clause are - // logically nested in that package clause. + // logically nested in that package clause. Finally, for the root package + // we switch back to the original test. This means that rop-level packages in + // the root package take priority over root imports. For instance, + // a top-level io package takes priority over scala.io. + // It would be nice if we could drop all this complication, and + // always use the second condition. Unfortunately compileStdLib breaks + // with an error on CI which I cannot replicate locally (not even + // with the exact list of files given). val isNewDefScope = - if (curOwner is Package) curOwner ne ctx.outer.owner + if (curOwner.is(Package) && !curOwner.isRoot) curOwner ne ctx.outer.owner else (ctx.scope ne lastCtx.scope) || (curOwner ne lastCtx.owner) if (isNewDefScope) { diff --git a/tests/neg/i1641.scala b/tests/neg/i1641.scala index db1daf79166a..659816b3bb5d 100644 --- a/tests/neg/i1641.scala +++ b/tests/neg/i1641.scala @@ -2,7 +2,7 @@ package bar { object bippy extends (Double => String) { def apply(x: Double): St package object println { def bippy(x: Int, y: Int, z: Int) = "(Int, Int, Int)" } object Test { def main(args: Array[String]): Unit = { - println(bar.bippy(5.5)) + println(bar.bippy(5.5)) // error println(bar.bippy(1, 2, 3)) // error } } diff --git a/tests/pos/i2856.scala b/tests/pos/i2856.scala new file mode 100644 index 000000000000..3ad748c28a51 --- /dev/null +++ b/tests/pos/i2856.scala @@ -0,0 +1,7 @@ +package io.grpc { + trait Grpc +} +package bar { + import io.grpc.Grpc + object a extends Grpc +}