Skip to content

Commit

Permalink
Avoid crash in erasure when reference cannot be emitted (#18056)
Browse files Browse the repository at this point in the history
Fixes #17391
  • Loading branch information
odersky authored Jul 3, 2023
2 parents 108f8d0 + 996bb15 commit 347a567
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/Erasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,9 @@ object Erasure {
val symIsPrimitive = sym.owner.isPrimitiveValueClass

def originalQual: Type =
erasure(tree.qualifier.typeOpt.widen.finalResultType)
erasure(
inContext(preErasureCtx):
tree.qualifier.typeOpt.widen.finalResultType)

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

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

Expand Down
7 changes: 7 additions & 0 deletions tests/pos/i17391/Bar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package mypkg;

class Base<E> {
public void retainAll(String x) {}
}

public class Bar<E> extends Base<E> {}
11 changes: 11 additions & 0 deletions tests/pos/i17391/test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def test(): Unit =
{
val x: Foo[mypkg.Bar[String]] = ???
val y: mypkg.Bar[String] = ???

y.retainAll("fd") // works
x.f.retainAll("fd"); // error

}

class Foo[T](val f: T)

0 comments on commit 347a567

Please sign in to comment.