Skip to content

Commit 64b95d2

Browse files
committed
Restore AugmentScala2Traits, but limit it to super accessors.
1 parent a48a5aa commit 64b95d2

File tree

3 files changed

+7
-22
lines changed

3 files changed

+7
-22
lines changed

compiler/src/dotty/tools/dotc/Compiler.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class Compiler {
8686
new LiftTry, // Put try expressions that might execute on non-empty stacks into their own methods
8787
new CollectNullableFields, // Collect fields that can be nulled out after use in lazy initialization
8888
new ElimOuterSelect, // Expand outer selections
89-
//new AugmentScala2Traits, // Augments Scala2 traits with additional members needed for mixin composition.
89+
new AugmentScala2Traits, // Augments Scala2 traits so that super accessors are made non-private
9090
new ResolveSuper, // Implement super accessors
9191
new FunctionXXLForwarders, // Add forwarders for FunctionXXL apply method
9292
new ParamForwarding, // Add forwarders for aliases of superclass parameters

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

+5-20
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@ object AugmentScala2Traits {
2020
val name: String = "augmentScala2Traits"
2121
}
2222

23-
/** This phase augments Scala2 traits with additional members needed for mixin composition.
23+
/** This phase augments Scala2 traits to fix up super accessors.
2424
*
25-
* These symbols would have been added between Unpickling and Mixin in the Scala2 pipeline.
25+
* Strangely, Scala 2 super accessors are pickled as private, but are compiled as public expanded.
26+
* In this phase we expand them and make them non-private, so that `ResolveSuper` does something meaningful.
2627
*
27-
* Specifically, we:
28-
* - Add trait setters for vals defined in traits.
29-
* - Expand the names of all private getters and setters as well as super accessors in the trait and make
30-
* not-private.
28+
* TODO Should we merge this into `ResolveSuper` at this point?
3129
*/
3230
class AugmentScala2Traits extends MiniPhase with IdentityDenotTransformer { thisPhase =>
3331
import ast.tpd._
@@ -47,21 +45,8 @@ class AugmentScala2Traits extends MiniPhase with IdentityDenotTransformer { this
4745
}
4846

4947
private def augmentScala2Trait(mixin: ClassSymbol)(implicit ctx: Context): Unit = {
50-
def traitSetter(getter: TermSymbol) =
51-
getter.copy(
52-
name = getter.ensureNotPrivate.name
53-
.expandedName(getter.owner, TraitSetterName)
54-
.asTermName.setterName,
55-
flags = Method | Accessor,
56-
info = MethodType(getter.info.resultType :: Nil, defn.UnitType))
57-
5848
for (sym <- mixin.info.decls) {
59-
if (sym.isGetter && !sym.isOneOf(DeferredOrLazy) && !sym.setter.exists &&
60-
!sym.info.resultType.isInstanceOf[ConstantType])
61-
traitSetter(sym.asTerm).enteredAfter(thisPhase)
62-
if ((sym.isAllOf(PrivateAccessor) && !sym.name.is(ExpandedName) &&
63-
(sym.isGetter || sym.isSetter)) // strangely, Scala 2 fields are also methods that have Accessor set.
64-
|| sym.isSuperAccessor) // scala2 superaccessors are pickled as private, but are compiled as public expanded
49+
if (sym.isSuperAccessor)
6550
sym.ensureNotPrivate.installAfter(thisPhase)
6651
}
6752
mixin.setFlagFrom(thisPhase, Scala2xPartiallyAugmented)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class ResolveSuper extends MiniPhase with IdentityDenotTransformer { thisPhase =
3434
override def phaseName: String = ResolveSuper.name
3535

3636
override def runsAfter: Set[String] = Set(ElimByName.name, // verified empirically, need to figure out what the reason is.
37-
//AugmentScala2Traits.name,
37+
AugmentScala2Traits.name,
3838
PruneErasedDefs.name) // Erased decls make `isCurrent` work incorrectly
3939

4040
override def changesMembers: Boolean = true // the phase adds super accessors

0 commit comments

Comments
 (0)