Skip to content

Commit

Permalink
only add @compileTimeOnly if it is not already defined
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippus authored and xeno-by committed Jun 18, 2017
1 parent d2da77c commit 7d38641
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ trait Compilers {
val macroTransform = clazz.info.member(nme.macroTransform)
if (macroTransform != NoSymbol) {
clazz.setFlag(MACRO)
clazz.addAnnotation(AnnotationInfo(CompileTimeOnlyAttr.tpe, List(Literal(Constant(MacroAnnotationNotExpandedMessage)) setType StringClass.tpe), Nil))
if (clazz.getAnnotation(CompileTimeOnlyAttr).isEmpty) clazz.addAnnotation(AnnotationInfo(CompileTimeOnlyAttr.tpe, List(Literal(Constant(MacroAnnotationNotExpandedMessage)) setType StringClass.tpe), Nil))
def flavorOk = macroTransform.isMacro
def paramssOk = mmap(macroTransform.paramss)(p => (p.name, p.info)) == List(List((nme.annottees, scalaRepeatedType(AnyTpe))))
def tparamsOk = macroTransform.typeParams.isEmpty
Expand All @@ -38,4 +38,4 @@ trait Compilers {
cdef
}
}
}
}
16 changes: 16 additions & 0 deletions tests/src/main/scala/issue90Class.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import scala.annotation.compileTimeOnly
import scala.annotation.StaticAnnotation
import scala.language.experimental.macros
import scala.reflect.macros.whitebox.Context

object issue90Macro {
def impl(c: Context)(annottees: c.Expr[Any]*): c.Expr[Any] = {
import c.universe._
c.Expr(EmptyTree)
}
}

@compileTimeOnly("this is the only annotation")
final class issue90Class extends StaticAnnotation {
def macroTransform(annottees: Any*): Any = macro issue90Macro.impl
}
10 changes: 10 additions & 0 deletions tests/src/test/scala/annotations/run/Issue90.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import org.scalatest.FunSuite

import scala.reflect.runtime.{currentMirror => cm}

class Issue90 extends FunSuite {
test("compileTimeOnly annotation is not added if it is already in the class definition") {
assert(cm.staticClass("issue90Class").annotations.length == 1)
assert(cm.staticClass("issue90Class").annotations.head.toString == "scala.annotation.compileTimeOnly(\"this is the only annotation\")")
}
}

0 comments on commit 7d38641

Please sign in to comment.