Skip to content

A subscript on a type with no index surface is an error, not a silent 0 (#1253) - #1257

Merged
ehartford merged 1 commit into
mainfrom
reject-index-on-unindexable
Sep 21, 2026
Merged

ehartford merged 1 commit into
mainfrom
reject-index-on-unindexable

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Fixes #1253.

check_index fell through to return 0 with no diagnostic for a runtime subscript on a struct that is neither a positional collection nor an IndexPlace implementor. Callers read 0 as "already reported", MirLower emitted an index projection on a struct local, and captures[1] rendered as "" inside an f-string; only a typed demand tripped the MIR validator.

The fallthrough now decides: a user IndexPlace type reads as its get returns (Sema records the type MirLower had to reconstruct from the signature, #1180); anything else is type 'T' cannot be indexed: it is not a positional collection and implements no IndexPlace. Type-level subscripts (Vec[i32] in a type position) are untouched. err_index_on_unindexable_struct pins it; the IndexPlace behavior tests are unchanged.

Battery (seed-driven, worktree): build, :fixpoint, :test, :test-green, :last-green all rc=0.

… 0 (#1253)

check_index fell through to `return 0` with no diagnostic for a runtime
subscript on a struct that is neither a positional collection nor an
IndexPlace implementor. Callers read 0 as "already reported", MirLower
emitted an index projection on a struct local, and `captures[1]` rendered
as "" inside an f-string; only a typed demand tripped the MIR validator.

The fallthrough now decides: a user IndexPlace type reads as its `get`
returns (Sema records the type MirLower had to reconstruct from the
signature, #1180); anything else is "type 'T' cannot be indexed: it is not
a positional collection and implements no IndexPlace". Type-level
subscripts (Vec[i32] in a type position) are untouched.
@ehartford
ehartford merged commit 0c66f96 into main Sep 21, 2026
4 of 5 checks passed
@ehartford
ehartford deleted the reject-index-on-unindexable branch September 24, 2026 16:57
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.

Indexing a struct with no index method is accepted by Sema: captures[1] prints "" in an f-string, invalid MIR when typed

1 participant