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

Has* methods on messages ambiguous for union types. #55

Closed
abraithwaite opened this issue Nov 1, 2016 · 4 comments
Closed

Has* methods on messages ambiguous for union types. #55

abraithwaite opened this issue Nov 1, 2016 · 4 comments
Labels

Comments

@abraithwaite
Copy link

Just noticed this. If you have a union type in a struct and you check msg.Has* for the different union types, they'll both return true if only one is set.

From the generated code:

func (s Message) HasLog() bool {
    p, err := s.Struct.Ptr(1)
    return p.IsValid() || err != nil
}
func (s Message) HasRequest() bool {
    p, err := s.Struct.Ptr(1)
    return p.IsValid() || err != nil
}
@abraithwaite
Copy link
Author

Not sure if anything needs to be done about this. Maybe a little documentation is all.

@zombiezen zombiezen added the bug label Nov 1, 2016
@zombiezen
Copy link
Contributor

Hm. While in general the behavior of using the wrong union field is undefined, perhaps there should be more explicit checking. What does the C++ implementation do?

@zombiezen
Copy link
Contributor

C++ does do this check. It also makes assertions for every union member access that which matches.

@zombiezen
Copy link
Contributor

Forgot to mention: I opened #56 to add runtime assertions for other accessor methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants