You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The const evaluator strips parentheses while folding: evaluating a ParenExpression returns the evaluated inner expression without re-wrapping it (src/resolver/const_evaluator.rs:654). This was harmless before fix: const-fold array initializers before lowering into constructors #1826 because the folded statement was only consumed by codegen's literal generators, which don't care about parens.
Validation runs after lowering, so validate_array_of_structs (src/validation/array.rs) now sees the paren-stripped clone inside the generated constructor: a LiteralArray of bare Assignment nodes where it requires ParenExpression elements. Each element is flagged as E043, reported at the original source spans because the cloned nodes keep their locations.
Only the nested shape (struct → array of structs) is affected — the flat-array cases covered by #1826's test have no struct elements for the validator to check.
Candidate fixes: preserve the ParenExpression wrapper when the const evaluator folds struct initializers (paren-stripping is where the information is lost), or make the post-lowering validation tolerant of folded bare-Assignment elements.
Note
This issue was drafted by Claude on behalf of @ghaith.
Bug description
Initializing an array of structs that contain a nested array of structs produces a false-positive
E043:The inner struct initializers are wrapped in parentheses; the diagnostic is raised anyway and, being error-severity, blocks compilation.
Reproduction
plc --check repro.streportsE043on each inner(value := ...)element. Expected: compiles cleanly and prints(verified on the commit before the regression). Lit-ready version for the fix:
Root cause
Regressed by 1fc8dea (#1826). Three pieces interact:
folded_array_initializerincompiler/plc_lowering/src/initializer.rs).ParenExpressionreturns the evaluated inner expression without re-wrapping it (src/resolver/const_evaluator.rs:654). This was harmless before fix: const-fold array initializers before lowering into constructors #1826 because the folded statement was only consumed by codegen's literal generators, which don't care about parens.validate_array_of_structs(src/validation/array.rs) now sees the paren-stripped clone inside the generated constructor: aLiteralArrayof bareAssignmentnodes where it requiresParenExpressionelements. Each element is flagged asE043, reported at the original source spans because the cloned nodes keep their locations.Only the nested shape (struct → array of structs) is affected — the flat-array cases covered by #1826's test have no struct elements for the validator to check.
Candidate fixes: preserve the
ParenExpressionwrapper when the const evaluator folds struct initializers (paren-stripping is where the information is lost), or make the post-lowering validation tolerant of folded bare-Assignmentelements.Affected versions
mastersince 1fc8dea (2026-07-27)release/1.0.xis not affected (fix: const-fold array initializers before lowering into constructors #1826 was not backported)