File tree 3 files changed +10
-4
lines changed
compiler/src/dotty/tools/dotc/typer
tests/run/toplevel-overloads
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
265
265
// with the exact list of files given).
266
266
val isNewDefScope =
267
267
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.
269
274
270
275
if (isNewDefScope) {
271
276
val defDenot = ctx.denotNamed(name, required)
Original file line number Diff line number Diff line change @@ -2,11 +2,11 @@ package top
2
2
3
3
def hello (name : String ) = s " hello, $name"
4
4
def hello (x : Int ) = x.toString
5
- def hello (x : Boolean ) = if (x) " yes" else " no"
6
5
7
6
object O {
8
7
def hi = hello(" Bob" )
9
8
def gb = hello(true )
10
9
}
11
10
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 1
1
package top
2
2
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