OpenJDK / amber / amber
changeset 47434:a21b299b0729 patterns
Fixing disambiguation between lambdas and parentheses in presence of __matches, reported on amber-dev.
author | jlahoda |
---|---|
date | Tue, 17 Oct 2017 09:31:17 +0200 |
parents | 7a3fb234695d |
children | 1683edf5160c |
files | src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java test/langtools/tools/javac/patterns/MatchesToken.java |
diffstat | 2 files changed, 22 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java Tue Oct 17 12:35:54 2017 +0530 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java Tue Oct 17 09:31:17 2017 +0200 @@ -1700,6 +1700,14 @@ // Identifier, "matches" -> ! explicit lambda return ParensResult.PARENS; } + if (peekToken(lookahead, MATCHES)) { + Token next = S.token(lookahead + 1); + if (next.kind == COMMA || next.kind == RPAREN) { + // Identifier matches ','|')' -> explicit lambda + return ParensResult.EXPLICIT_LAMBDA; + } + return ParensResult.PARENS; + } if (peekToken(lookahead, LAX_IDENTIFIER)) { // Identifier, Identifier/'_'/'assert'/'enum' -> explicit lambda return ParensResult.EXPLICIT_LAMBDA;
--- a/test/langtools/tools/javac/patterns/MatchesToken.java Tue Oct 17 12:35:54 2017 +0530 +++ b/test/langtools/tools/javac/patterns/MatchesToken.java Tue Oct 17 09:31:17 2017 +0200 @@ -8,6 +8,20 @@ boolean b1 = __matches __matches __matches; boolean b2 = o __matches __matches; boolean b3 = __matches __matches Integer i; + boolean b4 = (__matches __matches __matches) __matches true; + } + + private void test() { + I1 i1 = (int __matches) -> {}; + I2 i2 = (int __matches, int other) -> {}; + } + + interface I1 { + public void m(int i); + } + + interface I2 { + public void m(int i1, int i2); } }