-
-
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
cgen: make possible to initialize sumtype with default type (first variant) #22039
Conversation
You will have to change vfmt too, so that it would not sort the variants anymore. |
… | Variant0 | Variant22`
…er than ast.AnonFn)
b5c11f9
to
2dab3b9
Compare
And what happens if the first variant of the sumtype is a struct that has some field that is of pointer type? (the compiler should force explicit initialization) |
In this case it is zero'd initilization, just like |
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 about @StunxFS's comment, consider this: struct Node {
parent &Node
left &Node
right &Node
}
type Sumtype = Node | int
// n := Node{} /* will produce a compiler error, because the reference fields will be nil pointers */
s := Sumtype{} // currently, the compiler does not care, even though the node that will be created by default will be the same as `n` above
dump(s) producing (without any compiler messages):
|
i.e. the compiler currently acts on struct Node {
parent &Node = unsafe { nil }
left &Node = unsafe { nil }
right &Node = unsafe { nil }
} It is a second order effect. This PR already makes sure, that |
Fix #22030