PLC-lang / rusty

Structured Text Parser and LLVM Frontend
GNU Lesser General Public License v3.0
223 stars 53 forks source link

Inline Enum variants with the same name do not resolve correctly #1111

Closed riederm closed 8 months ago

riederm commented 8 months ago

When initializing an inline enum using one variant of that enum, the x will be resolved to one of the two. I think it is fair to say that such a line always wants x of the respective enum-type.

TYPE StateA: (Idle := 0); END_TYPE
TYPE StateB : (Idle := 0, Running := 1); END_TYPE

FUNCTION main : DINT
  VAR
      variant1 : (x := 1, y := 2) := x;
      variant2 : (x := 2, y := 2) := x;
  END_VAR

END_FUNCTION

Found during review of https://github.com/PLC-lang/rusty/pull/1098

tisis2 commented 8 months ago

in IEC61131-3 6.4.4.2.1 it is mentioned that it is an error if the literal has not enought information to resolve to a unique value. in my understanding this can be interpreted that this part should lead to an error

VAR
      variant1 : (x := 1, y := 2) := x;
      variant2 : (x := 2, y := 2) := x;
END_VAR

since you cannot address x in a uniqe way in the body of the POU

if the enum is a declared type like the StateA and StateB above you are allowed to do StateA#Idle to identify which Idle state you are using

riederm commented 8 months ago

alright then this needs to become a validation. I got the impression that it was not reported as a problem, but i'll re-check.

riederm commented 8 months ago

already covered by #1091, will close this one