Skip to content

Commit 5e8272b

Browse files
committed
Skip package objects in Typer#findRef
1 parent 2b045cc commit 5e8272b

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,12 @@ class Typer extends Namer
265265
// with the exact list of files given).
266266
val isNewDefScope =
267267
if (curOwner.is(Package) && !curOwner.isRoot) curOwner ne ctx.outer.owner
268-
else (ctx.scope ne lastCtx.scope) || (curOwner ne lastCtx.owner)
268+
else ((ctx.scope ne lastCtx.scope) || (curOwner ne lastCtx.owner)) &&
269+
!curOwner.isPackageObject
270+
// Package objects are never searched directly. We wait until we
271+
// hit the enclosing package. That way we make sure we consider
272+
// all overloaded altrenatives of a definition, even if they are
273+
// in different source files.
269274

270275
if (isNewDefScope) {
271276
val defDenot = ctx.denotNamed(name, required)

tests/run/toplevel-overloads/defs_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package top
22

33
def hello(name: String) = s"hello, $name"
44
def hello(x: Int) = x.toString
5-
def hello(x: Boolean) = if (x) "yes" else "no"
65

76
object O {
87
def hi = hello("Bob")
98
def gb = hello(true)
109
}
1110

12-
val test = hello(false)
11+
val test1 = top.hello(false)
12+
val test2 = hello(false)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
package top
22

3-
def hello(b: Boolean) = b.toString
3+
def hello(b: Boolean): String = if (b) "yes" else "no"
4+

0 commit comments

Comments
 (0)