Skip to content

Commit 25e53b0

Browse files
authored
Merge pull request #3656 from dotty-staging/fix-#3636
Fix #3636: Better disambiguation in withPrefix
2 parents a1c20d5 + c2bbff3 commit 25e53b0

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,9 +1698,10 @@ object Types {
16981698
finally ctx.typerState.ephemeral |= savedEphemeral
16991699
}
17001700

1701-
private def disambiguate(d: Denotation)(implicit ctx: Context): Denotation = {
1702-
val sig = currentSignature
1703-
//if (ctx.isAfterTyper) println(i"overloaded $this / $d / sig = $sig") // DEBUG
1701+
private def disambiguate(d: Denotation)(implicit ctx: Context): Denotation =
1702+
disambiguate(d, currentSignature)
1703+
1704+
private def disambiguate(d: Denotation, sig: Signature)(implicit ctx: Context): Denotation =
17041705
if (sig != null)
17051706
d.atSignature(sig, relaxed = !ctx.erasedTypes) match {
17061707
case d1: SingleDenotation => d1
@@ -1711,7 +1712,6 @@ object Types {
17111712
}
17121713
}
17131714
else d
1714-
}
17151715

17161716
private def memberDenot(name: Name, allowPrivate: Boolean)(implicit ctx: Context): Denotation = {
17171717
var d = memberDenot(prefix, name, allowPrivate)
@@ -1974,12 +1974,10 @@ object Types {
19741974
def reload(): NamedType = {
19751975
val allowPrivate = !lastSymbol.exists || lastSymbol.is(Private) && prefix.classSymbol == this.prefix.classSymbol
19761976
var d = memberDenot(prefix, name, allowPrivate)
1977-
if (d.isOverloaded && lastSymbol.exists) {
1978-
val targetSig =
1979-
if (lastSymbol.signature == Signature.NotAMethod) Signature.NotAMethod
1980-
else lastSymbol.asSeenFrom(prefix).signature
1981-
d = d.atSignature(targetSig, relaxed = !ctx.erasedTypes)
1982-
}
1977+
if (d.isOverloaded && lastSymbol.exists)
1978+
d = disambiguate(d,
1979+
if (lastSymbol.signature == Signature.NotAMethod) Signature.NotAMethod
1980+
else lastSymbol.asSeenFrom(prefix).signature)
19831981
NamedType(prefix, name, d)
19841982
}
19851983
if (prefix eq this.prefix) this

tests/pos/i3636.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
trait Iterable[A] {
2+
def concat[B >: A](that: Iterable[B]): Iterable[B] = ???
3+
@`inline` final def ++ [B >: A](that: Iterable[B]): Iterable[B] = concat(that)
4+
}
5+
6+
class BitSet extends Iterable[Int] {
7+
def concat(that: Iterable[Int]): BitSet = ???
8+
@`inline` final def ++ (that: Iterable[Int]): BitSet = concat(that)
9+
}
10+
11+
class Test {
12+
def test(x: BitSet, y: Iterable[Int]): Unit = {
13+
val foo = x ++ y
14+
}
15+
}

0 commit comments

Comments
 (0)