fix(visitor): store text expressions with their whitespace - #692
Merged
Merged
Conversation
Four places stored an expression as TEXT via ANTLR's ctx.GetText(),
which joins the tokens without the whitespace between them. Literals,
`+` and a lone $currentObject survive that, so the common cases looked
right; a keyword operator fuses with its neighbours, and the fused text
was written into the model:
action: microflow GT.ACT(Flag: true and false) -> "trueandfalse"
action: microflow GT.ACT(Mode: if true then 'a' else 'b')
-> "iftruethen'a'else'b'"
send rest request ... with ($OrderId = if $x then $id else 'none')
-> "if$xthen$idelse'none'"
Measured by decoding the units on a copy of ako/TestApp (11.14.0);
check -p --references passed on all of it. Also affected: contentparams
values and a dynamic `execute database query`.
expressionSourceText takes the author's text - whitespace kept, MDL
comments stripped - the same extraction the microflow expression sites
moved to for the comment-leak fix, which missed these four because they
live in page and REST code. ruleSourceText (the OData and widget
expression slots) now shares it, so a comment inside those expressions
is stripped too.
Tests failed first with the fused values (`$aand$b`,
`if$xthen'a'else'b'`, `if$xthen1else2`); the single-token control
`$currentObject` passed throughout. After the fix the same TestApp run
stores "true and false", "if true then 'a' else 'b'" and
"if $x then $id else 'none'".
Found while resolving PROPOSAL_first_class_expressions.md §5.1.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P65SqmwwvbWdJVRwhYiMQw
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found while resolving §5.1 of
docs/11-proposals/PROPOSAL_first_class_expressions.md(mendixlabs#750).The bug
Four places stored an expression as text via ANTLR's
ctx.GetText(), which joins the tokens without the whitespace between them.+and a lone$currentObject. So the common cases looked right, and no test caught it.Measured by decoding the units on a copy of ako/TestApp (Mendix 11.14.0).
check -p --referencespassed on all of it:action: microflow GT.ACT(Flag: true and false)trueandfalsetrue and falseaction: microflow GT.ACT(Mode: if true then 'a' else 'b')iftruethen'a'else'b'if true then 'a' else 'b'send rest request … with ($OrderId = if $x then $id else 'none')if$xthen$idelse'none'if $x then $id else 'none'contentparamsvalues and a dynamicexecute database querywere affected the same way.The fix
expressionSourceTexttakes the author's text, keeps the whitespace and strips MDL comments. It's the same extraction the microflow expression sites already use.extractExpressionText. These four live in page and REST code, not microflow statements.ruleSourceText, used by the OData and widget expression settings from feat(odata): credentials and headers as expressions, ServiceUrl as a constant reference (#750) #676 and feat(pages): write DynamicClasses and DynamicCellClass as expressions (#750) #682, now shares the same helper. A comment inside those expressions is now stripped too.Evidence
mdl/visitor/visitor_expression_source_text_test.gocovers each site plus a comment case. Before the fix it failed with$aand$b,if$xthen'a'else'b'andif$xthen1else2. The single-token control$currentObjectpassed throughout.describeprints them readably.mdl-examples/bug-tests/expression-text-keyword-operators.mdl, a finding infindings/mdl-visitor.jsonl, and a changelog entry under Fixed.Found, not fixed here
describe microflowdrops asend rest request'swith (…)parameters. The binding is stored, but a round trip loses it. It's a separate describe gap.not $adoes not parse as an expression. It's a grammar gap.Checks
make build,make test,make lint,make check-mdlandmake check-findingspass after merging currentmain.mx checkwas not run, because there is no mxbuild in this environment. I'd expect CE0117 on the fused expressions it replaces.🤖 Generated with Claude Code
https://claude.ai/code/session_01P65SqmwwvbWdJVRwhYiMQw
Generated by Claude Code