I only tested this in Rust (since that was easiest for me), but I imagine this would cause issues in other languages as well.
If I define an enum in a FlatBuffer Schema file that has more fields that the underlying integral type can store, it leads to compiler errors in Rust (that is, flatc generates Rust code without error, but that generated code will not compile).
A quick test case:
$ cargo new fb-enum-test && cd fb-enum-testflatbuffers crate to the project: $ echo 'flatbuffers = "0.5"' >> Cargo.tomlsrc/main.rs:#[path = "./too_many_enums_generated.rs"]
mod too_many_enums_generated;
too_many_enums.fbs, which looks like this (not using the literal ... field, but filling in all 257 fields):enum Foo: uint8 {
Field0,
Field1,
...
Field255,
Field256
}
$ flatc -r -o src too_many_enums.fbs && cargo buildThis last step will yield the following Rust compilation error:
error[E0081]: discriminant value `0` already exists
--> src/./too_many_enums_generated.rs:268:14
|
12 | Field0 = 0,
| - first use of `0`
...
268 | Field256 = 256,
| ^^^ enum already has `0`
Platform details:
flatc version:$ flatc --version
flatc version 1.10.0 (Oct 5 2018 07:47:40)
@tymcauley Looks like we need to update the schema parser -- this is upstream of the language ports. @aardappel ?
This should be fixed by #5265.
Sorry for losing track of this, you're right, this is now fixed, and results in a flatc error:
error: /path/to/too_many_enums.fbs:258: 13: error: enum value does not fit [0; 255]
$ flatc --version
flatc version 1.11.0
Thanks for the fix @vglavnyy!
Most helpful comment
This should be fixed by #5265.