Fix issue with anon union in generated code #69
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ok I still don't completely understand the root cause of this issue, but I documented my discovery in olbat/libgen#59. Basically in trying to generate bindings for
ruby.h
I was running into an issue where I was getting the errorBug: missing struct name
. I eventually tracked the error to this line and this line inruby/intern.h
where there is an anonymous union inside some generated code. In trying to generate a Crystal type for the anonymous union it threw an error because there was no name to assign the type to.So I did something simple that could probably be improved upon, and added a counter, removed the
raise
call that was causing things to break, and if all the other conditions inTypeMapper#check_anonymous_name
fail, it returns a generated nameanon_#{@anon_count += 1}
. So now instead of breaking it gives that union a crystal type nameAnon1
.Let me know if there is anything I can do to improve this, but I personally see it as an acceptable solution. This looks like an edge case that probably won't pop up much. I couldn't even figure out how to reproduce the bug for the specs.