Skip to content

Commit 334e831

Browse files
authored
Backport "Avoid crash in erasure when reference cannot be emitted" to LTS (#19056)
Backports #18056 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents 1089e51 + 8454909 commit 334e831

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
@@ -762,7 +762,9 @@ object Erasure {
762762
val symIsPrimitive = sym.owner.isPrimitiveValueClass
763763

764764
def originalQual: Type =
765-
erasure(tree.qualifier.typeOpt.widen.finalResultType)
765+
erasure(
766+
inContext(preErasureCtx):
767+
tree.qualifier.typeOpt.widen.finalResultType)
766768

767769
if (qualIsPrimitive && !symIsPrimitive || qual.tpe.widenDealias.isErasedValueType)
768770
recur(box(qual))
@@ -867,7 +869,7 @@ object Erasure {
867869

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

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)