Skip to content

Commit 8191c86

Browse files
committed
Copy annotations from trait members to their implementations
Implementations inherit all annotations on the implemented trait methods.
1 parent 674e6bb commit 8191c86

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/dotty/tools/dotc/transform/MixinOps.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ class MixinOps(cls: ClassSymbol, thisTransform: DenotTransformer)(implicit ctx:
1313
val superCls: Symbol = cls.superClass
1414
val mixins: List[ClassSymbol] = cls.mixins
1515

16-
def implementation(member: TermSymbol): TermSymbol =
17-
member.copy(
16+
def implementation(member: TermSymbol): TermSymbol = {
17+
val res = member.copy(
1818
owner = cls,
1919
name = member.name.stripScala2LocalSuffix,
2020
flags = member.flags &~ Deferred,
2121
info = cls.thisType.memberInfo(member)).enteredAfter(thisTransform).asTerm
22+
res.addAnnotations(member)
23+
res
24+
}
2225

2326
def superRef(target: Symbol, pos: Position = cls.pos): Tree = {
2427
val sup = if (target.isConstructor && !target.owner.is(Trait))

tests/pos/scala2traits/dotty-subclass.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
// This is supposed to be compiled by Dotty
22
class Sub extends T
33

4-
class A extends S2T with S2Tprivate {
4+
trait DT {
5+
6+
@volatile lazy val dx = 2
7+
8+
}
9+
10+
class A extends S2T with S2Tprivate with DT {
511
val a: Int = 3
612
var b = 2
713
}

0 commit comments

Comments
 (0)