Skip to content

Commit 0e65ae4

Browse files
oderskyKordyjan
authored andcommitted
Avoid crash in erasure when reference cannot be emitted
Fixes #17391 [Cherry-picked 8231a48]
1 parent f333e55 commit 0e65ae4

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

compiler/src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ object Erasure {
867867

868868
app(fun1)
869869
case t =>
870-
if ownArgs.isEmpty then fun1
870+
if ownArgs.isEmpty || t.isError then fun1
871871
else throw new MatchError(i"tree $tree has unexpected type of function $fun/$fun1: $t, was $origFunType, args = $ownArgs")
872872
end typedApply
873873

tests/neg/i17391/Bar.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package mypkg;
2+
3+
class Base<E> {
4+
public void retainAll(String x) {}
5+
}
6+
7+
public class Bar<E> extends Base<E> {}

tests/neg/i17391/test.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def test(): Unit =
2+
{
3+
val x: Foo[mypkg.Bar[String]] = ???
4+
val y: mypkg.Bar[String] = ???
5+
6+
y.retainAll("fd") // works
7+
x.f.retainAll("fd"); // error
8+
9+
}
10+
11+
class Foo[T](val f: T)

0 commit comments

Comments
 (0)