diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 59598d332803..f0298cf63804 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -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 @@ -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) @@ -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 diff --git a/tests/pos/i3636.scala b/tests/pos/i3636.scala new file mode 100644 index 000000000000..f250ab94b542 --- /dev/null +++ b/tests/pos/i3636.scala @@ -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 + } +}