Skip to content

Commit

Permalink
Handle overloaded inherited conflicting denot
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed May 9, 2023
1 parent c6d4c47 commit 1aa6f7d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
5 changes: 2 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
if owner.is(Package) then
owner.denot.asClass.membersNamed(name)
.filterWithPredicate(d => !d.symbol.is(Package)
&& denot.symbol.source.exists
&& d.symbol.source == denot.symbol.source)
&& denot.alternatives.exists(alt => alt.symbol.source.exists && alt.symbol.source == d.symbol.source))
else
val scope = if owner.isClass then owner.info.decls else outer.scope
scope.denotsNamed(name)
Expand Down Expand Up @@ -481,7 +480,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
result = checkNewOrShadowed(found, Definition) // no need to go further out, we found highest prec entry
found match
case found: NamedType
if curOwner.isClass && found.denot.exists && isInherited(found.denot) && !ctx.compilationUnit.isJava =>
if curOwner.isClass && isInherited(found.denot) && !ctx.compilationUnit.isJava =>
checkNoOuterDefs(found.denot, ctx, ctx)
case _ =>
else
Expand Down
8 changes: 8 additions & 0 deletions tests/neg/i17433.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- [E049] Reference Error: tests/neg/i17433.scala:9:10 -----------------------------------------------------------------
9 | def g = f(42) // error
| ^
| Reference to f is ambiguous.
| It is both defined in package <empty>
| and inherited subsequently in class D
|
| longer explanation available when compiling with `-explain`
12 changes: 12 additions & 0 deletions tests/neg/i17433.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

class C:
def f(i: Int) = i + 1
def f(s: String) = s + "_1"

def f = 42

class D extends C:
def g = f(42) // error

@main def test() = println:
D().g

0 comments on commit 1aa6f7d

Please sign in to comment.