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] Enum namespaces not getting imported #5591

Closed
anthony-ozdemir opened this issue Oct 28, 2019 · 2 comments
Closed

[Go] Enum namespaces not getting imported #5591

anthony-ozdemir opened this issue Oct 28, 2019 · 2 comments

Comments

@anthony-ozdemir
Copy link
Contributor

GoLang issue.zip

Flatbuffer compiler: 1.11 - Windows

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

It looks like flatc is not generating correct namespaces for enums, I`m constantly getting "undefined: ServerType" error for the setup below:

  • data
    • common_data.fbs
  • message
    • auth_messages.fbs
  • 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,
}

Generate Go file for "ServerAuthReq.go" doesn`t import Example.Data ServerType enum, hence Golang compiler complains that ServerType cannot be found.

Normally it should generate the following code in "ServerAuthReq.go"

import (
	flatbuffers "github.com/google/flatbuffers/go"

        Example__Data "Example/Data"
)

...

func (rcv *ServerAuthReq) MutateSelfType(n Example__Data.ServerType) bool {
	return rcv._tab.MutateByteSlot(4, n)
}

but what we get instead is this:

import (
	flatbuffers "github.com/google/flatbuffers/go"
)

...

func (rcv *ServerAuthReq) MutateSelfType(n ServerType) bool {
	return rcv._tab.MutateByteSlot(4, n)
}

I`m also attaching an example file setup "GoLang issue.zip", just run the "generateFB.py" file on the root folder, it will create a folder named "golang" with the same problem.

Please note that this only happens for Enums, table namespaces are correctly generated and can be referred from other namespaces.

@anthony-ozdemir anthony-ozdemir changed the title [Go] Enum name spaces not getting imported [Go] Enum namespaces not getting imported Oct 28, 2019
@aardappel
Copy link
Collaborator

Not familiar with Go importing, but generally it is better for a language to refer to types with a full namespaced path to avoid these kinds of issues, regardless of imports. It may well be that the generator is outputting these types incorrectly.

@rw?

@tigrato
Copy link
Contributor

tigrato commented Nov 1, 2019

This issue was already fixed by #5406

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

No branches or pull requests

3 participants