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

Union does not work for pointer type #255

Closed
itstarsun opened this issue Aug 6, 2022 · 3 comments
Closed

Union does not work for pointer type #255

itstarsun opened this issue Aug 6, 2022 · 3 comments

Comments

@itstarsun
Copy link

https://go.dev/play/p/CWC44DlcCl5

@alecthomas
Copy link
Owner

Ah yes, interesting. I have a fix half done, will get it in today hopefully.

@alecthomas
Copy link
Owner

Tagged v2.0.0-beta.5 with the fix.

@petee-d
Copy link
Contributor

petee-d commented Dec 27, 2022

@alecthomas while making coverage for this in #213, I discovered this fix wasn't correct. 49f4822e#diff-5bc2d8471b75bfdf044ca005bc151f75b27c820ab857ef639ffe1124405c3c47R114 (nodes.go:114) - vals always has length 0 (no match) or 1 (match, will be the result of strct.Parse, a single struct value). There is no correlation between the indexes of vals and u.members. This fix ends up only looking at the first union option and makes either all the options pointers, or none.

To see the bug in action, try modifying TestParserWithUnion. In the participle.Union option, change AMember2{} to (*AMember2)(nil) - it changes nothing. Or make just AMember1 into a pointer - then it uses pointers for both of them.

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

No branches or pull requests

3 participants