Repository navigation
fix(compiler): accept arrays nested in generic type arguments - #24
Merged
Mister-Meeseeks merged 1 commit intoOct 19, 2026
Merged
Conversation
Pair[uint32, [][32]byte] failed Check with "array type was not declared before use" (CrocSwap#8). Type arguments are validated while instantiations are discovered, before any array type is declared, and typeArgRule only bounded a top-level array (or a pointer to one) without looking it up; arrays inside slices and pointers went to the lookup. Separately, arrays reached only through a field of an instantiated generic struct (V [][3]T, P *[4]T, Rows []Row[T]) were never declared. typeArgRule now descends through pointers and slices, keeping their rejections, and Check and the emitter declare the arrays a struct field holds through pointer, slice, map and array types before using it. Programs whose arrays are all written in source emit the same C: the frozen corpus, every example ELF and the reference ELFs are unchanged. Host differentials against native Go and SBF runs on fogo-v0 and solana-v3.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Pair[uint32, [][32]byte]fails Check witharray type was not declared before use. Two causes:typeArgRulebounded a top-level array without a lookup but sent everything else to one, so[32]bytepassed while[][32]byte,[]*[4]byte,[]Key,map[K][][4]byteandfunc([]*[4]byte)failedV [][3]TonBox[uint16]holds[3]uint16, which source may never write, so it failed even with the first cause fixedSolution
typeArgRuledescends through pointers and slices and bounds the arrays it reaches, keeping the pointer and slice rejections.An oversized or zero-length array inside a type argument now reports that rule's message instead of the declaration error. ERROR_CONTRACT changelog entry included.
Tests
TestGenericArrayTypeArgs*: two programs, 256 inputs each, native Go vs host C: the issue'sPair, a sorted[]Pairlookup, pointers, maps, named arrays, nested slices and generics, inferred and function-typed arguments, generic fields with arrays written nowhere else, bounds and nil traps.79cf25cnow compile and their C builds; storage rules still apply inside type arguments.examples/*gosvm projects, a fresh starter and the 4 reference ELFs build byte-identical to79cf25c.make testpasses apart from the knownTestStdlib*andTestFullSwapFactshost failures.Linked work
Closes #8. hyperlane-xyz/hyperlane-monorepo#9852 worked around it by wrapping the slice in a struct. Evidence:
results/compiler/2026-10-19-generic-array-type-args. Conflicts with the #7 fix on ERROR_CONTRACT and HANDOFF are mechanical.