Skip to content

Treat ^ and v as operators even without surrounding whitespace#639

Open
chuenchen309 wants to merge 1 commit into
fgmacedo:developfrom
chuenchen309:fix/spec-parser-unspaced-classical-operators
Open

Treat ^ and v as operators even without surrounding whitespace#639
chuenchen309 wants to merge 1 commit into
fgmacedo:developfrom
chuenchen309:fix/spec-parser-unspaced-classical-operators

Conversation

@chuenchen309

Copy link
Copy Markdown

parse_boolean_expr has a fast-path that returns the whole expression as a
single variable name when it looks operator-free. It only checked for !, not
the other two documented classical operators ^ (and) / v (or), so an
unspaced guard skipped operator replacement and was resolved as a variable:

cond="a ^ b"   # parsed as (a and b)
cond="a^b"     # resolved as a variable literally named "a^b"

a^b then evaluates wrong (or raises InvalidDefinition: Did not found name 'a^b' at class-definition time). Since !a already worked without spaces, the
inconsistency is surprising — users copy operators from the guards docs, where
^/v are listed with no whitespace requirement.

Gate the fast-path on the module's existing pattern (which already matches
!, ^, and the word-bounded v) instead of the hand-rolled "!" not in expr
check. Genuine single-name variables like avc (no word-boundary v) still
take the fast-path. Added a regression test asserting the unspaced forms match
their spaced equivalents.


This PR was authored by an AI coding agent (Claude Code) running on this account:
the AI found the bug, ran the repro, wrote the test, and wrote this description.
The human account holder reviews every change and is accountable for it. The
verification is real and re-runnable from the diff. If this isn't the kind of
contribution you want, say so and I'll close it.

parse_boolean_expr has a fast-path that returns the whole string as a single
variable name when it contains no operator. It only checked for "!", not the
other two classical operators "^" (and) and "v" (or), so an unspaced guard like
cond="a^b" skipped operator replacement and was looked up as a variable named
"a^b" -- silently evaluating wrong (or raising InvalidDefinition on a
StateChart). "!a" already worked unspaced, so this was an inconsistency.

Gate the fast-path on the module's existing operator `pattern` (which already
matches !, ^ and the word-bounded v) instead of a hand-rolled "!" check.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: chuenchen309 <48723787+chuenchen309@users.noreply.github.com>
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant