[GO] Fix support for enums with underscores and Unions with imported members (#5600)

* Fix Enum Stringer method when Enum has underscores

Fixes #5481

* Fix go package importing itself when Union has imported members.
This commit is contained in:
Tiago Silva
2019-11-26 20:25:36 +00:00
committed by Robert Winslow
parent c3c32ec942
commit 3c964e10ab
4 changed files with 91 additions and 91 deletions

View File

@@ -10,6 +10,36 @@ import (
MyGame__Example2 "MyGame/Example2"
)
type Any byte
const (
AnyNONE Any = 0
AnyMonster Any = 1
AnyTestSimpleTableWithEnum Any = 2
AnyMyGame_Example2_Monster Any = 3
)
var EnumNamesAny = map[Any]string{
AnyNONE: "NONE",
AnyMonster: "Monster",
AnyTestSimpleTableWithEnum: "TestSimpleTableWithEnum",
AnyMyGame_Example2_Monster: "MyGame_Example2_Monster",
}
var EnumValuesAny = map[string]Any{
"NONE": AnyNONE,
"Monster": AnyMonster,
"TestSimpleTableWithEnum": AnyTestSimpleTableWithEnum,
"MyGame_Example2_Monster": AnyMyGame_Example2_Monster,
}
func (v Any) String() string {
if s, ok := EnumNamesAny[v]; ok {
return s
}
return "Any(" + strconv.FormatInt(int64(v), 10) + ")"
}
type AnyT struct {
Type Any
Value interface{}
@@ -44,33 +74,3 @@ func AnyUnPack(t Any, table flatbuffers.Table) *AnyT {
}
return nil
}
type Any byte
const (
AnyNONE Any = 0
AnyMonster Any = 1
AnyTestSimpleTableWithEnum Any = 2
AnyMyGame_Example2_Monster Any = 3
)
var EnumNamesAny = map[Any]string{
AnyNONE: "NONE",
AnyMonster: "Monster",
AnyTestSimpleTableWithEnum: "TestSimpleTableWithEnum",
AnyMyGame_Example2_Monster: "MyGame_Example2_Monster",
}
var EnumValuesAny = map[string]Any{
"NONE": AnyNONE,
"Monster": AnyMonster,
"TestSimpleTableWithEnum": AnyTestSimpleTableWithEnum,
"MyGame_Example2_Monster": AnyMyGame_Example2_Monster,
}
func (v Any) String() string {
if s, ok := EnumNamesAny[v]; ok {
return s
}
return "Any(" + strconv.FormatInt(int64(v), 10) + ")"
}