Skip to content

Fix #3636: Better disambiguation in withPrefix #3656

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
Dec 12, 2017
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
18 changes: 8 additions & 10 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1698,9 +1698,10 @@ object Types {
finally ctx.typerState.ephemeral |= savedEphemeral
}

private def disambiguate(d: Denotation)(implicit ctx: Context): Denotation = {
val sig = currentSignature
//if (ctx.isAfterTyper) println(i"overloaded $this / $d / sig = $sig") // DEBUG
private def disambiguate(d: Denotation)(implicit ctx: Context): Denotation =
disambiguate(d, currentSignature)

private def disambiguate(d: Denotation, sig: Signature)(implicit ctx: Context): Denotation =
if (sig != null)
d.atSignature(sig, relaxed = !ctx.erasedTypes) match {
case d1: SingleDenotation => d1
Expand All @@ -1711,7 +1712,6 @@ object Types {
}
}
else d
}

private def memberDenot(name: Name, allowPrivate: Boolean)(implicit ctx: Context): Denotation = {
var d = memberDenot(prefix, name, allowPrivate)
Expand Down Expand Up @@ -1974,12 +1974,10 @@ object Types {
def reload(): NamedType = {
val allowPrivate = !lastSymbol.exists || lastSymbol.is(Private) && prefix.classSymbol == this.prefix.classSymbol
var d = memberDenot(prefix, name, allowPrivate)
if (d.isOverloaded && lastSymbol.exists) {
val targetSig =
if (lastSymbol.signature == Signature.NotAMethod) Signature.NotAMethod
else lastSymbol.asSeenFrom(prefix).signature
d = d.atSignature(targetSig, relaxed = !ctx.erasedTypes)
}
if (d.isOverloaded && lastSymbol.exists)
d = disambiguate(d,
if (lastSymbol.signature == Signature.NotAMethod) Signature.NotAMethod
else lastSymbol.asSeenFrom(prefix).signature)
NamedType(prefix, name, d)
}
if (prefix eq this.prefix) this
Expand Down
15 changes: 15 additions & 0 deletions tests/pos/i3636.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
trait Iterable[A] {
def concat[B >: A](that: Iterable[B]): Iterable[B] = ???
@`inline` final def ++ [B >: A](that: Iterable[B]): Iterable[B] = concat(that)
}

class BitSet extends Iterable[Int] {
def concat(that: Iterable[Int]): BitSet = ???
@`inline` final def ++ (that: Iterable[Int]): BitSet = concat(that)
}

class Test {
def test(x: BitSet, y: Iterable[Int]): Unit = {
val foo = x ++ y
}
}