[dart] fix toString() method generated for enum value#8260
[dart] fix toString() method generated for enum value#8260fawdlstty wants to merge 1 commit intogoogle:masterfrom
Conversation
| code += " switch (value) {\n"; | ||
| for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end(); ++it) { | ||
| auto &ev = **it; | ||
| const auto enum_var = namer_.Variant(ev); | ||
| code += " case " + enum_def.ToString(ev) + ": return \"" + enum_var + | ||
| "\";\n"; | ||
| } | ||
| code += " default: return \"\";\n"; | ||
| code += " }\n"; |
There was a problem hiding this comment.
The proposed format loses the information about the containing enum. What's the reasoning behind that proposal?
Also, if we should change this, i'd suggest aligning with dart Enum toString() instead:
enum Color { red, green, blue }
main() {
test('test', () {
expect(Color.red.toString(), 'Color.red');
});
}
Additionally, that would seem like a good time to switch to actual enums. Do you think we'd be able to do all that's needed to construct in the scope of flatbuffers if we use enhanced enum syntax?
There was a problem hiding this comment.
Update: I've looked into enhanced enums and it works fine, even with the default toString. I'll prep a PR.
There was a problem hiding this comment.
Current code already handles that and throws in such a case: throw StateError('Invalid value $value for bit flag enum Abc');. Whether that's the best thing to do is a different topic.
the behavior remains unchanged after the change to enhanced enums (#8313)
There was a problem hiding this comment.
See what others think. If the new PR is merged, I will close this PR
example fbs file:
before change:
after change: