Skip to content

feat: Add fixed-size array support to the Go code generator#8974

Open
statxc wants to merge 3 commits intogoogle:masterfrom
statxc:go/fixed-size-array-support
Open

feat: Add fixed-size array support to the Go code generator#8974
statxc wants to merge 3 commits intogoogle:masterfrom
statxc:go/fixed-size-array-support

Conversation

@statxc
Copy link
Contributor

@statxc statxc commented Mar 11, 2026

Summary

Add fixed-size array support to the Go code generator, resolving a long-standing gap where Go was the only major language without support for the [type:length] struct field syntax (fixes #8417).

Changes

  • src/idl_parser.cpp: Add IDLOptions::kGo to the SupportsAdvancedArrayFeatures() allowlist.
  • src/idl_gen_go.cpp: Implement array-aware code generation for Go, including:
    • Indexed accessors and length methods for scalar and struct array fields
    • Scalar array mutators with bounds-checked index access
    • Builder body logic with correct reverse-order writing and nested struct flattening
    • Object API (Pack/UnPack) support using Go fixed-size arrays ([N]Type)
  • tests/go_arrays_test_test.go: Comprehensive test covering read, mutate, object API round-trip, and standalone struct creation against the arrays_test.fbs schema.
  • tests/GoArraysTest.sh: Test runner script following the same pattern as GoTest.sh.

Design

The implementation follows the same flattening strategy used by the Java and C# generators: nested struct array fields are expanded into per-sub-field slices in the Create function signature. For example, d:[NestedStruct:2] becomes d_a [][]int32, d_b []TestEnum, d_c [][]TestEnum, d_d [][]int64. Field offsets were verified against the Java reference output.

Test plan

  • go vet clean on generated code
  • All 4 new tests pass (TestArrayStructRead, TestArrayStructMutate, TestArrayStructObjectAPI, TestNestedStructStandalone)
  • Existing Go tests (GoTest.sh) still pass
  • flatc builds with no warnings

@statxc statxc requested a review from dbaileychess as a code owner March 11, 2026 17:38
@github-actions github-actions bot added golang c++ codegen Involving generating code from schema labels Mar 11, 2026
@statxc
Copy link
Contributor Author

statxc commented Mar 11, 2026

@jtdavis777 would you review this PR
thank you

@jtdavis777
Copy link
Collaborator

this is also a language I am not familiar with, and that I think we do not have an active maintainer of. so will take me some time

@statxc statxc force-pushed the go/fixed-size-array-support branch from 5a05954 to b9564b4 Compare March 11, 2026 18:16
@github-actions github-actions bot added the rust label Mar 11, 2026
@statxc
Copy link
Contributor Author

statxc commented Mar 16, 2026

Please any updates for me 🙏

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 golang rust

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Go] Fixed Size Array

2 participants