P4014

Code

P4014

Message

Symbol declaration name is duplicated

This error occurs when a variable name is declared more than once in the same scope. A scope is a program, function, function block or method, counting every VAR, VAR_INPUT, VAR_OUTPUT and other block it contains, or the global scope, counting every VAR_GLOBAL block in the project wherever it sits.

The comparison is case-insensitive, like all IEC 61131-3 identifiers. Two declarations of one name in a scope would leave the compiler to pick one, and the other would never be read; the compiler rejects the program instead.

Example

The following code will generate error P4014:

PROGRAM main
  VAR_INPUT
    start : BOOL;
  END_VAR
  VAR
    start : INT;
  END_VAR
END_PROGRAM

start is declared as an input and again as a local variable of main.

To fix this error, remove one declaration or rename the variable:

PROGRAM main
  VAR_INPUT
    start : BOOL;
  END_VAR
  VAR
    startCount : INT;
  END_VAR
END_PROGRAM

Compiler-provided globals

When --allow-system-uptime-global is on, the compiler declares the globals __SYSTEM_UP_TIME and __SYSTEM_UP_LTIME itself. A VAR_GLOBAL that declares either name is reported with this error:

VAR_GLOBAL
  __SYSTEM_UP_TIME : TIME;
END_VAR

To read the compiler’s uptime value, remove the declaration; the name is available without one. To keep a variable of your own, rename it. Names beginning with __ are reserved for the compiler.

Scopes and hiding

This rule compares declarations within one scope only. Whether a variable in one scope may reuse the name of a variable in an enclosing scope is a separate question: a program may not reuse a global’s name (P4050), while a function, function block or method may, and the local declaration then hides the outer one. A VAR_EXTERNAL names a global rather than declaring a new variable, so it is not a duplicate of that global.

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.