Skip to content

fix(compiler): index and slice type parameters that can be strings - #554

Merged
paralin merged 1 commit into
s4wave:devfrom
cogentcore:fix/generic-string-index
Nov 2, 2026
Merged

paralin merged 1 commit into
s4wave:devfrom
cogentcore:fix/generic-string-index

Conversation

@rcoreilly

Copy link
Copy Markdown
Contributor

Indexing or slicing a value whose type is a type parameter with a string in its type set, such as T ~string | ~[]byte, used the slice helpers (arrayIndex, goSlice), which panic with "runtime error: index on unsupported type" when the value is a string. github.com/clipperhouse/uax29/v2/graphemes reads its data this way in Iterator.Next, so Cogent Code crashed on startup. Such values now use the existing indexStringOrBytes and sliceStringOrBytes helpers, as strings do.

The new compliance test generic_string_bytes_index indexes and slices strings, byte slices and a named string type through such type parameters, and fails without the change. go test ./compiler passes.

Indexing or slicing a value whose type is a type parameter with a string
in its type set, such as T ~string | ~[]byte, used the slice helpers,
which panicked with "index on unsupported type" when the value was a
string. This is how github.com/clipperhouse/uax29/v2/graphemes reads its
data, which Cogent Code reaches at startup. Such values now use the
indexStringOrBytes and sliceStringOrBytes helpers, as strings do.

Signed-off-by: Randall C. O'Reilly <randall@astera.org>
@paralin
paralin changed the base branch from master to dev November 2, 2026 22:37
@paralin
paralin merged commit d0d86e0 into s4wave:dev Nov 2, 2026
6 of 7 checks passed
@paralin

paralin commented Nov 2, 2026

Copy link
Copy Markdown
Member

Merged through dev so this PR retains its merged status, then landed on master as 96c8245 with the original author preserved. The amendment corrects three stale runtime tests: Go print spacing and clone methods for two registered struct fixtures. It also adds a purpose comment in the constraint inspection.

The generic string/byte compliance test passes from a clean archive without generated drift. All 76 tests in the three affected runtime files, TypeScript checking, the compiler and CLI build, and repository lint pass. Source review found no remaining defect; the independent review route was unavailable because its usage allowance was exhausted.

@rcoreilly
rcoreilly deleted the fix/generic-string-index branch November 4, 2026 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants