File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed
src/jdk.compiler/share/classes/com/sun/tools/javac/parser
test/langtools/tools/javac/patterns Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -3436,7 +3436,15 @@ PatternResult analyzePattern(int lookahead) {
34363436 : PatternResult .PATTERN ;
34373437 }
34383438 parenDepth ++; break ;
3439- case RPAREN : parenDepth --; break ;
3439+ case RPAREN :
3440+ parenDepth --;
3441+ if (parenDepth == 0 &&
3442+ typeDepth == 0 &&
3443+ peekToken (lookahead , TokenKind .IDENTIFIER ) &&
3444+ S .token (lookahead + 1 ).name () == names .when ) {
3445+ return PatternResult .PATTERN ;
3446+ }
3447+ break ;
34403448 case ARROW : return parenDepth > 0 ? PatternResult .EXPRESSION
34413449 : pendingResult ;
34423450 case FINAL :
Original file line number Diff line number Diff line change 11/*
2- * Copyright (c) 2021, 2022 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2021, 2024 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
@@ -109,6 +109,10 @@ public static void main(String... args) throws Throwable {
109109 ExpressionType .EXPRESSION );
110110 test .disambiguationTest ("a & b" ,
111111 ExpressionType .EXPRESSION );
112+ test .disambiguationTest ("R r when (x > 0)" ,
113+ ExpressionType .PATTERN );
114+ test .disambiguationTest ("R(int x) when (x > 0)" ,
115+ ExpressionType .PATTERN );
112116 }
113117
114118 private final ParserFactory factory ;
You can’t perform that action at this time.
0 commit comments