-
-
Notifications
You must be signed in to change notification settings - Fork 758
Non-sense cyclic initialization #5149
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
Comments
This isn't a cycle, but it should report that And indeed, I get the expected errors when I compile with package scratch
main :: proc() {
View :: struct {
widget_make: proc(),
widget_handler: proc(),
}
// Top level statement
view_hex := View {
widget_make = proc() {
a := view_hex.widget_handler
},
}
}
And even with just
|
If tried this way, it is a cycle, and the error is correct. package scratch
View :: struct {
widget_make: proc(),
widget_handler: proc(),
}
// Top level statement
view_hex := View {
widget_make = proc() {
a := view_hex.widget_handler
},
}
main :: proc() {
} |
Wait, first of all, I talked about top level statement, so your first example is irrelevant. Second, why would cycle initialization be a correct error here if view_hex is a pointer looking at the assembly and you can do a relative memory read? The only way this is a correct error is if it breaks the paradigm, but at that point the question is if the paradigm is worth it, so you should answer to what are you exchanging for. |
You almost answered your own question there. But relative to what? You're pointing at the thing you're trying to initialize with the thing you're trying to initialize, so you can then read something slightly off to the side of it. |
It could conceivably have a clearer error message, like "Error: Trying to intialize a member of |
It can be done in two steps, and this is no longer a cycle. package scratch
import "core:fmt"
View :: struct {
widget_make: proc(),
widget_handler: proc(),
}
// Top level statement
view_hex: View
@(init)
init_view_hex :: proc() {
view_hex.widget_make = proc() {
a := view_hex.widget_handler
fmt.printfln("hello from widget_make: %p", a)
}
}
main :: proc() {
fmt.printfln("view_hex: %#v", view_hex)
view_hex.widget_make()
}
|
There is some sort of misunderstanding here. |
I've been programming in assembly for just shy of 40 years, thanks. All that aside, it's still a cycle in Odin for the reasons I've explained: You're initializing something with a reference to itself, which you need so you can take a relative address of it. That you can do this in asm, and even codegen the Odin equivalent in theory, doesn't make it valid Odin. |
So, yeah, you're just basically saying it's a problem raised by the language's paradigm, which can as it cannot be fine (this is another discussion). As simple as that. |
Context
Expected Behavior
view_hex
is a pointer and therefore it's an easy relative memory read, except if we're then breaking the paradigm (this is my doubt).Current Behavior
The text was updated successfully, but these errors were encountered: