Skip to content

Commit e25e13d

Browse files
committed
Refine handling of package objects in typedIdent
We skip a package object if we look for a term, but consider it if we look for a type. That way we can handle at the same time overloaded terms in several source files and opaque types.
1 parent f8a9776 commit e25e13d

File tree

4 files changed

+10
-31
lines changed

4 files changed

+10
-31
lines changed

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -278,17 +278,15 @@ 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-
// 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.
281+
else ((ctx.scope ne lastCtx.scope) || (curOwner ne lastCtx.owner)) &&
282+
(name.isTypeName || !curOwner.isPackageObject)
283+
// If we are looking for a term, skip package objects and 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+
// On the other hand, for a type we should stop at the package object
288+
// since the type might be opaque, so we need to have the package object's
289+
// thisType as prefix in order to see the alias.
292290

293291
if (isNewDefScope) {
294292
val defDenot = ctx.denotNamed(name, required)

tests/neg/toplevel-overload-1/defs_1.scala

Lines changed: 0 additions & 15 deletions
This file was deleted.

tests/neg/toplevel-overload-1/moredefs_1.scala

Lines changed: 0 additions & 4 deletions
This file was deleted.

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) // does not work anymore, see comment on line 280 in Typer#findRef.
12+
val test2 = hello(false)

0 commit comments

Comments
 (0)