diff --git a/compiler/src/dotty/tools/dotc/Compiler.scala b/compiler/src/dotty/tools/dotc/Compiler.scala index f5a2bb4fec81..84e81801a495 100644 --- a/compiler/src/dotty/tools/dotc/Compiler.scala +++ b/compiler/src/dotty/tools/dotc/Compiler.scala @@ -86,7 +86,6 @@ class Compiler { new LiftTry, // Put try expressions that might execute on non-empty stacks into their own methods new CollectNullableFields, // Collect fields that can be nulled out after use in lazy initialization new ElimOuterSelect, // Expand outer selections - new AugmentScala2Traits, // Augments Scala2 traits so that super accessors are made non-private new ResolveSuper, // Implement super accessors new FunctionXXLForwarders, // Add forwarders for FunctionXXL apply method new ParamForwarding, // Add forwarders for aliases of superclass parameters diff --git a/compiler/src/dotty/tools/dotc/core/Flags.scala b/compiler/src/dotty/tools/dotc/core/Flags.scala index 8fc9f1920b3c..7fd3042f67d5 100644 --- a/compiler/src/dotty/tools/dotc/core/Flags.scala +++ b/compiler/src/dotty/tools/dotc/core/Flags.scala @@ -378,12 +378,8 @@ object Flags { /** Children were queried on this class */ val (_, _, ChildrenQueried @ _) = newFlags(56, "") - /** A module variable (Scala 2.x only) - * / - * A Scala 2.x trait that has been augmented. - * This is set in `AugmentScala2Trait` when the trait is augmented. - */ - val (_, Scala2ModuleVar @ _, Scala2xAugmented @ _) = newFlags(57, "", "") + /** A module variable (Scala 2.x only) */ + val (_, Scala2ModuleVar @ _, _) = newFlags(57, "") /** A macro */ val (Macro @ _, _, _) = newFlags(58, "") diff --git a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index 85c8f6a8d071..cd071607d41a 100644 --- a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -455,8 +455,12 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas flags = flags &~ Scala2ExpandedName } if (flags.is(Scala2SuperAccessor)) { - name = name.asTermName.unmangle(SuperAccessorName) - flags = flags &~ Scala2SuperAccessor + /* Scala 2 super accessors are pickled as private, but are compiled as public expanded. + * Dotty super accessors, however, are already pickled as public expanded. + * We bridge the gap right now. + */ + name = name.asTermName.unmangle(SuperAccessorName).expandedName(owner) + flags = flags &~ (Scala2SuperAccessor | Private) } name = name.mapLast(_.decode) @@ -1308,4 +1312,3 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas errorBadSignature("expected an TypeDef (" + other + ")") } } - diff --git a/compiler/src/dotty/tools/dotc/transform/AugmentScala2Traits.scala b/compiler/src/dotty/tools/dotc/transform/AugmentScala2Traits.scala deleted file mode 100644 index 280977c78b93..000000000000 --- a/compiler/src/dotty/tools/dotc/transform/AugmentScala2Traits.scala +++ /dev/null @@ -1,54 +0,0 @@ -package dotty.tools.dotc -package transform - -import core._ -import MegaPhase._ -import Contexts.{Context, ctx} -import Flags._ -import SymUtils._ -import Symbols._ -import Types._ -import Decorators._ -import DenotTransformers._ -import Annotations._ -import StdNames._ -import NameOps._ -import NameKinds.{ExpandedName, TraitSetterName} -import ast.Trees._ - -object AugmentScala2Traits { - val name: String = "augmentScala2Traits" -} - -/** This phase augments Scala2 traits to fix up super accessors. - * - * Strangely, Scala 2 super accessors are pickled as private, but are compiled as public expanded. - * In this phase we expand them and make them non-private, so that `ResolveSuper` does something meaningful. - * - * TODO Should we already drop the Private flag when reading from Scala2 pickles in Scala2Unpickler? - */ -class AugmentScala2Traits extends MiniPhase with IdentityDenotTransformer { thisPhase => - import ast.tpd._ - - override def changesMembers: Boolean = true - - override def phaseName: String = AugmentScala2Traits.name - - override def transformTemplate(impl: Template)(using Context): Template = { - val cls = impl.symbol.owner.asClass - for (mixin <- cls.mixins) { - val erasedMixin = TypeErasure.normalizeClass(mixin) - if (erasedMixin.is(Scala2x) && !erasedMixin.is(Scala2xAugmented)) - augmentScala2Trait(erasedMixin) - } - impl - } - - private def augmentScala2Trait(mixin: ClassSymbol)(using Context): Unit = { - for (sym <- mixin.info.decls) { - if (sym.isSuperAccessor) - sym.ensureNotPrivate.installAfter(thisPhase) - } - mixin.setFlagFrom(thisPhase, Scala2xAugmented) - } -} diff --git a/compiler/src/dotty/tools/dotc/transform/ResolveSuper.scala b/compiler/src/dotty/tools/dotc/transform/ResolveSuper.scala index f58359946b17..f4dbf80e85b0 100644 --- a/compiler/src/dotty/tools/dotc/transform/ResolveSuper.scala +++ b/compiler/src/dotty/tools/dotc/transform/ResolveSuper.scala @@ -34,7 +34,6 @@ class ResolveSuper extends MiniPhase with IdentityDenotTransformer { thisPhase = override def phaseName: String = ResolveSuper.name override def runsAfter: Set[String] = Set(ElimByName.name, // verified empirically, need to figure out what the reason is. - AugmentScala2Traits.name, PruneErasedDefs.name) // Erased decls make `isCurrent` work incorrectly override def changesMembers: Boolean = true // the phase adds super accessors