feat: reject variables declared with a PROGRAM type (E142)#1802
Draft
volsa wants to merge 1 commit into
Draft
Conversation
Programs are singletons: the compiler allocates exactly one global instance per program, and calls by name operate on that instance. Declaring a variable of a program type created a detached copy of the singleton's state, which calls would mutate while the real instance never advances. IEC 61131-3 only allows program instantiation inside CONFIGURATION/RESOURCE declarations, which are not supported. Variable declarations (all VAR blocks, VAR_GLOBAL, struct members, and arrays) whose effective type resolves to a PROGRAM POU now report E142. Direct calls (`myProg(...)`) and member access (`myProg.out1`) on the program name keep working. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Build Artifacts🐧 Linux
From workflow run 🪟 Windows
From workflow run |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Declaring a variable whose type is a
PROGRAMis now a validation error (E142):Why
Programs are singletons — the compiler allocates exactly one global instance per program, and calling a program by name operates on that instance. A program-typed variable silently created a detached copy of the singleton's state: calls through it mutated the copy while the real program instance never advanced. IEC 61131-3 only allows program instantiation inside
CONFIGURATION/RESOURCE, which are not supported.Notes
VAR,VAR_INPUT,VAR_OUTPUT,VAR_IN_OUT,VAR_TEMP,VAR_GLOBAL), struct members, and arrays of a program type.myProg(in1 := 5);) and member access (x := myProg.out1;) on the program name keep working — both are pinned with tests.E142with documentation (plc explain E142).🤖 Generated with Claude Code