Skip to content

Commit 8231a48

Browse files
committed
Avoid crash in erasure when reference cannot be emitted
Fixes #17391
1 parent 46b30cc commit 8231a48

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
@@ -869,7 +869,7 @@ object Erasure {
869869

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

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)