Skip to content

Commit

Permalink
Merge pull request #11080 from dotty-staging/fix-#11015
Browse files Browse the repository at this point in the history
Take type bounds into account for overloading resolution
  • Loading branch information
abgruszecki committed Jan 18, 2021
2 parents 67835c3 + 6dfe0fb commit dd74065
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1867,7 +1867,13 @@ trait Applications extends Compatibility {
case pt @ PolyProto(targs1, pt1) =>
val alts1 = alts.filter(pt.canInstantiate)
if isDetermined(alts1) then alts1
else resolveMapped(alts1, _.widen.appliedTo(targs1.tpes), pt1)
else
def withinBounds(alt: TermRef) = alt.widen match
case tp: PolyType =>
TypeOps.boundsViolations(targs1, tp.paramInfos, _.substParams(tp, _), NoType).isEmpty
val alts2 = alts1.filter(withinBounds)
if isDetermined(alts2) then alts2
else resolveMapped(alts1, _.widen.appliedTo(targs1.tpes), pt1)

case defn.FunctionOf(args, resultType, _, _) =>
narrowByTypes(alts, args, resultType)
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/tcpoly_overloaded.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ trait Test {
def flatMap[S]
(f: T => List[S], foo: Int): List[S] = sys.error("foo")
}
val l: MList[String] = moo.flatMap[String, List, Any, MList]((x: Int) => new MList("String"))
val l: MList[String] = moo.flatMap[String, List, Any, MList]((x: Int) => new MList("String")) // error: no alternative matches
}
6 changes: 6 additions & 0 deletions tests/pos/i11015.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import annotation.targetName
object Foo:
def apply[A <: Int]: Int = 0
@targetName("applyS") def apply[B <: String]: String = "0"

def test = Foo[Int]

0 comments on commit dd74065

Please sign in to comment.