Skip to content

Commit dd74065

Browse files
authored
Merge pull request #11080 from dotty-staging/fix-#11015
Take type bounds into account for overloading resolution
2 parents 67835c3 + 6dfe0fb commit dd74065

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1867,7 +1867,13 @@ trait Applications extends Compatibility {
18671867
case pt @ PolyProto(targs1, pt1) =>
18681868
val alts1 = alts.filter(pt.canInstantiate)
18691869
if isDetermined(alts1) then alts1
1870-
else resolveMapped(alts1, _.widen.appliedTo(targs1.tpes), pt1)
1870+
else
1871+
def withinBounds(alt: TermRef) = alt.widen match
1872+
case tp: PolyType =>
1873+
TypeOps.boundsViolations(targs1, tp.paramInfos, _.substParams(tp, _), NoType).isEmpty
1874+
val alts2 = alts1.filter(withinBounds)
1875+
if isDetermined(alts2) then alts2
1876+
else resolveMapped(alts1, _.widen.appliedTo(targs1.tpes), pt1)
18711877

18721878
case defn.FunctionOf(args, resultType, _, _) =>
18731879
narrowByTypes(alts, args, resultType)

tests/neg/tcpoly_overloaded.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ trait Test {
2121
def flatMap[S]
2222
(f: T => List[S], foo: Int): List[S] = sys.error("foo")
2323
}
24-
val l: MList[String] = moo.flatMap[String, List, Any, MList]((x: Int) => new MList("String"))
24+
val l: MList[String] = moo.flatMap[String, List, Any, MList]((x: Int) => new MList("String")) // error: no alternative matches
2525
}

tests/pos/i11015.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import annotation.targetName
2+
object Foo:
3+
def apply[A <: Int]: Int = 0
4+
@targetName("applyS") def apply[B <: String]: String = "0"
5+
6+
def test = Foo[Int]

0 commit comments

Comments
 (0)