Skip to content

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

Merged
dbaileychess merged 3 commits intogoogle:masterfrom
le-michael:go-fix-import-gen-onefile
Dec 13, 2022
Merged

[Go] Fix bug where bytes wasn't being imported when using --gen-onefile flag#7706
dbaileychess merged 3 commits intogoogle:masterfrom
le-michael:go-fix-import-gen-onefile

Conversation

@le-michael
Copy link
Copy Markdown
Contributor

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