Open momala454 opened 1 year ago
Thanks for reporting this @momala454 !
I've been able to confirm the bug. Smallest reproduction example:
if (!match (1) {
default => 1,
}) {
}
The match
correctly gets scope opener/closers and gets added to conditions
. The if
does not.
I haven't had a chance to properly debug this yet (and may be a while before I can). Relevant part of the verbose output:
Start scope map at 2:T_IF => if
=> Begin scope map recursion at token 2 with depth 1
Process token 3 on line 3 []: T_WHITESPACE =>
Process token 4 on line 3 []: T_OPEN_PARENTHESIS => (
Process token 5 on line 3 []: T_BOOLEAN_NOT => !
Process token 6 on line 3 []: T_MATCH => match
=> Found new opening condition before scope opener for 2:T_IF, backtracking
... and then the backtrace doesn't appear to happen ?
I can see that for closures the debug output from the Tokenizer::recurseScopeMap()
method says "handled manually", so maybe for nested match structures it should be too ?
Note: as I said, haven't done proper debugging yet, so I may well be wrong.
hello, any updates ?
Describe the bug The rule
SlevomatCodingStandard.ControlStructures.EarlyExit
will cause the following error at line 1 (but there is nothing on line 1), and there shouldn't be any error, the code is valid and doesn't contains any if without a curly braceCode sample
Custom ruleset
Strangely, adding anything (even a comment) on the last line inside
foreach
avoid the error. Like this :To reproduce Steps to reproduce the behavior:
test.php
with the code sample above...phpcs test.php ...
Expected behavior A clear and concise description of what you expected to happen.
Versions (please complete the following information):
Additional context Add any other context about the problem here.
Initially reported there https://github.com/slevomat/coding-standard/issues/1506 . They say :
Originally posted by @kukulich in https://github.com/slevomat/coding-standard/issues/1506#issuecomment-1408648561