rusty
rusty copied to clipboard
Calling `REF` or `ADR` on a propagated constant variable yields cryptic codegen error
When trying to compile the following snippet:
VAR_GLOBAL CONSTANT
x: DINT := 4;
END_VAR
FUNCTION main
VAR
y : REF_TO DINT;
END_VAR
y := REF(x);
END_FUNCTION
the compiler will fail during codegen with the following error:
error[E071]: ()
┌─ target/demo.st:9:14
│
9 │ y := REF(x);
│ ^ ()
Compilation aborted due to previous errors.
Hint: You can use `plc explain <ErrorCode>` for more information
This is probably due to the constant x's value being folded into each occurance, resulting in the actual REF call to be y := REF(4).