diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-01-14 15:35:36 -0800 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-01-14 15:35:36 -0800 |
commit | be9428e05f6c91b820dd7a08bd72e61edaf1a7e5 (patch) | |
tree | 70849264d0bb0be2e79c06efd9fa423e94aca5d1 | |
parent | 5197864839ce046336f1447a42f2bca1082abb5e (diff) | |
parent | 39352fe0f3048e86b339db4b40851a9f27c7a6ef (diff) | |
download | scala-be9428e05f6c91b820dd7a08bd72e61edaf1a7e5.tar.gz scala-be9428e05f6c91b820dd7a08bd72e61edaf1a7e5.tar.bz2 scala-be9428e05f6c91b820dd7a08bd72e61edaf1a7e5.zip |
Merge pull request #1894 from retronym/ticket/6082
SI-6082 Conditionally expand @ann(x) to @ann(value = x)
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 11 | ||||
-rw-r--r-- | test/files/neg/t6082.check | 13 | ||||
-rw-r--r-- | test/files/neg/t6082.scala | 2 |
3 files changed, 22 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 61f4a6bdf9..2720f8a0ef 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -3672,15 +3672,18 @@ trait Typers extends Modes with Adaptations with Tags { } else if (argss.length > 1) { reportAnnotationError(MultipleArgumentListForAnnotationError(ann)) } else { - val args = - if (argss.head.length == 1 && !isNamed(argss.head.head)) - List(new AssignOrNamedArg(Ident(nme.value), argss.head.head)) - else argss.head val annScope = annType.decls .filter(sym => sym.isMethod && !sym.isConstructor && sym.isJavaDefined) val names = new scala.collection.mutable.HashSet[Symbol] + def hasValue = names exists (_.name == nme.value) names ++= (if (isJava) annScope.iterator else typedFun.tpe.params.iterator) + val args = argss match { + case List(List(arg)) if !isNamed(arg) && hasValue => + List(new AssignOrNamedArg(Ident(nme.value), arg)) + case as :: _ => as + } + val nvPairs = args map { case arg @ AssignOrNamedArg(Ident(name), rhs) => val sym = if (isJava) annScope.lookup(name) diff --git a/test/files/neg/t6082.check b/test/files/neg/t6082.check new file mode 100644 index 0000000000..b68de5ce08 --- /dev/null +++ b/test/files/neg/t6082.check @@ -0,0 +1,13 @@ +t6082.scala:1: warning: Implementation restriction: subclassing Classfile does not +make your annotation visible at runtime. If that is what +you want, you must write the annotation class in Java. +class annot(notValue: String) extends annotation.ClassfileAnnotation + ^ +t6082.scala:2: error: classfile annotation arguments have to be supplied as named arguments +@annot("") class C + ^ +t6082.scala:2: error: annotation annot is missing argument notValue +@annot("") class C + ^ +one warning found +two errors found diff --git a/test/files/neg/t6082.scala b/test/files/neg/t6082.scala new file mode 100644 index 0000000000..30de91a4c9 --- /dev/null +++ b/test/files/neg/t6082.scala @@ -0,0 +1,2 @@ +class annot(notValue: String) extends annotation.ClassfileAnnotation +@annot("") class C
\ No newline at end of file |