Passing self as a parameter to a function or method can result in IL that throws an invalid program exception or otherwise fails at runtime, if self is a struct.
The issue is that ldarg.0 loads the address of the current instance not that value:
struct THING is
init() is
// the string interpolator expects self to be passed by value here
// but we wrongly pass a reference to `self` via `ldarg.0`
IO.Std.write_line("{self}");
si
to_string() -> string => "a thing";
si
The fix is to generate an appropriately type ldobj to load the value from the reference, where needed
Passing
self
as a parameter to a function or method can result in IL that throws an invalid program exception or otherwise fails at runtime, ifself
is a struct.The issue is that
ldarg.0
loads the address of the current instance not that value:The fix is to generate an appropriately type
ldobj
to load the value from the reference, where needed