提交 d4d132d0 编写于 作者: V vromero

8199744: Incorrect compiler message for ReceiverParameter in inner class constructor

Reviewed-by: mcimadamore
上级 cb93815e
......@@ -3106,35 +3106,34 @@ public class JavacParser implements Parser {
name = token.name();
nextToken();
} else {
if (allowThisIdent && !lambdaParameter) {
if (allowThisIdent ||
!lambdaParameter ||
LAX_IDENTIFIER.accepts(token.kind) ||
mods.flags != Flags.PARAMETER ||
mods.annotations.nonEmpty()) {
JCExpression pn = qualident(false);
if (pn.hasTag(Tag.IDENT) && ((JCIdent)pn).name != names._this) {
name = ((JCIdent)pn).name;
} else {
if ((mods.flags & Flags.VARARGS) != 0) {
log.error(token.pos, Errors.VarargsAndReceiver);
}
if (token.kind == LBRACKET) {
log.error(token.pos, Errors.ArrayAndReceiver);
if (allowThisIdent) {
if ((mods.flags & Flags.VARARGS) != 0) {
log.error(token.pos, Errors.VarargsAndReceiver);
}
if (token.kind == LBRACKET) {
log.error(token.pos, Errors.ArrayAndReceiver);
}
}
return toP(F.at(pos).ReceiverVarDef(mods, pn, type));
}
} else {
if (!lambdaParameter ||
LAX_IDENTIFIER.accepts(token.kind) ||
mods.flags != Flags.PARAMETER ||
mods.annotations.nonEmpty()) {
name = ident();
} else {
/** if it is a lambda parameter and the token kind is not an identifier,
* and there are no modifiers or annotations, then this means that the compiler
* supposed the lambda to be explicit but it can contain a mix of implicit,
* var or explicit parameters. So we assign the error name to the parameter name
* instead of issuing an error and analyze the lambda parameters as a whole at
* a higher level.
*/
name = names.empty;
}
/** if it is a lambda parameter and the token kind is not an identifier,
* and there are no modifiers or annotations, then this means that the compiler
* supposed the lambda to be explicit but it can contain a mix of implicit,
* var or explicit parameters. So we assign the error name to the parameter name
* instead of issuing an error and analyze the lambda parameters as a whole at
* a higher level.
*/
name = names.empty;
}
}
if ((mods.flags & Flags.VARARGS) != 0 &&
......@@ -3905,7 +3904,7 @@ public class JavacParser implements Parser {
JCVariableDecl lastParam;
accept(LPAREN);
if (token.kind != RPAREN) {
this.allowThisIdent = true;
this.allowThisIdent = !lambdaParameters;
lastParam = formalParameter(lambdaParameters);
if (lastParam.nameexpr != null) {
this.receiverParam = lastParam;
......
......@@ -2740,7 +2740,8 @@ compiler.err.assert.as.identifier=\
# TODO 308: make a better error message
compiler.err.this.as.identifier=\
as of release 8, ''this'' is allowed as the parameter name for the receiver type only, which has to be the first parameter
as of release 8, ''this'' is allowed as the parameter name for the receiver type only\n\
which has to be the first parameter, and cannot be a lambda parameter
compiler.err.receiver.parameter.not.applicable.constructor.toplevel.class=\
receiver parameter not applicable for constructor of top-level class
......
/*
* @test /nodynamiccopyright/
* @bug 8199744
* @summary Incorrect compiler message for ReceiverParameter in inner class constructor
* @compile/fail/ref=IncorrectMsgQualifiedReceiverTest.out -XDrawDiagnostics IncorrectMsgQualifiedReceiverTest.java
*/
class IncorrectMsgQualifiedReceiverTest {
void foo(int any, IncorrectMsgQualifiedReceiverTest IncorrectMsgQualifiedReceiverTest.this) {}
void bar(int any, IncorrectMsgQualifiedReceiverTest IncorrectMsgQualifiedReceiverTest.this, int another) {}
}
IncorrectMsgQualifiedReceiverTest.java:9:91: compiler.err.this.as.identifier
IncorrectMsgQualifiedReceiverTest.java:10:91: compiler.err.this.as.identifier
2 errors
T8131742.java:8:38: compiler.err.expected3: ',', ')', '['
T8131742.java:8:39: compiler.err.this.as.identifier
T8131742.java:8:43: compiler.err.expected: ';'
3 errors
1 error
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册