From 674e6bb0ed9ab7a45bf0016585c2c020eb50351b Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 8 Jun 2015 09:43:18 +0200 Subject: Fix to trait setter generation The logic to add trait setters to Scala 2 traits was wrong. This led to AbstractMethodErrors in the formerly commented out part of scala-trait.scala. --- tests/pos/scala2traits/scala-trait.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/pos') diff --git a/tests/pos/scala2traits/scala-trait.scala b/tests/pos/scala2traits/scala-trait.scala index db05bc941..4d91b12b2 100644 --- a/tests/pos/scala2traits/scala-trait.scala +++ b/tests/pos/scala2traits/scala-trait.scala @@ -9,7 +9,7 @@ trait T { trait S2T { var x: Int = 0 lazy val y: Int = 1 -// val z: Int = 2 + val z: Int = 2 val a: Int var b: Int @@ -19,13 +19,13 @@ trait S2T { trait S2Tprivate { private var x: Int = 0 private lazy val y: Int = 1 -// private val z: Int = 2 // @darkdimius uncomment once lazy vals can be inherited. + private val z: Int = 2 private def f(x: Int): Int = x + y def xx = x def xx_=(x: Int) = this.x = x def yy = y -// def zz = z + def zz = z def ff(x: Int) = f(x) } -- cgit v1.2.3 From 8191c86cba985e9edb596fbd1a2190c02cf45e0b Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 8 Jun 2015 12:41:06 +0200 Subject: Copy annotations from trait members to their implementations Implementations inherit all annotations on the implemented trait methods. --- src/dotty/tools/dotc/transform/MixinOps.scala | 7 +++++-- tests/pos/scala2traits/dotty-subclass.scala | 8 +++++++- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'tests/pos') diff --git a/src/dotty/tools/dotc/transform/MixinOps.scala b/src/dotty/tools/dotc/transform/MixinOps.scala index 64f0edfb8..48c6f9bea 100644 --- a/src/dotty/tools/dotc/transform/MixinOps.scala +++ b/src/dotty/tools/dotc/transform/MixinOps.scala @@ -13,12 +13,15 @@ class MixinOps(cls: ClassSymbol, thisTransform: DenotTransformer)(implicit ctx: val superCls: Symbol = cls.superClass val mixins: List[ClassSymbol] = cls.mixins - def implementation(member: TermSymbol): TermSymbol = - member.copy( + def implementation(member: TermSymbol): TermSymbol = { + val res = member.copy( owner = cls, name = member.name.stripScala2LocalSuffix, flags = member.flags &~ Deferred, info = cls.thisType.memberInfo(member)).enteredAfter(thisTransform).asTerm + res.addAnnotations(member) + res + } def superRef(target: Symbol, pos: Position = cls.pos): Tree = { val sup = if (target.isConstructor && !target.owner.is(Trait)) diff --git a/tests/pos/scala2traits/dotty-subclass.scala b/tests/pos/scala2traits/dotty-subclass.scala index 4e162dd14..62720b993 100644 --- a/tests/pos/scala2traits/dotty-subclass.scala +++ b/tests/pos/scala2traits/dotty-subclass.scala @@ -1,7 +1,13 @@ // This is supposed to be compiled by Dotty class Sub extends T -class A extends S2T with S2Tprivate { +trait DT { + + @volatile lazy val dx = 2 + +} + +class A extends S2T with S2Tprivate with DT { val a: Int = 3 var b = 2 } -- cgit v1.2.3