Skip to content

Commit 6908239

Browse files
authored
SONARPHP-1600 Parser should support match statements in unary expressions (#1357)
1 parent 98b2ef7 commit 6908239

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

php-frontend/src/main/java/org/sonar/php/parser/PHPGrammar.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,7 @@ public ExpressionTree POWER_EXPR() {
12301230
b.firstOf(
12311231
CAST_EXPR(),
12321232
ASSIGNMENT_EXPRESSION(),
1233+
MATCH_EXPRESSION(),
12331234
POSTFIX_EXPRESSION()),
12341235
b.zeroOrMore(f.newTuple(
12351236
b.token(STAR_STAR),

php-frontend/src/test/java/org/sonar/php/parser/expression/PowerExpressionTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ void test() {
2929
.matches("$a")
3030
.matches("$a ** $a")
3131
.matches("$a ** -2")
32-
.matches("$a ** (int) $a");
32+
.matches("$a ** (int) $a")
33+
.matches("""
34+
match ($food) {
35+
'apple' => 1,
36+
'bar' => 2
37+
} ** 3""");
3338
}
3439

3540
}

php-frontend/src/test/java/org/sonar/php/parser/expression/UnaryExprTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ void test() {
4040
.matches("++$a = $b")
4141
.matches("(int) $a = $b")
4242

43+
.matches("match ($a) {$a=>1}")
44+
.matches("!match ($a) {$a=>1}")
45+
.matches("(string) match ($a) {$a=>1}")
46+
4347
.notMatches("(int) $a + $b");
4448
}
4549
}

0 commit comments

Comments
 (0)