Skip to content

Skip ambiguous reference error when symbols are aliases #16401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,17 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
case denot => !denot.hasAltWith(isCurrent)

def checkNoOuterDefs(denot: Denotation, last: Context, prevCtx: Context): Unit =
def sameTermOrType(d1: SingleDenotation, d2: Denotation) =
d2.containsSym(d1.symbol) || d2.hasUniqueSym && {
val sym1 = d1.symbol
val sym2 = d2.symbol
if sym1.isTerm then
sym1.isStableMember &&
sym2.isStableMember &&
sym1.owner.thisType.select(name, sym1) =:= sym2.owner.thisType.select(name, sym2)
else
(sym1.isAliasType || sym2.isAliasType) && d1.info =:= d2.info
}
val outer = last.outer
val owner = outer.owner
if (owner eq last.owner) && (outer.scope eq last.scope) then
Expand All @@ -385,7 +396,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
val competing = scope.denotsNamed(name).filterWithFlags(required, excluded)
if competing.exists then
val symsMatch = competing
.filterWithPredicate(sd => denot.containsSym(sd.symbol))
.filterWithPredicate(sd => sameTermOrType(sd, denot))
.exists
if !symsMatch && !suppressErrors then
report.errorOrMigrationWarning(
Expand Down
16 changes: 16 additions & 0 deletions tests/pos/t11921.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
object t1:
class C
class A:
val c: B.c.type = B.c
object B:
val c = new C
val a = new A:
def m = c // not ambiguous, `this.c` and `B.c` are compatible paths

object t2:
class C[T]:
type TT = T
object O:
type TT = String
class D extends C[TT]:
def n(x: TT) = x // `TT` is not ambiguous, `this.TT` and `O.TT` are aliases