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

[Go] Fix bug where bytes wasn't being imported when using --gen-onefile flag #7706

Merged
merged 3 commits into from
Dec 13, 2022

Conversation

le-michael
Copy link
Collaborator

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.

namespace example;

table Foo {
  name: string (key);
}

table Bar {
  id: int;
}

When processing the Foo table the needs_bytes_import will be set to true because of the key field. Then when processing the Bar table the needs_bytes_import will be reset to false resulting in the final output file to not import the bytes 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.

@github-actions github-actions bot added c++ codegen Involving generating code from schema golang labels Dec 11, 2022
src/idl_gen_go.cpp Outdated Show resolved Hide resolved
src/idl_gen_go.cpp Outdated Show resolved Hide resolved
@dbaileychess dbaileychess merged commit e1a2f68 into google:master Dec 13, 2022
sunwen18 pushed a commit to sunwen18/flatbuffers that referenced this pull request Dec 25, 2022
…file flag (google#7706)

* Fix bug one file import bug

* Create reset import function and add braces
jochenparm pushed a commit to jochenparm/flatbuffers that referenced this pull request Oct 29, 2024
…file flag (google#7706)

* Fix bug one file import bug

* Create reset import function and add braces
jochenparm pushed a commit to jochenparm/flatbuffers that referenced this pull request Oct 29, 2024
…file flag (google#7706)

* Fix bug one file import bug

* Create reset import function and add braces
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ codegen Involving generating code from schema golang
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants