Skip to content

Commit be5043a

Browse files
committed
Keep constructor proxies after erasure
It's awkward to delete all references to them. We should treat them like other symbols that are effectively erased.
1 parent f3a4263 commit be5043a

File tree

5 files changed

+6
-19
lines changed

5 files changed

+6
-19
lines changed

compiler/src/dotty/tools/backend/jvm/BTypesFromSymbols.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class BTypesFromSymbols[I <: DottyBackendInterface](val int: I) extends BTypes {
214214
private def definedClasses(sym: Symbol, phase: Phase) =
215215
if (sym.isDefinedInCurrentRun)
216216
atPhase(phase) {
217-
toDenot(sym).info.decls.filter(_.isClass)
217+
toDenot(sym).info.decls.filter(sym => sym.isClass && !sym.isEffectivelyErased)
218218
}
219219
else Nil
220220

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,11 +1180,13 @@ object SymDenotations {
11801180
*/
11811181
final def companionModule(using Context): Symbol =
11821182
if (is(Module)) sourceModule
1183+
else if registeredCompanion.isAbsent() then NoSymbol
11831184
else registeredCompanion.sourceModule
11841185

11851186
private def companionType(using Context): Symbol =
11861187
if (is(Package)) NoSymbol
11871188
else if (is(ModuleVal)) moduleClass.denot.companionType
1189+
else if registeredCompanion.isAbsent() then NoSymbol
11881190
else registeredCompanion
11891191

11901192
/** The class with the same (type-) name as this module or module class,

compiler/src/dotty/tools/dotc/core/TypeErasure.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ object TypeErasure {
238238

239239
if (defn.isPolymorphicAfterErasure(sym)) eraseParamBounds(sym.info.asInstanceOf[PolyType])
240240
else if (sym.isAbstractType) TypeAlias(WildcardType)
241+
else if sym.is(ConstructorProxy) then NoType
241242
else if (sym.isConstructor) outer.addParam(sym.owner.asClass, erase(tp)(using preErasureCtx))
242243
else if (sym.is(Label)) erase.eraseResult(sym.info)(using preErasureCtx)
243244
else erase.eraseInfo(tp, sym)(using preErasureCtx) match {

compiler/src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,24 +1038,9 @@ object Erasure {
10381038
override def typedTypeDef(tdef: untpd.TypeDef, sym: Symbol)(using Context): Tree =
10391039
EmptyTree
10401040

1041-
/** Drop all constructor proxies of members of class `cls`.
1042-
* If `cls` is itself a constructor proxy, mark it as absent after erasure.
1043-
*/
1044-
private def dropConstructorProxies(cls: ClassSymbol)(using Context) =
1045-
import Flags._
1046-
if cls.linkedClass.is(ConstructorProxy) then
1047-
if cls.owner.is(PackageClass) && cls.isDefinedInCurrentRun then
1048-
cls.linkedClass.copySymDenotation(initFlags = EmptyFlags, info = NoType)
1049-
.installAfter(erasurePhase)
1050-
cls.registeredCompanion = NoSymbol
1051-
for mbr <- cls.info.decls do
1052-
if mbr.is(ConstructorProxy) then mbr.dropAfter(erasurePhase)
1053-
10541041
override def typedClassDef(cdef: untpd.TypeDef, cls: ClassSymbol)(using Context): Tree =
10551042
if cls.is(Flags.Erased) then erasedDef(cls)
1056-
else
1057-
try super.typedClassDef(cdef, cls)
1058-
finally dropConstructorProxies(cls)
1043+
else super.typedClassDef(cdef, cls)
10591044

10601045
override def typedAnnotated(tree: untpd.Annotated, pt: Type)(using Context): Tree =
10611046
typed(tree.arg, pt)

compiler/src/dotty/tools/dotc/transform/TreeChecker.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,7 @@ class TreeChecker extends Phase with SymTransformer {
446446
val decls = cls.classInfo.decls.toList.toSet.filter(isNonMagicalMember)
447447
val defined = impl.body.map(_.symbol)
448448

449-
def isAllowed(sym: Symbol): Boolean =
450-
sym.is(ConstructorProxy) && !ctx.phase.erasedTypes
449+
def isAllowed(sym: Symbol): Boolean = sym.is(ConstructorProxy)
451450

452451
val symbolsNotDefined = (decls -- defined - constr.symbol).filterNot(isAllowed)
453452

0 commit comments

Comments
 (0)