Skip to content

Commit ae1d7d9

Browse files
committed
Fix #7630: Use weak conformance in overloading resolution
Following the spec, use weak conformance when determining whether an overloaded variant is applicable to arguments.
1 parent 77ca516 commit ae1d7d9

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,8 @@ trait Applications extends Compatibility {
666666
* argument trees.
667667
*/
668668
class ApplicableToTreesDirectly(methRef: TermRef, targs: List[Type], args: List[Tree], resultType: Type)(implicit ctx: Context) extends ApplicableToTrees(methRef, targs, args, resultType)(ctx) {
669-
override def argOK(arg: TypedArg, formal: Type): Boolean = argType(arg, formal) <:< formal.widenExpr
669+
override def argOK(arg: TypedArg, formal: Type): Boolean =
670+
argType(arg, formal) relaxed_<:< formal.widenExpr
670671
}
671672

672673
/** Subclass of Application for applicability tests with value argument types. */

tests/run/i7630.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2

tests/run/i7630.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
object Asserts {
2+
def assertEquals(expected: Any, actual: Any): Unit = {
3+
println(1)
4+
assert(expected.equals(actual), s"expected $expected but got $actual")
5+
}
6+
7+
def assertEquals(expected: Long, actual: Long): Unit = {
8+
println(2)
9+
assert(expected == actual, s"expected $expected but got $actual")
10+
}
11+
}
12+
13+
object Test {
14+
def main(args: Array[String]): Unit = {
15+
def foo(): Long = 42L
16+
17+
Asserts.assertEquals(42, foo()) // an Int and a Long
18+
}
19+
}

0 commit comments

Comments
 (0)