From 3aba8841c2c589d64048cdc0f881c1f6632cde28 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Thu, 19 Oct 2023 18:26:32 +0100 Subject: [PATCH] Fallback erasing term references [Cherry-picked f35261d250901e03e70090f3b1cc034bb4457114] --- compiler/src/dotty/tools/dotc/core/TypeErasure.scala | 3 +-- tests/pos/i18721.min/core.scala | 5 +++++ tests/pos/i18721.min/main.scala | 3 +++ 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 tests/pos/i18721.min/core.scala create mode 100644 tests/pos/i18721.min/main.scala diff --git a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala index baa6bf21e64e..fe76ab25ceb7 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala @@ -239,8 +239,7 @@ object TypeErasure { * TermRefs are kept instead of being widened away. */ def erasedRef(tp: Type)(using Context): Type = tp match { - case tp: TermRef => - assert(tp.symbol.exists, tp) + case tp: TermRef if tp.symbol.exists => val tp1 = makePackageObjPrefixExplicit(tp) if (tp1 ne tp) erasedRef(tp1) else TermRef(erasedRef(tp.prefix), tp.symbol.asTerm) diff --git a/tests/pos/i18721.min/core.scala b/tests/pos/i18721.min/core.scala new file mode 100644 index 000000000000..02b172fdd73b --- /dev/null +++ b/tests/pos/i18721.min/core.scala @@ -0,0 +1,5 @@ +class Foo +class Bar extends Selectable: + def selectDynamic(name: String): Foo = null + +inline def meth(inline foo: Foo): Foo = foo diff --git a/tests/pos/i18721.min/main.scala b/tests/pos/i18721.min/main.scala new file mode 100644 index 000000000000..a62ee8b0562b --- /dev/null +++ b/tests/pos/i18721.min/main.scala @@ -0,0 +1,3 @@ +class Test: + def t1(bar: Bar { val foo: Foo }): Any = + meth(bar.foo)