Skip to content

Commit 3750291

Browse files
committed
Merge pull request #118 from dotty-staging/fix/annotations
Fixing annotations
2 parents 6bc463d + 01c33ee commit 3750291

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

src/dotty/tools/dotc/core/Annotations.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ object Annotations {
77

88
abstract class Annotation {
99
def tree(implicit ctx: Context): Tree
10-
def symbol(implicit ctx: Context): Symbol = tree.tpe.typeSymbol
10+
def symbol(implicit ctx: Context): Symbol =
11+
if (tree.symbol.isConstructor) tree.symbol.owner
12+
else tree.tpe.typeSymbol
1113
def matches(cls: Symbol)(implicit ctx: Context): Boolean = symbol.derivesFrom(cls)
1214
def appliesToModule: Boolean = true // for now; see remark in SymDenotations
1315

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class LazyValsCreateCompanionObjects extends CreateCompanionObjects {
3232
val body = forClass.rhs.asInstanceOf[Template].body
3333
body.exists {
3434
case x: ValDef =>
35-
(x.mods is Flags.Lazy) && x.mods.annotations.exists(_.tpe == defn.VolatileAnnotType)
35+
(x.mods is Flags.Lazy) && x.symbol.hasAnnotation(defn.VolatileAnnot)
3636
case _ => false
3737
}
3838
}
@@ -84,7 +84,7 @@ class LazyValTranformContext {
8484
if (!(tree.mods is Flags.Lazy)) tree
8585
else {
8686
val isField = tree.symbol.owner.isClass
87-
val isVolatile = tree.mods.annotations.exists(_.tpe == defn.VolatileAnnotType)
87+
val isVolatile = tree.symbol.hasAnnotation(defn.VolatileAnnot)
8888

8989
if (isField) {
9090
if (isVolatile) transformFieldValDefVolatile(tree)

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -738,8 +738,9 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
738738
assignType(cpy.Alternative(tree, trees1), trees1)
739739
}
740740

741-
def typedModifiers(mods: untpd.Modifiers)(implicit ctx: Context): Modifiers = track("typedModifiers") {
741+
def typedModifiers(mods: untpd.Modifiers, sym: Symbol)(implicit ctx: Context): Modifiers = track("typedModifiers") {
742742
val annotations1 = mods.annotations mapconserve typedAnnotation
743+
for (tree <- annotations1) sym.addAnnotation(Annotation(tree))
743744
if (annotations1 eq mods.annotations) mods.asInstanceOf[Modifiers]
744745
else Modifiers(mods.flags, mods.privateWithin, annotations1)
745746
}
@@ -750,7 +751,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
750751

751752
def typedValDef(vdef: untpd.ValDef, sym: Symbol)(implicit ctx: Context) = track("typedValDef") {
752753
val ValDef(mods, name, tpt, rhs) = vdef
753-
val mods1 = typedModifiers(mods)
754+
val mods1 = typedModifiers(mods, sym)
754755
val tpt1 = typedType(tpt)
755756
if ((sym is Implicit) && sym.owner.isType) checkImplicitTptNonEmpty(vdef)
756757
val rhs1 = rhs match {
@@ -762,7 +763,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
762763

763764
def typedDefDef(ddef: untpd.DefDef, sym: Symbol)(implicit ctx: Context) = track("typedDefDef") {
764765
val DefDef(mods, name, tparams, vparamss, tpt, rhs) = ddef
765-
val mods1 = typedModifiers(mods)
766+
val mods1 = typedModifiers(mods, sym)
766767
val tparams1 = tparams mapconserve (typed(_).asInstanceOf[TypeDef])
767768
val vparamss1 = vparamss nestedMapconserve (typed(_).asInstanceOf[ValDef])
768769
if (sym is Implicit) {
@@ -777,7 +778,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
777778

778779
def typedTypeDef(tdef: untpd.TypeDef, sym: Symbol)(implicit ctx: Context): Tree = track("typedTypeDef") {
779780
val TypeDef(mods, name, rhs) = tdef
780-
val mods1 = typedModifiers(mods)
781+
val mods1 = typedModifiers(mods, sym)
781782
val _ = typedType(rhs) // unused, typecheck only to remove from typedTree
782783
assignType(cpy.TypeDef(tdef, mods1, name, TypeTree(sym.info)), sym)
783784
}
@@ -804,7 +805,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
804805
}
805806

806807
val TypeDef(mods, name, impl @ Template(constr, parents, self, body)) = cdef
807-
val mods1 = typedModifiers(mods)
808+
val mods1 = typedModifiers(mods, cls)
808809
val constr1 = typed(constr).asInstanceOf[DefDef]
809810
val parents1 = ensureConstrCall(ensureFirstIsClass(
810811
parents mapconserve typedParent, cdef.pos.toSynthetic))

0 commit comments

Comments
 (0)