Skip to content

Commit

Permalink
SONARPHP-1600 Parser should support match statements in unary express…
Browse files Browse the repository at this point in the history
…ions (#1357)
  • Loading branch information
GabinL21 authored Jan 3, 2025
1 parent 98b2ef7 commit 6908239
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,7 @@ public ExpressionTree POWER_EXPR() {
b.firstOf(
CAST_EXPR(),
ASSIGNMENT_EXPRESSION(),
MATCH_EXPRESSION(),
POSTFIX_EXPRESSION()),
b.zeroOrMore(f.newTuple(
b.token(STAR_STAR),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ void test() {
.matches("$a")
.matches("$a ** $a")
.matches("$a ** -2")
.matches("$a ** (int) $a");
.matches("$a ** (int) $a")
.matches("""
match ($food) {
'apple' => 1,
'bar' => 2
} ** 3""");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ void test() {
.matches("++$a = $b")
.matches("(int) $a = $b")

.matches("match ($a) {$a=>1}")
.matches("!match ($a) {$a=>1}")
.matches("(string) match ($a) {$a=>1}")

.notMatches("(int) $a + $b");
}
}

0 comments on commit 6908239

Please sign in to comment.