Skip to content

[Dart] Fix issues in namespace_test#9103

Open
jakobkordez wants to merge 3 commits into
google:masterfrom
jakobkordez:fix/dart-namespace
Open

[Dart] Fix issues in namespace_test#9103
jakobkordez wants to merge 3 commits into
google:masterfrom
jakobkordez:fix/dart-namespace

Conversation

@jakobkordez
Copy link
Copy Markdown
Contributor

The Dart code generator was emitting invalid namespace qualifiers for enum and union types defined in nested namespaces. For example, it produced namespace_a.namespace_b.EnumInNestedNs (dot-separated) instead of the correct Dart import alias namespace_a_namespace_b.EnumInNestedNs, and omitted the namespace prefix entirely for union TypeId enums. This happened because GenDartTypeName had a separate code path for enums that constructed the namespace prefix manually instead of routing through MaybeWrapNamespace like every other named type.

Two further changes were required to make cross-namespace access work correctly:

_createOrNull was removed from enums — its leading underscore made it private in Dart, so it could not be called from generated code in a different file. Enum reading now uses the public .reader directly (e.g. Color.reader.vTableGet(...) with a typed default).
The per-field union switch dispatch was moved into a top-level _getXxxReader() function in the same file as the union enum, so tables in other namespaces simply call xxxType?.valueReader?.vTableGetNullable(...) instead of embedding a switch that references type names they may not have access to.

Commits c08fa85 and a71f417 were done to regenerate the namespace_test test that was failing. Commit 17e2ef3 is the actual fix and the files it affects.

@jakobkordez jakobkordez requested a review from dbaileychess as a code owner May 26, 2026 15:52
@github-actions github-actions Bot added python c++ codegen Involving generating code from schema dart labels May 26, 2026
@jakobkordez
Copy link
Copy Markdown
Contributor Author

@jtdavis777 This is the issue I was referring to in #9088

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 python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant