@couldCoerce - check if a type will coerce to another #3641
Labels
proposal
This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone
Uh oh!
There was an error while loading. Please reload this page.
Sometimes its safe to assign a variable to a similar type when the types don't exactly match. Such is the case with []const u8 and [3]u8. Checking if the types match fails, but it IS safe to assign a []const u8 variable to a value of type [3]u8. I would like to be able to test if [3]u8 can be coerced into a []const u8.
I ran into this issue trying to instantiate a tagged union from a runtime known tag, I check the union field type against
val: var
on line 82 of the linked gist. It would have been safe to assign the value, but because the types don't match control flow proceeds into the 'else unreachable' branch.A @couldCoerce method would eliminate the need for possibly complex type comparisons necessary to determine wether it is safe to perform this assignment.
Here is a condensed version of the gist:
The text was updated successfully, but these errors were encountered: