Skip to content

Fixing annotations #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 9, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/dotty/tools/dotc/core/Annotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ object Annotations {

abstract class Annotation {
def tree(implicit ctx: Context): Tree
def symbol(implicit ctx: Context): Symbol = tree.tpe.typeSymbol
def symbol(implicit ctx: Context): Symbol =
if (tree.symbol.isConstructor) tree.symbol.owner
else tree.tpe.typeSymbol
def matches(cls: Symbol)(implicit ctx: Context): Boolean = symbol.derivesFrom(cls)
def appliesToModule: Boolean = true // for now; see remark in SymDenotations

Expand Down
4 changes: 2 additions & 2 deletions src/dotty/tools/dotc/transform/LazyVals.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class LazyValsCreateCompanionObjects extends CreateCompanionObjects {
val body = forClass.rhs.asInstanceOf[Template].body
body.exists {
case x: ValDef =>
(x.mods is Flags.Lazy) && x.mods.annotations.exists(_.tpe == defn.VolatileAnnotType)
(x.mods is Flags.Lazy) && x.symbol.hasAnnotation(defn.VolatileAnnot)
case _ => false
}
}
Expand Down Expand Up @@ -84,7 +84,7 @@ class LazyValTranformContext {
if (!(tree.mods is Flags.Lazy)) tree
else {
val isField = tree.symbol.owner.isClass
val isVolatile = tree.mods.annotations.exists(_.tpe == defn.VolatileAnnotType)
val isVolatile = tree.symbol.hasAnnotation(defn.VolatileAnnot)

if (isField) {
if (isVolatile) transformFieldValDefVolatile(tree)
Expand Down
11 changes: 6 additions & 5 deletions src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -738,8 +738,9 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
assignType(cpy.Alternative(tree, trees1), trees1)
}

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

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

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

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

val TypeDef(mods, name, impl @ Template(constr, parents, self, body)) = cdef
val mods1 = typedModifiers(mods)
val mods1 = typedModifiers(mods, cls)
val constr1 = typed(constr).asInstanceOf[DefDef]
val parents1 = ensureConstrCall(ensureFirstIsClass(
parents mapconserve typedParent, cdef.pos.toSynthetic))
Expand Down
Loading