Skip to content

fix(codegen): cast replaced expressions to the expected type - #1957

Closed
volsa wants to merge 1 commit into
masterfrom
fix/codegen-replacement-cast
Closed

volsa wants to merge 1 commit into
masterfrom
fix/codegen-replacement-cast

Conversation

@volsa

@volsa volsa commented Sep 30, 2026

Copy link
Copy Markdown
Member

Problem: Codegen stores the result of an expression the resolver replaced (the builtins ADD, SUB, MUL, DIV, date and time operators, string comparisons) without converting it to the type of the target. x := t * 1.5 with an LREAL x writes the TIME bits into the double and reads 0.0, n := ADD(n, r) stores float bits into a DINT, and (tod + T#20s) in parentheses skips the replacement and does not wrap at midnight. With #1937, the builtin forms such as MUL(t, 1.5) would hit the same path.

Solution: Generate the replacement where every expression value is generated. The replaced node already has the type of its replacement, so its value takes the same conversion to its hint as any other value, also inside parentheses.

🤖 Generated with Claude Code

Problem: Codegen stores the result of an expression the resolver
replaced (the builtins ADD, SUB, MUL, DIV, date and time operators,
string comparisons) without converting it to the type of the target.
`x := t * 1.5` with an LREAL `x` writes the TIME bits into the double
and reads 0.0, and `(tod + T#20s)` in parentheses skips the replacement
and does not wrap at midnight.

Solution: Generate the replacement where every expression value is
generated, so the replaced value takes the same conversion to its hint
as any other value, also inside parentheses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Build Artifacts

🐧 Linux

Artifact Link Size
plc-aarch64 Download 43.4 MB
deb-x86_64 Download 38.5 MB
plc-x86_64 Download 43.6 MB
stdlib Download 32.4 MB
deb-aarch64 Download 30.9 MB
schema Download 0.0 MB

From workflow run

🪟 Windows

Artifact Link Size
plc.exe Download 38.4 MB
stdlib.lib Download 4.0 MB
stdlib.dll Download 0.1 MB

From workflow run

@volsa

volsa commented Sep 30, 2026

Copy link
Copy Markdown
Member Author

Closing in favor of carrying this fix in #1937, which routes the date and time builtins through the same replacement path.

@volsa volsa closed this Sep 30, 2026
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