Skip to content

Make it a fatal error if erasure cannot resolve a type #16373

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

Merged
merged 1 commit into from
Dec 14, 2022
Merged
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
24 changes: 18 additions & 6 deletions compiler/src/dotty/tools/dotc/core/TypeErasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -591,17 +591,17 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
tp
case tp: TypeRef =>
val sym = tp.symbol
if (!sym.isClass) this(tp.translucentSuperType)
else if (semiEraseVCs && isDerivedValueClass(sym)) eraseDerivedValueClass(tp)
else if (defn.isSyntheticFunctionClass(sym)) defn.functionTypeErasure(sym)
if !sym.isClass then this(checkedSuperType(tp))
else if semiEraseVCs && isDerivedValueClass(sym) then eraseDerivedValueClass(tp)
else if defn.isSyntheticFunctionClass(sym) then defn.functionTypeErasure(sym)
else eraseNormalClassRef(tp)
case tp: AppliedType =>
val tycon = tp.tycon
if (tycon.isRef(defn.ArrayClass)) eraseArray(tp)
else if (tycon.isRef(defn.PairClass)) erasePair(tp)
else if (tp.isRepeatedParam) apply(tp.translateFromRepeated(toArray = sourceLanguage.isJava))
else if (semiEraseVCs && isDerivedValueClass(tycon.classSymbol)) eraseDerivedValueClass(tp)
else apply(tp.translucentSuperType)
else this(checkedSuperType(tp))
case tp: TermRef =>
this(underlyingOfTermRef(tp))
case _: ThisType =>
Expand Down Expand Up @@ -689,6 +689,18 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
tp
}

/** Like translucentSuperType, but issue a fatal error if it does not exist. */
private def checkedSuperType(tp: TypeProxy)(using Context): Type =
val tp1 = tp.translucentSuperType
if !tp1.exists then
val msg = tp.typeConstructor match
case tycon: TypeRef =>
MissingType(tycon.prefix, tycon.name).toMessage.message
case _ =>
i"Cannot resolve reference to $tp"
throw FatalError(msg)
tp1

/** Widen term ref, skipping any `()` parameter of an eventual getter. Used to erase a TermRef.
* Since getters are introduced after erasure, one would think that erasing a TermRef
* could just use `widen`. However, it's possible that the TermRef got read from a class
Expand Down Expand Up @@ -815,7 +827,7 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
throw new MissingType(tp.prefix, tp.name)
val sym = tp.symbol
if (!sym.isClass) {
val info = tp.translucentSuperType
val info = checkedSuperType(tp)
if (!info.exists) assert(false, i"undefined: $tp with symbol $sym")
return sigName(info)
}
Expand All @@ -841,7 +853,7 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
sigName( // todo: what about repeatedParam?
if (erasureDependsOnArgs(sym)) this(tp)
else if (sym.isClass) tp.underlying
else tp.translucentSuperType)
else checkedSuperType(tp))
case ErasedValueType(_, underlying) =>
sigName(underlying)
case JavaArrayType(elem) =>
Expand Down