Skip to content

Commit

Permalink
Use enum types in generated read/mutate methods for Go (#4978)
Browse files Browse the repository at this point in the history
  • Loading branch information
kostya-sh authored and aardappel committed Oct 8, 2018
1 parent 7c3c027 commit a4c362a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/idl_gen_go.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ static std::string GenGetter(const Type &type) {
case BASE_TYPE_STRING: return "rcv._tab.ByteVector";
case BASE_TYPE_UNION: return "rcv._tab.Union";
case BASE_TYPE_VECTOR: return GenGetter(type.VectorType());
default: return "rcv._tab.Get" + MakeCamel(GenTypeGet(type));
default: return "rcv._tab.Get" + MakeCamel(GenTypeBasic(type));
}
}

Expand Down Expand Up @@ -711,6 +711,9 @@ static std::string GenTypePointer(const Type &type) {
}

static std::string GenTypeGet(const Type &type) {
if (type.enum_def != nullptr && !type.enum_def->is_union) {
return GetEnumTypeName(*type.enum_def);
}
return IsScalar(type.base_type) ? GenTypeBasic(type) : GenTypePointer(type);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/MyGame/Example/Monster.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/MyGame/Example/TestSimpleTableWithEnum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/MyGame/Example/Vec3.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tests/go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ func CheckReadBuffer(buf []byte, offset flatbuffers.UOffsetT, fail func(string,
fail(FailString("name", "MyMonster", got))
}

if got := monster.Color(); example.ColorBlue != got {
fail(FailString("color", example.ColorBlue, got))
}

// initialize a Vec3 from Pos()
vec := new(example.Vec3)
vec = monster.Pos(vec)
Expand Down
4 changes: 2 additions & 2 deletions tests/namespace_test/NamespaceA/TableInFirstNS.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a4c362a

Please sign in to comment.