Skip to content

Commit 9502d48

Browse files
committed
Don't skip package objects as owners in typedIdent
The previous treatment would be incompatible with the new opaque types scheme.
1 parent f0af687 commit 9502d48

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,17 @@ class Typer extends Namer
278278
// with the exact list of files given).
279279
val isNewDefScope =
280280
if (curOwner.is(Package) && !curOwner.isRoot) curOwner ne ctx.outer.owner
281-
else ((ctx.scope ne lastCtx.scope) || (curOwner ne lastCtx.owner)) &&
282-
!curOwner.isPackageObject
283-
// Package objects are never searched directly. We wait until we
284-
// hit the enclosing package. That way we make sure we consider
285-
// all overloaded alternatives of a definition, even if they are
286-
// in different source files.
281+
else ((ctx.scope ne lastCtx.scope) || (curOwner ne lastCtx.owner))
282+
// Was: ... && !curOwner.isPackageObject
283+
// Package objects are never searched directly. We wait until we
284+
// hit the enclosing package. That way we make sure we consider
285+
// all overloaded alternatives of a definition, even if they are
286+
// in different source files.
287+
//
288+
// But this is now disabled since otherwise we will not see self type refinements
289+
// for opaque types.
290+
// We should evaluate later whether we want to keep & spec it that way,
291+
// or go back to the old scheme and compensate for opaque type refinements.
287292

288293
if (isNewDefScope) {
289294
val defDenot = ctx.denotNamed(name, required)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package top
2+
3+
def hello(name: String) = s"hello, $name"
4+
def hello(x: Int) = x.toString
5+
6+
object O {
7+
def hi = hello("Bob")
8+
def gb = hello(true) // OK
9+
}
10+
11+
val test1 = top.hello(false) // OK, all overloaded variants are considered
12+
13+
val test2 = hello(false) // error , since we now consider only local overloaded definitions
14+
// in the same compilation unit.
15+
// See comment on line 280 in Typer#findRef.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package top
2+
3+
def hello(b: Boolean): String = if (b) "yes" else "no"
4+

tests/run/toplevel-overloads/defs_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ object O {
99
}
1010

1111
val test1 = top.hello(false)
12-
val test2 = hello(false)
12+
// val test2 = hello(false) // does not work anymore, see comment on line 280 in Typer#findRef.

0 commit comments

Comments
 (0)