Jump to content

Making Coerce To Type a little safer


Recommended Posts

Posted (edited)

Coerce to type is useful for getting nontypedeffed data into a typedef form but there's a small problem of type safety. For example, if you try and coerce an I32 to a U8, the value will silently wrap without even so much as a coercion dot.

But in recent versions of LV, we have something to ensure a little safety— "Assert Structural Type Match"

And fortunately, for this use case, it's not so sensitive as to disallow typedeffed data from matching it's plain counterpart so we can use it to enforce a runtime error if someone wires an I32 up. And, to make this new function more convenient, you can wrap it up in a VIM. 

TypeDef Snippet.png

Edited by infinitenothing
Posted (edited)

Why would there be a coercion dot on the input of a function whose name implies it is being used for a coercion?  The fact that a coercion is taking place is obvious due to the presence of the node for doing the coercion......

That aside, I think the addition of type safety would be a welcome additional function.  But does your function allow us to coerce a U8 to a U16 for example?  Here no data is lost and it should be completely safe (under the assumption the programmer knows what they are doing).

Edited by shoneill
spelling
Posted

No, it will break if you try and convert a U8 into U16 so it's a little conservative in that manner.  The programmer would be expected to do the U8 to U16 upstream to "get rid of the broken arrow". It would be really cool if there was a way to allow all the "safe cooerces".

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.