Skip to content

[Kotlin] Fix required union accessors - #9219

Open
mjmahone wants to merge 1 commit into
google:masterfrom
mjmahone:fix-kotlin-required-union
Open

[Kotlin] Fix required union accessors#9219
mjmahone wants to merge 1 commit into
google:masterfrom
mjmahone:fix-kotlin-required-union

Conversation

@mjmahone

@mjmahone mjmahone commented Sep 2, 2026

Copy link
Copy Markdown

Summary

  • Throw when a required union field is absent.
  • Preserve null for optional union fields.
  • Add a focused Kotlin code-generation regression test.

Why

Required union accessors have a non-null return type, but their missing-field branch currently returns null. As a result, schemas containing required unions generate Kotlin that does not compile. The new behavior matches the existing handling for required string accessors.

Test

  • Compiled the complete flatc source with Clang.
  • Ran the focused KotlinTests.RequiredUnion regression test.
  • Verified that generated Kotlin contains a non-null Table return type and throws AssertionError when the field offset is absent.

@github-actions github-actions Bot added python c++ codegen Involving generating code from schema kotlin labels Sep 2, 2026
@google-cla

google-cla Bot commented Sep 2, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Required union accessors have non-null return types, but their missing-field branch currently returns null. This produces Kotlin code that does not compile.

Throw an AssertionError for absent required unions, matching required string accessors, and add a focused code-generation regression test.
@mjmahone
mjmahone force-pushed the fix-kotlin-required-union branch from 2d721ee to 60111ec Compare September 2, 2026 20:05
@mjmahone
mjmahone marked this pull request as ready for review September 2, 2026 20:19
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 kotlin python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant