Odin
Odin copied to clipboard
check if a procedure signature is similar enough before allowing a cast
Note: consider this a proposal that contains an implementation.
This PR changes the way casting between two procedures is checked and will only allow casts for "similar enough" procedure signatures and otherwise suggest a transmute instead.
For example, this is allowed:
A :: distinct int
B :: distinct int
foo :: proc(a: A) {}
foo_b := cast(proc(b: B))foo
But this won't be allowed:
foo :: proc(a: u8) {}
foo_b := cast(proc(a: u16))foo
test.odin(10:29) Error: Cannot cast 'foo' as 'proc(u16)' from 'proc(u8)'
foo_b := cast(proc(a: u16))foo
^~^
Suggestion: the procedure types are not similar enough to allow a safe cast, you may use 'transmute' to do an unsafe cast