Describe the bug
A block of code having a when() with guard conditions is incorrectly reported as an error.
Example code:
when (val node = path.node) {
// Handle property declarations (val/const val)
is PropertyDeclaration if node.initializerExpression != null -> addIfValid(node.initializerExpression!!)
// ...
}
the relevant part of error log:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':diktatCheck'.
> 124:44 Expecting '->'
Notice the reported text position is at the first character of if.
Expected behavior
Code passes checks
Observed behavior
- Code fails the check
- The message reports an error but no specific rule is violated
- The Diktat reports are empty
Steps to Reproduce
- Write a block of code using when with guards
- run
gradle diktatCheck
Environment information
- diktat version: 2.0.0
- build tool (maven/gradle): gradle
- how is diktat run (CLI, plugin, etc.): plugin
- kotlin version: 2.2.21
- operating system: MacOS 26.2
Describe the bug
A block of code having a
when()with guard conditions is incorrectly reported as an error.Example code:
the relevant part of error log:
Notice the reported text position is at the first character of
if.Expected behavior
Code passes checks
Observed behavior
Steps to Reproduce
gradle diktatCheckEnvironment information