Skip to content

Conversation

@insertjokehere
Copy link
Contributor

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

@github-actions github-actions bot added c++ codegen Involving generating code from schema dart labels Apr 19, 2024
@insertjokehere insertjokehere force-pushed the 8052-enum-name-conflict branch from cf9549d to 1b39351 Compare April 19, 2024 03:59
Copy link
Contributor

@vaind vaind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution.

This is quite a breaking change - it would break anyone accessing these properties. Instead, I'd suggest changing the field name in case it conflicts, which would not break anyone because they couldn't have used that name anyway. That is what we do for conflicts with reserved keywords too (see uses of namer_).

…rated classes

Fixes google#8052

The Dart code generated for enums includes class properties called 'value', 'values', 'minValue' and 'maxValue'. If the Flatbuffer schema includes enums with these values, the generated code will be invalid. This modifies the Dart generator to rename enum properties if they will conflict with these names (as well as the existing rules to avoid conflicts with Dart keywords)
@insertjokehere insertjokehere force-pushed the 8052-enum-name-conflict branch 2 times, most recently from 28f0190 to 8d91a4f Compare August 16, 2024 02:07
@insertjokehere
Copy link
Contributor Author

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.

@insertjokehere insertjokehere requested a review from vaind August 16, 2024 02:13
@github-actions
Copy link
Contributor

This pull request is stale because it has been open 6 months with no activity. Please comment or label not-stale, or this will be closed in 14 days.

@github-actions github-actions bot added the stale label Feb 14, 2025
@github-actions
Copy link
Contributor

This pull request was automatically closed due to no activity for 6 months plus the 14 day notice period.

@github-actions github-actions bot closed this Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ codegen Involving generating code from schema dart stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Dart, master] Enum named "value" causes variable name conflict

2 participants