File tree Expand file tree Collapse file tree 3 files changed +10
-4
lines changed
compiler/src/dotty/tools/dotc/typer
tests/run/toplevel-overloads Expand file tree Collapse file tree 3 files changed +10
-4
lines changed Original file line number Diff line number Diff 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)
Original file line number Diff line number Diff line change @@ -2,11 +2,11 @@ package top
22
33def hello (name : String ) = s " hello, $name"
44def hello (x : Int ) = x.toString
5- def hello (x : Boolean ) = if (x) " yes" else " no"
65
76object 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 )
Original file line number Diff line number Diff line change 11package top
22
3- def hello (b : Boolean ) = b.toString
3+ def hello (b : Boolean ): String = if (b) " yes" else " no"
4+
You can’t perform that action at this time.
0 commit comments