Skip to content

Commit 1aa6f7d

Browse files
committed
Handle overloaded inherited conflicting denot
1 parent c6d4c47 commit 1aa6f7d

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
439439
if owner.is(Package) then
440440
owner.denot.asClass.membersNamed(name)
441441
.filterWithPredicate(d => !d.symbol.is(Package)
442-
&& denot.symbol.source.exists
443-
&& d.symbol.source == denot.symbol.source)
442+
&& denot.alternatives.exists(alt => alt.symbol.source.exists && alt.symbol.source == d.symbol.source))
444443
else
445444
val scope = if owner.isClass then owner.info.decls else outer.scope
446445
scope.denotsNamed(name)
@@ -481,7 +480,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
481480
result = checkNewOrShadowed(found, Definition) // no need to go further out, we found highest prec entry
482481
found match
483482
case found: NamedType
484-
if curOwner.isClass && found.denot.exists && isInherited(found.denot) && !ctx.compilationUnit.isJava =>
483+
if curOwner.isClass && isInherited(found.denot) && !ctx.compilationUnit.isJava =>
485484
checkNoOuterDefs(found.denot, ctx, ctx)
486485
case _ =>
487486
else

tests/neg/i17433.check

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- [E049] Reference Error: tests/neg/i17433.scala:9:10 -----------------------------------------------------------------
2+
9 | def g = f(42) // error
3+
| ^
4+
| Reference to f is ambiguous.
5+
| It is both defined in package <empty>
6+
| and inherited subsequently in class D
7+
|
8+
| longer explanation available when compiling with `-explain`

tests/neg/i17433.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
class C:
3+
def f(i: Int) = i + 1
4+
def f(s: String) = s + "_1"
5+
6+
def f = 42
7+
8+
class D extends C:
9+
def g = f(42) // error
10+
11+
@main def test() = println:
12+
D().g

0 commit comments

Comments
 (0)