rusty icon indicating copy to clipboard operation
rusty copied to clipboard

Refactor: error message for initializing multiple variables

Open abroooo opened this issue 3 months ago • 0 comments

Is your refactor request related to a problem? Please describe.

VAR
    a, b, c   :   INT   :=  (0, 1, 2);
END_VAR

This code is wrong and won't compile because IEC61131-3 doesn't support initializing multiple variables with a parenthesized list.

The error the compiler returns is:

Expected Struct-literal, got ExpressionList {
    expressions: [
        LiteralInteger {
            value: 0,
        },
        LiteralInteger {
            value: 1,
        },
        LiteralInteger {
            value: 2,
        },
    ],
} at: myfile.st

Describe the solution you'd like IMO this is not very helpful for the user. We should give the user more information on the problem. Maybe something like this would be more helpful:

Error: Multiple variable declarations require individual initializers
Found: a, b, c : INT := (0, 1, 2)
Expected format: a : INT := 0;
                    b : INT := 1;
                    c : INT := 2;

abroooo avatar Sep 19 '25 12:09 abroooo