Skip to content

Commit 5ba8ea3

Browse files
authored
Merge pull request #2860 from dotty-staging/fix-#2856
Fix #2856 Drop special treatment of packages in findRef
2 parents c933e0d + f50bf57 commit 5ba8ea3

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

Diff for: compiler/src/dotty/tools/dotc/typer/Typer.scala

+9-2
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,16 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
251251
// context immediately nested in it. But for package contexts, it's
252252
// the opposite: the last context before the package changes. This distinction
253253
// is made so that top-level imports following a package clause are
254-
// logically nested in that package clause.
254+
// logically nested in that package clause. Finally, for the root package
255+
// we switch back to the original test. This means that rop-level packages in
256+
// the root package take priority over root imports. For instance,
257+
// a top-level io package takes priority over scala.io.
258+
// It would be nice if we could drop all this complication, and
259+
// always use the second condition. Unfortunately compileStdLib breaks
260+
// with an error on CI which I cannot replicate locally (not even
261+
// with the exact list of files given).
255262
val isNewDefScope =
256-
if (curOwner is Package) curOwner ne ctx.outer.owner
263+
if (curOwner.is(Package) && !curOwner.isRoot) curOwner ne ctx.outer.owner
257264
else (ctx.scope ne lastCtx.scope) || (curOwner ne lastCtx.owner)
258265

259266
if (isNewDefScope) {

Diff for: tests/neg/i1641.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package bar { object bippy extends (Double => String) { def apply(x: Double): St
22
package object println { def bippy(x: Int, y: Int, z: Int) = "(Int, Int, Int)" }
33
object Test {
44
def main(args: Array[String]): Unit = {
5-
println(bar.bippy(5.5))
5+
println(bar.bippy(5.5)) // error
66
println(bar.bippy(1, 2, 3)) // error
77
}
88
}

Diff for: tests/pos/i2856.scala

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package io.grpc {
2+
trait Grpc
3+
}
4+
package bar {
5+
import io.grpc.Grpc
6+
object a extends Grpc
7+
}

0 commit comments

Comments
 (0)