bit-access on pointers will panic without error/validation
We are missing validations for the following examples, all of which end either in an unreachable or panic.
For regular pointer variables, I don't think bit-access makes much sense, but what about structs etc.? In some ST dialects/implementations it is possible to directly bit-access into a struct, but I guess the structs in these variants are packed? Should we also support this or just return an error and abort codegen?
TYPE struct_t : STRUCT
field : DINT;
END_STRUCT END_TYPE
FUNCTION_BLOCK fb_t
END_FUNCTION_BLOCK
PROGRAM mainProg
VAR
st : struct_t;
fb : fb_t;
ptr : REF_TO DINT;
END_VAR
// None of these are currently validated
st.%X1; // hits unreachable in cast_if_needed
fb.%X1; // hits unreachable in cast_if_needed
ptr.%X1; // panics in Inkwell
END_PROGRAM
Has this been fixed? I'm unable to reproduce on the current master
Looks like a validation for this has been added with #951. That fixes the issue of hitting unreachables/panics, but we are still unable to directly bit-access into structs, so I guess this is now more of a discussion of whether or not we want to support that functionality.
Updated example:
TYPE struct_t : STRUCT
field : DINT;
END_STRUCT END_TYPE
PROGRAM mainProg
VAR
st : struct_t := (field := 2);
END_VAR
st.%X1; // should this return the second bit of `st.field`, i.e. 1?
END_PROGRAM
It might make sense to close this issue and open a new one for this use-case?