Skip to content

Commit 5b0d52b

Browse files
committed
Compare erasedness of parameters in the TypeComparer
1 parent 3ca8073 commit 5b0d52b

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2117,7 +2117,14 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
21172117
case nil =>
21182118
formals2.isEmpty
21192119
}
2120-
loop(tp1.paramInfos, tp2.paramInfos)
2120+
// Check if methods are erased, then the erased parameters match
2121+
val erasedValid = if tp1.isErasedMethod && tp1.isErasedMethod then
2122+
val comp1 = tp1.companion.asInstanceOf[ErasedMethodCompanion]
2123+
val comp2 = tp2.companion.asInstanceOf[ErasedMethodCompanion]
2124+
comp1.isErased == comp2.isErased
2125+
else !tp1.isErasedMethod && !tp2.isErasedMethod
2126+
2127+
erasedValid && loop(tp1.paramInfos, tp2.paramInfos)
21212128
}
21222129

21232130
/** Do the parameter types of `tp1` and `tp2` match in a way that allows `tp1`
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def foo(erased x: Int, y: Int) = y
2+
def bar(x: Int, erased y: Int) = x
3+
4+
def consumeFoo(f: (erased x: Int, y: Int) => Int) = f(0, 1)
5+
6+
val fooF: (erased x: Int, y: Int) => Int = foo
7+
val barF: (x: Int, erased y: Int) => Int = bar
8+
9+
val a = consumeFoo(foo) // ok
10+
val b = consumeFoo(bar) // error
11+
12+
val c = consumeFoo(fooF) // ok
13+
val d = consumeFoo(barF) // error
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def foo(x: Int, erased y: Int): Int = x
2+
def bar(erased x: Int, y: Int): Int = y
3+
4+
val fooF: (x: Int, erased y: Int) => Int = foo
5+
6+
val fooG: (erased x: Int, y: Int) => Int = foo // error
7+
8+
val barF: (x: Int, erased y: Int) => Int = bar // error
9+
10+
val barG: (erased x: Int, y: Int) => Int = bar
11+

0 commit comments

Comments
 (0)