You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
csgui
changed the title
var-get should thrown a runtime error if variable does not exists
var-get should throw a runtime error if variable does not exist
Apr 17, 2024
@csgui found something AMAZING in link_get_variable_fn: the type of the returned variable varies depending on if the var exists or not. If it exists, the type is the type of the var. If not, it's an optional.
So in this case, we will need a horrible workaround, where we will have to check if the fetched variable has the same type as the computed return type:
if yes, we have to wrap both the var and the type in Optional to make it coherent,
if not, we have to change only the return type to Optional.
Actually,if not, we could just write a "None" on the first byte which will contain the result, and in the wasm function check the first byte to see if we runtime-error or not.
For now,
var-get
on an non-existing variable could lead to the generation of invalid Wasm code.To remedy this, there is an "easy enough" fix to write:
link_get_variable_fn
to write an optional Value to the memory;get-var
to unwrap the optional, and return a runtime error if it's none.The text was updated successfully, but these errors were encountered: