rusty icon indicating copy to clipboard operation
rusty copied to clipboard

Validate types of for-loop

Open volsa opened this issue 1 year ago • 0 comments

Is your feature request related to a problem? Please describe. According to the norm, the start, end, counter and step values have to be of the same type meaning if one of them are e.g. INT every other value also has to be of type INT. However, validating this is currently hard because of integral promotion. Specifically because

VAR
  i : INT;
  x : INT;
END_VAR

FOR i := 0 TO x DO (* ... *) END_FOR
              ^ this is ok, `INT` will be returned when calling `annotations.get_type(...)`

FOR i := 0 TO (x + 1) DO (* ... *) END_FOR
              ^^^^^^^ this is NOT ok, `DINT` will be returned when calling `annotations.get_type(...)` 
                      breaking the `i.type == (x+1).type` requirement

Describe the solution you'd like Either don't be so strict and differ from the norm or find a solution for integral promotion

Additional context https://github.com/PLC-lang/rusty/pull/1103 had a validation for it, but because of integral promotion was removed later on

volsa avatar Mar 07 '24 13:03 volsa