Skip to content

Initial values not generated with array of struct #1019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
volsa opened this issue Nov 16, 2023 · 1 comment · Fixed by #1020
Closed

Initial values not generated with array of struct #1019

volsa opened this issue Nov 16, 2023 · 1 comment · Fixed by #1020
Assignees
Labels
bug Something isn't working

Comments

@volsa
Copy link
Member

volsa commented Nov 16, 2023

Describe the bug
When skipping initialization for some struct fields, a codegen error pops up due to said skipped value not being generated. For example

TYPE STRUCT1 : STRUCT
    node    : DINT;
    myArr   : ARRAY[0..1] OF STRUCT2;
END_STRUCT END_TYPE

TYPE STRUCT2 : STRUCT
    x1  : INT;
    x2  : INT;
END_STRUCT END_TYPE

PROGRAM main
    VAR
        var_init1 : ARRAY[0..1] OF STRUCT1 := [
            (node := 0, myArr := [(x1 := 0)])
        ];
    END_VAR
END_PROGRAM

will yield the following error

error: Some initial values were not generated
Codegen Error: Compilation aborted due to previous errors

Similarly this will not work (myArr := [(x1 := 0, x2 := 1), (x1 := 2, x2 := 3)]).
When initializing x2 / node however, it seem to work i.e. (node := 0, myArr := [(x1 := 0, x2 := 0)]).

Additional context
This seems like a regression due to 5dac39d

@volsa volsa added the bug Something isn't working label Nov 16, 2023
@mhasel
Copy link
Member

mhasel commented Nov 17, 2023

looks similar to #932

@volsa volsa self-assigned this Nov 20, 2023
volsa added a commit that referenced this issue Nov 21, 2023
…ucts (#1020)

Fixes #1019

This commit adds a type-hint on struct field assignments when dealing with array of structs. For example given structs 
- `STRUCT1 { idx: DINT, arr: ARRAY[...] OF STRUCT2 }` and 
- `STRUCT2 { x: DINT, y: DINT }`
The following snippet `ARRAY[1..3] OF STRUCT1 := [(idx := 0, arr := [(x := 1)])];` will result in `idx := 0` having a type-hint on `STRUCT1` and `x := 1` on `STRUCT2`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants