Skip to content

Commit 65e5278

Browse files
committed
wip: drop add interfaces, straight to interface from trait
what could possibly go wrong /* * Decompiled with CFR 0_101. * * Could not load the following classes: * scala.reflect.ScalaSignature */ import scala.reflect.ScalaSignature; @ScalaSignature(bytes="\u0006\u0001\t2q!\u0001\u0002\u0011\u0002\u0007\u0005QAA\u0001U\u0015\u0005\u0019\u0011a\u0002\u001ff[B$\u0018PP\u0002\u0001'\t\u0001a\u0001\u0005\u0002\b\u00155\t\u0001BC\u0001\n\u0003\u0015\u00198-\u00197b\u0013\tY\u0001B\u0001\u0004B]f\u0014VM\u001a\u0005\u0006\u001b\u0001!\tAD\u0001\u0007I%t\u0017\u000e\u001e\u0013\u0015\u0003=\u0001\"a\u0002\t\n\u0005EA!\u0001B+oSRDQa\u0005\u0001\u0005\u0002Q\t\u0011\u0001_\u000b\u0002+A\u0011qAF\u0005\u0003/!\u00111!\u00138u\u0011\u0015I\u0002A\"\u0001\u001b\u0003\u0005IX#A\u000e\u0011\u0005qybBA\u0004\u001e\u0013\tq\u0002\"\u0001\u0004Qe\u0016$WMZ\u0005\u0003A\u0005\u0012aa\u0015;sS:<'B\u0001\u0010\t\u0001") public interface T { default public int x() { return 3; } public String y(); default public void $init$() { } } ➜ scala git:(defaults) ✗ cat /Users/adriaan/Desktop/trait_accessors.scala trait T { def x: Int = 3 def y: String } object O extends T { val y = "2" def main(args: Array[String]): Unit = { println(x + y) } }%
1 parent 4df7b6a commit 65e5278

File tree

6 files changed

+26
-27
lines changed

6 files changed

+26
-27
lines changed

src/compiler/scala/tools/nsc/backend/jvm/BCodeAsmCommon.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ final class BCodeAsmCommon[G <: Global](val global: G) {
262262
if (classSym.isPublic) ACC_PUBLIC else 0,
263263
if (classSym.isFinal) ACC_FINAL else 0,
264264
// see the link above. javac does the same: ACC_SUPER for all classes, but not interfaces.
265-
if (classSym.isInterface) ACC_INTERFACE else ACC_SUPER,
265+
if (classSym.isInterface && !classSym.isTrait) ACC_INTERFACE else ACC_SUPER,
266266
// for Java enums, we cannot trust `hasAbstractFlag` (see comment in enumFlags)
267267
if (!classSym.hasJavaEnumFlag && classSym.hasAbstractFlag) ACC_ABSTRACT else 0,
268268
if (classSym.isArtifact) ACC_SYNTHETIC else 0,

src/compiler/scala/tools/nsc/backend/jvm/BTypes.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ abstract class BTypes {
824824
def info_=(i: Either[NoClassBTypeInfo, ClassInfo]): Unit = {
825825
assert(_info == null, s"Cannot set ClassBType.info multiple times: $this")
826826
_info = i
827-
checkInfoConsistency()
827+
// checkInfoConsistency()
828828
}
829829

830830
classBTypeFromInternalName(internalName) = this

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -572,12 +572,12 @@ class BTypesFromSymbols[G <: Global](val global: G) extends BTypes {
572572
GenBCode.mkFlags(
573573
if (privateFlag) ACC_PRIVATE else ACC_PUBLIC,
574574
if ((sym.isDeferred && !sym.hasFlag(symtab.Flags.JAVA_DEFAULTMETHOD))|| sym.hasAbstractFlag) ACC_ABSTRACT else 0,
575-
if (sym.isInterface) ACC_INTERFACE else 0,
575+
if (sym.isInterface || sym.isTrait) ACC_INTERFACE else 0,
576576
if (finalFlag && !sym.hasAbstractFlag) ACC_FINAL else 0,
577577
if (sym.isStaticMember) ACC_STATIC else 0,
578578
if (sym.isBridge) ACC_BRIDGE | ACC_SYNTHETIC else 0,
579579
if (sym.isArtifact) ACC_SYNTHETIC else 0,
580-
if (sym.isClass && !sym.isInterface) ACC_SUPER else 0,
580+
if (sym.isClass && !sym.isTrait) ACC_SUPER else 0,
581581
if (sym.hasJavaEnumFlag) ACC_ENUM else 0,
582582
if (sym.isVarargsMethod) ACC_VARARGS else 0,
583583
if (sym.hasFlag(symtab.Flags.SYNCHRONIZED)) ACC_SYNCHRONIZED else 0,

src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters { self =>
306306
if (sym.isStaticMember) ACC_STATIC else 0,
307307
if (sym.isBridge) ACC_BRIDGE | ACC_SYNTHETIC else 0,
308308
if (sym.isArtifact) ACC_SYNTHETIC else 0,
309-
if (sym.isClass && !sym.isInterface) ACC_SUPER else 0,
309+
if (sym.isClass && !sym.isTrait) ACC_SUPER else 0,
310310
if (sym.hasJavaEnumFlag) ACC_ENUM else 0,
311311
if (sym.isVarargsMethod) ACC_VARARGS else 0,
312312
if (sym.hasFlag(Flags.SYNCHRONIZED)) ACC_SYNCHRONIZED else 0

src/compiler/scala/tools/nsc/transform/Erasure.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import symtab._
1212
import Flags._
1313
import scala.reflect.internal.Mode._
1414

15-
abstract class Erasure extends scala.reflect.internal.transform.Erasure
15+
abstract class Erasure extends InfoTransform with scala.reflect.internal.transform.Erasure
1616
with typechecker.Analyzer
1717
with TypingTransformers
1818
with ast.TreeDSL

src/compiler/scala/tools/nsc/transform/Mixin.scala

+20-21
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
111111
/** The implementation class corresponding to a currently compiled interface.
112112
* todo: try to use Symbol.implClass instead?
113113
*/
114-
private def implClass(iface: Symbol) = iface.implClass orElse (erasure implClass iface)
114+
private def implClass(iface: Symbol) = iface.implClass //orElse (erasure implClass iface)
115115

116116
/** Returns the symbol that is accessed by a super-accessor in a mixin composition.
117117
*
@@ -191,15 +191,14 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
191191
newSym
192192
}
193193

194-
/** Add getters and setters for all non-module fields of an implementation
195-
* class to its interface unless they are already present. This is done
196-
* only once per class. The mixedin flag is used to remember whether late
197-
* members have been added to an interface.
198-
* - lazy fields don't get a setter.
199-
*/
200-
def addLateInterfaceMembers(clazz: Symbol) {
201-
if (treatedClassInfos(clazz) != clazz.info) {
202-
treatedClassInfos(clazz) = clazz.info
194+
/** Add getters and setters for all non-module fields of `mixinClass`'s implementation class
195+
* to `mixinClass`, unless they are already present. This is done only once per class.
196+
* The mixedin flag is used to remember whether late members have been added to an interface.
197+
* Lazy fields don't get a setter.
198+
*/
199+
def addLateInterfaceMembers(mixinClass: Symbol) {
200+
if (treatedClassInfos(mixinClass) != mixinClass.info) {
201+
treatedClassInfos(mixinClass) = mixinClass.info
203202
assert(phase == currentRun.mixinPhase, phase)
204203

205204
/* Create a new getter. Getters are never private or local. They are
@@ -208,7 +207,7 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
208207
// println("creating new getter for "+ field +" : "+ field.info +" at "+ field.locationString+(field hasFlag MUTABLE))
209208
val newFlags = field.flags & ~PrivateLocal | ACCESSOR | lateDEFERRED | ( if (field.isMutable) 0 else STABLE )
210209
// TODO preserve pre-erasure info?
211-
clazz.newMethod(field.getterName, field.pos, newFlags) setInfo MethodType(Nil, field.info)
210+
mixinClass.newMethod(field.getterName, field.pos, newFlags) setInfo MethodType(Nil, field.info)
212211
}
213212

214213
/* Create a new setter. Setters are never private or local. They are
@@ -217,33 +216,33 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
217216
//println("creating new setter for "+field+field.locationString+(field hasFlag MUTABLE))
218217
val setterName = field.setterName
219218
val newFlags = field.flags & ~PrivateLocal | ACCESSOR | lateDEFERRED
220-
val setter = clazz.newMethod(setterName, field.pos, newFlags)
219+
val setter = mixinClass.newMethod(setterName, field.pos, newFlags)
221220
// TODO preserve pre-erasure info?
222221
setter setInfo MethodType(setter.newSyntheticValueParams(List(field.info)), UnitTpe)
223222
if (field.needsExpandedSetterName)
224-
setter.name = nme.expandedSetterName(setter.name, clazz)
223+
setter.name = nme.expandedSetterName(setter.name, mixinClass)
225224

226225
setter
227226
}
228227

229-
clazz.info // make sure info is up to date, so that implClass is set.
230-
val impl = implClass(clazz) orElse abort("No impl class for " + clazz)
228+
mixinClass.info // make sure info is up to date, so that implClass is set.
229+
val impl = implClass(mixinClass) orElse abort("No impl class for " + mixinClass)
231230

232231
for (member <- impl.info.decls) {
233232
if (!member.isMethod && !member.isModule && !member.isModuleVar) {
234233
assert(member.isTerm && !member.isDeferred, member)
235234
if (member.getterIn(impl).isPrivate) {
236-
member.makeNotPrivate(clazz) // this will also make getter&setter not private
235+
member.makeNotPrivate(mixinClass) // this will also make getter&setter not private
237236
}
238-
val getter = member.getterIn(clazz)
239-
if (getter == NoSymbol) addMember(clazz, newGetter(member))
237+
val getter = member.getterIn(mixinClass)
238+
if (getter == NoSymbol) addMember(mixinClass, newGetter(member))
240239
if (!member.tpe.isInstanceOf[ConstantType] && !member.isLazy) {
241-
val setter = member.setterIn(clazz)
242-
if (setter == NoSymbol) addMember(clazz, newSetter(member))
240+
val setter = member.setterIn(mixinClass)
241+
if (setter == NoSymbol) addMember(mixinClass, newSetter(member))
243242
}
244243
}
245244
}
246-
debuglog("new defs of " + clazz + " = " + clazz.info.decls)
245+
debuglog("new defs of " + mixinClass + " = " + mixinClass.info.decls)
247246
}
248247
}
249248

0 commit comments

Comments
 (0)