[Go] Fix bug where bytes
wasn't being imported when using --gen-onefile flag
#7706
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.
Fix for discussion in #7460.
Currently, the go generator resets the state of needed imports each time we process an enum or struct. This works fine when we want each enum and struct to be in their own files.
However, this will lead to an error if an
fbs
file is defined like the following.When processing the
Foo
table theneeds_bytes_import
will be set totrue
because of the key field. Then when processing theBar
table theneeds_bytes_import
will be reset tofalse
resulting in the final output file to not import thebytes
package.When we want all code to be in the same file we shouldn't reset the needed imports as we iterate through the structs/enums.
Additional Changes
For the lookup function I moved the declaration of
bKey
outside of the for loop to reduce unnecessary casting.