Skip to content

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

Closed

Description

@ehartford
let m = /(a)(b)/.captures("ab").unwrap()      // std.regex Captures: get(i) -> Option[Match], text(i) -> str; no index method
print(f"[{m[1]}] [{m[2]}] [{m.text(1)}]")   // prints: [] [] [a]   — no diagnostic
let x: i32 = m[1]                             // error: invalid MIR before codegen: use rvalue does not resolve to a concrete MIR type (place local=1 local_ty=96 projs=1 proj0_kind=1)

Sema lets m[1] through on a struct type that implements no indexing (Captures has no IndexPlace/get-by-int surface); MirLower emits an index projection on a struct local. The validator catches it only when the value is demanded at a concrete type; in an f-string the garbage projection renders as an empty string, silently. Expected: a Sema error at m[1] ("type Captures cannot be indexed") — the tool must not stay silent (a rewrite script keyed on c[1] silently rewrote nothing).

Found 2026-09-21 while scripting the #1249 fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions