@@ -2796,8 +2796,9 @@ class Typer extends Namer
27962796
27972797 def adaptOverloaded (ref : TermRef ) = {
27982798 val altDenots = ref.denot.alternatives
2799- println(i " adapt overloaded $ref with alternatives ${altDenots map (_.info)}% \n\n % " )
2800- val alts = altDenots.map(TermRef (ref.prefix, ref.name, _))
2799+ typr.println(i " adapt overloaded $ref with alternatives ${altDenots map (_.info)}% \n\n % " )
2800+ def altRef (alt : SingleDenotation ) = TermRef (ref.prefix, ref.name, alt)
2801+ val alts = altDenots.map(altRef)
28012802 resolveOverloaded(alts, pt) match {
28022803 case alt :: Nil =>
28032804 readaptSimplified(tree.withType(alt))
@@ -2823,11 +2824,20 @@ class Typer extends Namer
28232824 noMatches
28242825 }
28252826 }
2826- case alts =>
2827+ case ambiAlts =>
28272828 if (tree.tpe.isErroneous || pt.isErroneous) tree.withType(UnspecifiedErrorType )
28282829 else {
2829- val remainingDenots = alts map (_.denot.asInstanceOf [SingleDenotation ])
2830- errorTree(tree, AmbiguousOverload (tree, remainingDenots, pt))
2830+ val remainingDenots = altDenots.filter(denot => ambiAlts.contains(altRef(denot)))
2831+ val addendum =
2832+ if ambiAlts.toSet.size != ambiAlts.size then
2833+ // Several variants have the same signature. This can happen for structural
2834+ // type selections. See i8736.scala
2835+ """ |
2836+ |
2837+ |Note: this happens because one or more alternatives have the same erasure,
2838+ | so they cannot be distinguished by overloading resolution""" .stripMargin
2839+ else " "
2840+ errorTree(tree, AmbiguousOverload (tree, remainingDenots, pt, addendum))
28312841 }
28322842 }
28332843 }
0 commit comments