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: clarify error message about using empty map literal to initialize structs #22534

Merged
merged 1 commit into from
Oct 15, 2024

Conversation

StunxFS
Copy link
Contributor

@StunxFS StunxFS commented Oct 15, 2024

This PR clarifies the error message about using empty map literal to initialize structs, in addition to that it prevents another error message from appearing when using empty map literal with anonymous structs.

Fix #22498.

$ cat main.v
struct AStructName {
        foo  int
        anon struct {
                bar int
        }
}

fn main() {
        s := AStructName{5, {}}
        println(s)
}
$ v main.v
main.v:9:22: error: `{}` cannot be used to initialize anonymous structs. Use `struct{}` instead.
    7 | 
    8 | fn main() {
    9 |     s := AStructName{5, {}}
      |                         ~~
   10 |     println(s)
   11 | }

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 fde9516 into vlang:master Oct 15, 2024
78 checks passed
@StunxFS StunxFS deleted the fix_anon_syntax branch October 15, 2024 20:07
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.

Confusing error message when trying to initialize an anonymous struct with {}
2 participants