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] Package imports itself when using unions with imported members #5602

Closed
tigrato opened this issue Nov 1, 2019 · 0 comments · Fixed by #5600
Closed

[Go] Package imports itself when using unions with imported members #5602

tigrato opened this issue Nov 1, 2019 · 0 comments · Fixed by #5600

Comments

@tigrato
Copy link
Contributor

tigrato commented Nov 1, 2019

Following #5591 a regression, introduced by #5339, was detected when generating Union with imported members.

Version: master - Linux

flatc  --go --gen-object-api --gen-all  --gen-mutable -o ./golang/ Example_fbb.fbs

Example_fbb.fbs:

include "./message/auth_messages.fbs";

namespace Example;

union MsgType {
Auth.ServerAuthReq
}  

table Root  
{  
  message:MsgType;
}

root_type Root;

auth_messages.fbs:

include "./data/common_data.fbs";

namespace Example.Auth;

table ServerAuthReq{
	selfType:Data.ServerType;	
}

common_data.fbs

namespace Example.Data;

enum ServerType : uint8 {
	None = 0,
	DatabaseServer,
	WebServer,
}

The output code in "MsgType.go" imports itself

package Example

import (
        "strconv"

        flatbuffers "github.com/google/flatbuffers/go"
        
        Example "Example"
        Example__Auth "Example/Auth"
)
....

This happens because GenNativeUnion is called before updating cur_name_space_ to the correct enum namespace which eventually is done at GenEnum.

if ((*it)->is_union && parser_.opts.generate_object_based_api) {
GenNativeUnion(**it, &enumcode);
GenNativeUnionPack(**it, &enumcode);
GenNativeUnionUnPack(**it, &enumcode);
needs_imports = true;
}
GenEnum(**it, &enumcode);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant