Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions compiler/src/dotty/tools/dotc/core/TypeErasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,9 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
else if (tp.isRepeatedParam) apply(tp.translateFromRepeated(toArray = sourceLanguage.isJava))
else if (semiEraseVCs && isDerivedValueClass(tycon.classSymbol)) eraseDerivedValueClass(tp)
else apply(tp.translucentSuperType)
case _: TermRef | _: ThisType =>
case tp: TermRef =>
this(underlyingOfTermRef(tp))
case _: ThisType =>
this(tp.widen)
case SuperType(thistpe, supertpe) =>
SuperType(this(thistpe), this(supertpe))
Expand Down Expand Up @@ -687,6 +689,10 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
tp
}

private def underlyingOfTermRef(tp: TermRef)(using Context) = tp.widen match
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably deserves a comment referencing the issue. Otherwise someone will come here later, figure that this is useless, and remove it.

case tpw @ MethodType(Nil) if tp.symbol.isGetter => tpw.resultType
case tpw => tpw

private def eraseArray(tp: Type)(using Context) = {
val defn.ArrayOf(elemtp) = tp: @unchecked
if (isGenericArrayElement(elemtp, isScala2 = sourceLanguage.isScala2)) defn.ObjectType
Expand Down Expand Up @@ -832,7 +838,7 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
case JavaArrayType(elem) =>
sigName(elem) ++ "[]"
case tp: TermRef =>
sigName(tp.widen)
sigName(underlyingOfTermRef(tp))
case ExprType(rt) =>
sigName(defn.FunctionOf(Nil, rt))
case tp: TypeVar =>
Expand Down
11 changes: 11 additions & 0 deletions tests/pos/i15649.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
trait ConfigSourceModule:
object ConfigSource:
class R

object M extends ConfigSourceModule

object Foo:
implicit class FromConfigSource(c: M.ConfigSource.type)

object FooBar: // problem disappears if we rename as `Bar`
def foo: M.ConfigSource.R = new M.ConfigSource.R // problem disappears if we use `???` as rhs