Made declaring the underlying type of an enum mandatory.

This is a breaking change, anyone having schema files with enums
that do not specify a type will get a specialized error:

must specify the underlying integer type for this
enum (e.g. ': short', which was the default).

All of the samples and docs already had a type specified,
so hopefully this will affect very few people.

Bug: 15777205
Change-Id: I9b8d7c0827867f7efb6c217346db7e402695eff0
Tested: on Windows
parent b863ac01
...@@ -121,8 +121,7 @@ Define a sequence of named constants, each with a given value, or ...@@ -121,8 +121,7 @@ Define a sequence of named constants, each with a given value, or
increasing by one from the previous one. The default first value increasing by one from the previous one. The default first value
is `0`. As you can see in the enum declaration, you specify the underlying is `0`. As you can see in the enum declaration, you specify the underlying
integral type of the enum with `:` (in this case `byte`), which then determines integral type of the enum with `:` (in this case `byte`), which then determines
the type of any fields declared with this enum type. If you omit the underlying the type of any fields declared with this enum type.
type, it will be `short`.
### Unions ### Unions
......
...@@ -580,14 +580,15 @@ void Parser::ParseEnum(bool is_union) { ...@@ -580,14 +580,15 @@ void Parser::ParseEnum(bool is_union) {
if (is_union) { if (is_union) {
enum_def.underlying_type.base_type = BASE_TYPE_UTYPE; enum_def.underlying_type.base_type = BASE_TYPE_UTYPE;
enum_def.underlying_type.enum_def = &enum_def; enum_def.underlying_type.enum_def = &enum_def;
} else if (IsNext(':')) { } else {
// short is the default type for fields when you use enums, // Give specialized error message, since this type spec used to
// though people are encouraged to pick any integer type instead. // be optional in the first FlatBuffers release.
if (!IsNext(':')) Error("must specify the underlying integer type for this"
" enum (e.g. \': short\', which was the default).");
// Specify the integer type underlying this enum.
ParseType(enum_def.underlying_type); ParseType(enum_def.underlying_type);
if (!IsInteger(enum_def.underlying_type.base_type)) if (!IsInteger(enum_def.underlying_type.base_type))
Error("underlying enum type must be integral"); Error("underlying enum type must be integral");
} else {
enum_def.underlying_type.base_type = BASE_TYPE_SHORT;
} }
ParseMetaData(enum_def); ParseMetaData(enum_def);
Expect('{'); Expect('{');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment