P4098

Code

P4098

Message

RETURN(condition) conditional return requires choosing a dialect or –allow-conditional-return flag

This error occurs when a RETURN statement has a parenthesized condition (RETURN(condition)) without the --allow-conditional-return compiler flag.

The IEC 61131-3 standard grammar (Annex B) defines RETURN with no operand. The conditional form, which returns only when the condition is TRUE, is an extension.

A plain RETURN; is standard syntax and is always allowed.

Example

The following code will generate error P4098:

FUNCTION_BLOCK FB_Brake
VAR
    closed : BOOL;
END_VAR
    RETURN(closed);
END_FUNCTION_BLOCK

To fix this error, either write the condition as an IF:

FUNCTION_BLOCK FB_Brake
VAR
    closed : BOOL;
END_VAR
    IF closed THEN
        RETURN;
    END_IF;
END_FUNCTION_BLOCK

Or enable the extension:

Pass the --allow-conditional-return flag to enable it, or select a dialect that includes it. See Enabling Dialects and Features for the dialects and flags reference.

Think IronPLC is wrong about this?

If you believe this diagnostic is incorrect, open an issue on GitHub with a small sample that demonstrates the problem.