google / flatbuffers

FlatBuffers: Memory Efficient Serialization Library
https://flatbuffers.dev/
Apache License 2.0
23.16k stars 3.23k forks source link

Adjust the code generated for enum types to avoid conflicting with names not reserved by the Flatbuffers IDL #8285

Open insertjokehere opened 5 months ago

insertjokehere commented 5 months ago

Fixes #8052

The Flatbuffers IDL allows for enums to have values called value, values, minValue or maxValue, but if these names are used for values in an enum, the generated Dart code won't compile.

This modifies the Dart generator to use $value, $values, $minValue and $maxValue instead, so that valid Flatbuffer schemas can be used with Dart

insertjokehere commented 1 month ago

Sorry for the delay getting back to this - it slipped way down my list for a bit.

Your criticism about the degree to which this was a breaking change is valid - I've reworked this to set up a second Namer instance with an extended list of "keywords" that it needs to escape. C++ isn't a language I use very much, so I'm not sure if the way I'm doing this is correct/idiomatic, but it Works For Me. I've also added a test to ensure that we generate valid code for enums that use the reserved words as values.

Thanks.