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

checker: add error when initializing sumtype with struct as first type #22067

Merged
merged 3 commits into from
Aug 17, 2024

Conversation

felipensp
Copy link
Member

This PR add a checker error when initializing struct via sumtype as first variant type.

struct Node {
    parent &Node
    left &Node
    right &Node
}
type Sumtype = Node | int

fn main() {
    s := Sumtype{}
    dump(s)
}
bug.v:9:10: error: reference field `Node.parent` must be initialized
    7 | 
    8 | fn main() {
    9 |     s := Sumtype{}
      |          ~~~~~~~~~
   10 |     dump(s)
   11 | }
bug.v:9:10: error: reference field `Node.left` must be initialized
    7 | 
    8 | fn main() {
    9 |     s := Sumtype{}
      |          ~~~~~~~~~
   10 |     dump(s)
   11 | }
bug.v:9:10: error: reference field `Node.right` must be initialized
    7 | 
    8 | fn main() {
    9 |     s := Sumtype{}
      |          ~~~~~~~~~
   10 |     dump(s)
   11 | }

@felipensp felipensp marked this pull request as ready for review August 17, 2024 13:50
vlib/v/checker/struct.v Outdated Show resolved Hide resolved
Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work.

@spytheman spytheman merged commit d58cd9c into vlang:master Aug 17, 2024
73 checks passed
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.

2 participants