Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid crash in erasure when reference cannot be emitted #18056

Merged
merged 2 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)