8175198: Javac incorrectly allows receiver parameters in annotation methods

Reviewed-by: mcimadamore
This commit is contained in:
Vicente Romero 2017-03-10 09:52:49 -08:00
parent 8588a8563d
commit 50644d73dd
3 changed files with 19 additions and 2 deletions

View File

@ -974,8 +974,11 @@ public class Attr extends JCTree.Visitor {
ClassSymbol owner = env.enclClass.sym;
if ((owner.flags() & ANNOTATION) != 0 &&
tree.params.nonEmpty())
log.error(tree.params.head.pos(),
(tree.params.nonEmpty() ||
tree.recvparam != null))
log.error(tree.params.nonEmpty() ?
tree.params.head.pos() :
tree.recvparam.pos(),
"intf.annotation.members.cant.have.params");
// Attribute all value parameters.

View File

@ -0,0 +1,11 @@
/*
* @test /nodynamiccopyright/
* @bug 8175198
* @summary Javac incorrectly allows receiver parameters in annotation methods
* @compile/fail/ref=AnnotationsAndFormalParamsTest.out -XDrawDiagnostics -Werror -Xlint:unchecked AnnotationsAndFormalParamsTest.java
*/
@interface AnnotationsAndFormalParamsTest {
int value(int i);
int foo(AnnotationsAndFormalParamsTest this);
}

View File

@ -0,0 +1,3 @@
AnnotationsAndFormalParamsTest.java:9:19: compiler.err.intf.annotation.members.cant.have.params
AnnotationsAndFormalParamsTest.java:10:44: compiler.err.intf.annotation.members.cant.have.params
2 errors