Skip to content
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

Calling REF or ADR on a propagated constant variable yields cryptic codegen error #1371

Open
mhasel opened this issue Dec 6, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@mhasel
Copy link
Member

mhasel commented Dec 6, 2024

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).

@mhasel mhasel added the bug Something isn't working label Dec 6, 2024
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

No branches or pull requests

1 participant