Skip to content

Commit 347a567

Browse files
authored
Avoid crash in erasure when reference cannot be emitted (#18056)
Fixes #17391
2 parents 108f8d0 + 996bb15 commit 347a567

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,9 @@ object Erasure {
764764
val symIsPrimitive = sym.owner.isPrimitiveValueClass
765765

766766
def originalQual: Type =
767-
erasure(tree.qualifier.typeOpt.widen.finalResultType)
767+
erasure(
768+
inContext(preErasureCtx):
769+
tree.qualifier.typeOpt.widen.finalResultType)
768770

769771
if (qualIsPrimitive && !symIsPrimitive || qual.tpe.widenDealias.isErasedValueType)
770772
recur(box(qual))
@@ -869,7 +871,7 @@ object Erasure {
869871

870872
app(fun1)
871873
case t =>
872-
if ownArgs.isEmpty then fun1
874+
if ownArgs.isEmpty || t.isError then fun1
873875
else throw new MatchError(i"tree $tree has unexpected type of function $fun/$fun1: $t, was $origFunType, args = $ownArgs")
874876
end typedApply
875877

tests/pos/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/pos/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)