8335766: Switch case with pattern matching and guard clause compiles inconsistently
Reviewed-by: abimpoudis
This commit is contained in:
parent
a44b60c8c1
commit
537d20afbf
@ -3436,7 +3436,15 @@ public class JavacParser implements Parser {
|
||||
: PatternResult.PATTERN;
|
||||
}
|
||||
parenDepth++; break;
|
||||
case RPAREN: parenDepth--; break;
|
||||
case RPAREN:
|
||||
parenDepth--;
|
||||
if (parenDepth == 0 &&
|
||||
typeDepth == 0 &&
|
||||
peekToken(lookahead, TokenKind.IDENTIFIER) &&
|
||||
S.token(lookahead + 1).name() == names.when) {
|
||||
return PatternResult.PATTERN;
|
||||
}
|
||||
break;
|
||||
case ARROW: return parenDepth > 0 ? PatternResult.EXPRESSION
|
||||
: pendingResult;
|
||||
case FINAL:
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -109,6 +109,10 @@ public class DisambiguatePatterns {
|
||||
ExpressionType.EXPRESSION);
|
||||
test.disambiguationTest("a & b",
|
||||
ExpressionType.EXPRESSION);
|
||||
test.disambiguationTest("R r when (x > 0)",
|
||||
ExpressionType.PATTERN);
|
||||
test.disambiguationTest("R(int x) when (x > 0)",
|
||||
ExpressionType.PATTERN);
|
||||
}
|
||||
|
||||
private final ParserFactory factory;
|
||||
|
Loading…
Reference in New Issue
Block a user