-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
checker: add fntype casting validations #23872
base: master
Are you sure you want to change the base?
Conversation
Connected to Huly®: V_0.6-22276 |
type Foo = fn (bar string)
fn test_main() {
mut func := ?Foo(none)
dump(func)
} |
Thanks! |
This should not be allowed at all. We recently forced requiring nil instead of 0 for the same reason. |
We can do a warning for now (use nil instead of 0) |
No, it should be allowed in |
Why? |
Because there are cases (for example with -freestanding, you can write code that can then be booted on bare metal), when you write code, where you do know the actual address of a function (because it is an external requirement), and do want to cast it to a function pointer. Restricting what can be done in |
Then just use It's more clear this way too. V positions itself as a safe language. You can't cast numbers to functions in a safe language :) |
We are talking then about: I think that is very verbose for no gain at all. |
V itself does not do anything on its own. It is a language, not a person. You, however position it as a language, that I will not want to use for certain tasks, because of the verbosity and edge cases. Unsafe blocks are in V, to allow people to write unsafe code in them, not to make them jump through hoops to avoid weird quirks in the compiler. |
I've added V UI PR fix vlang/ui#599 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work @felipensp, thank you.
However, I will not merge it, since @medvednikov expressed another opinion, and he is ultimately the arbiter of what should happen with his language.
I do hope, that he will reconsider, but that is of course up to him.
Fix #23852