Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check if a procedure signature is similar enough before allowing a cast #4240

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

laytan
Copy link
Collaborator

@laytan laytan commented Sep 14, 2024

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

@laytan
Copy link
Collaborator Author

laytan commented Sep 14, 2024

If I'm told this will be merged I can fix the CI failures

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant