Skip to content

Refactor: error message for initializing multiple variables #1527

@abroooo

Description

@abroooo

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    InitializersbugSomething isn't workingvalidationcandidate for syntactic or semantic validation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions