Attention

IronPLC implements many parts of the IEC 61131-3 standard and is working toward full Structured Text support. Key features still missing include arrays and structures. Try it out in the IronPLC Playground.

P2031

Code

P2031

Message

Dereference operator (^) requires a REF_TO type

This error occurs when the dereference operator (^) is applied to an expression that is not a REF_TO type. The dereference operator follows a reference to access the value it points to, and can only be used on reference types.

Example

The following code will generate error P2031:

PROGRAM Main
    VAR
        x : INT := 42;
        y : INT;
    END_VAR

    y := x^;  (* Error: x is INT, not REF_TO *)
END_PROGRAM

To fix this error, ensure the variable is declared as a reference type:

PROGRAM Main
    VAR
        x : INT := 42;
        xRef : REF_TO INT := REF(x);
        y : INT;
    END_VAR

    y := xRef^;  (* Correct: xRef is REF_TO INT *)
END_PROGRAM