Skip to content

Commit 308cdb2

Browse files
committed
Remove nonsensical body for trait getter
This corrects an error in the change to the trait encoding in scala#5003: getters in traits should have empty bodies and be emitted as abstract. ``` % ~/scala/2.12.0-M4/bin/scalac sandbox/test.scala && javap -c T Compiled from "test.scala" public interface T { public abstract void T$_setter_$x_$eq(int); public int x(); Code: 0: aload_0 1: invokeinterface #15, 1 // InterfaceMethod x:()I 6: ireturn public int y(); Code: 0: aload_0 1: invokeinterface #20, 1 // InterfaceMethod y:()I 6: ireturn public void y_$eq(int); Code: 0: aload_0 1: iload_1 2: invokeinterface #24, 2 // InterfaceMethod y_$eq:(I)V 7: return public void $init$(); Code: 0: aload_0 1: bipush 42 3: invokeinterface #29, 2 // InterfaceMethod T$_setter_$x_$eq:(I)V 8: aload_0 9: bipush 24 11: invokeinterface #24, 2 // InterfaceMethod y_$eq:(I)V 16: return } % qscalac sandbox/test.scala && javap -c T Compiled from "test.scala" public interface T { public abstract void T$_setter_$x_$eq(int); public abstract int x(); public abstract int y(); public abstract void y_$eq(int); public static void $init$(T); Code: 0: aload_0 1: bipush 42 3: invokeinterface #21, 2 // InterfaceMethod T$_setter_$x_$eq:(I)V 8: aload_0 9: bipush 24 11: invokeinterface #23, 2 // InterfaceMethod y_$eq:(I)V 16: return public void $init$(); Code: 0: aload_0 1: invokestatic #27 // Method $init$:(LT;)V 4: return } ```
1 parent 3bb7358 commit 308cdb2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -1001,8 +1001,13 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
10011001
val parents1 = currentOwner.info.parents map (t => TypeTree(t) setPos tree.pos)
10021002
// mark fields which can be nulled afterward
10031003
lazyValNullables = nullableFields(templ) withDefaultValue Set()
1004+
val bodyEmptyAccessors = if (!sym.enclClass.isTrait) body else body mapConserve {
1005+
case dd: DefDef if dd.symbol.isAccessor && !dd.symbol.isLazy =>
1006+
deriveDefDef(dd)(_ => EmptyTree)
1007+
case tree => tree
1008+
}
10041009
// add all new definitions to current class or interface
1005-
treeCopy.Template(tree, parents1, self, addNewDefs(currentOwner, body))
1010+
treeCopy.Template(tree, parents1, self, addNewDefs(currentOwner, bodyEmptyAccessors))
10061011

10071012
case Select(qual, name) if sym.owner.isTrait && !sym.isMethod =>
10081013
// refer to fields in some trait an abstract getter in the interface.

0 commit comments

Comments
 (0)