Repository navigation
A subscript on a type with no index surface is an error, not a silent 0 (#1253) - #1257
Merged
Merged
Conversation
… 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.
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.
Fixes #1253.
check_indexfell through toreturn 0with no diagnostic for a runtime subscript on a struct that is neither a positional collection nor anIndexPlaceimplementor. Callers read 0 as "already reported", MirLower emitted an index projection on a struct local, andcaptures[1]rendered as "" inside an f-string; only a typed demand tripped the MIR validator.The fallthrough now decides: a user
IndexPlacetype reads as itsgetreturns (Sema records the type MirLower had to reconstruct from the signature, #1180); anything else istype '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_structpins it; the IndexPlace behavior tests are unchanged.Battery (seed-driven, worktree): build, :fixpoint, :test, :test-green, :last-green all rc=0.