alecthomas/participle

Union does not work for pointer type

itstarsun opened this issue · 3 comments

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

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

@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.