{"record":{"id":"f07b30255b72e851","repo":"astral-sh/ruff","slug":"argument-index-should-be-valid-f07b30","errorCode":null,"errorMessage":"argument index should be valid","messagePattern":"argument index should be valid","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ty_python_semantic/src/types/call/bind.rs","lineNumber":1405,"sourceCode":"                env,\n                constraints,\n                call_arguments,\n                call_expression_tcx,\n                dataclass_field_specifiers,\n            );\n        }\n\n        // For intersection elements with at least one successful binding,\n        // filter out the failing bindings after deferred constructor checks.\n        for element in &mut self.elements {\n            element.retain_successful(db);\n        }\n\n        self.as_result(db)\n    }\n\n    /// Finalize the bindings after a provisional check, retaining only those that contribute\n    /// to the final call evaluation.\n    pub(crate) fn finalize_argument_inference(\n        &mut self,\n        db: &'db dyn Db,\n        env: &ProgramEnvironment<'db>,\n        call_arguments: &CallArguments<'_, 'db>,\n        dataclass_field_specifiers: &[Type<'db>],\n    ) -> Result<(), CallErrorKind> {\n        self.evaluate_known_cases(db, env, call_arguments, dataclass_field_specifiers);\n\n        for constructor in self.iter_constructor_items_mut() {\n            if constructor.discard_downstream_constructor(db, env)\n                && let Some(downstream) = constructor.downstream_constructor_mut()\n            {\n                let _ = downstream.finalize_argument_inference(\n                    db,\n                    env,\n                    call_arguments,\n                    dataclass_field_specifiers,","sourceCodeStart":1387,"sourceCodeEnd":1423,"githubUrl":"https://github.com/astral-sh/ruff/blob/15f3fe6b15a5f00172f34b0f542f8ea277f5a586/crates/ty_python_semantic/src/types/call/bind.rs#L1387-L1423","documentation":"CallableBinding::type_for_argument reads the inferred argument types at `argument_index` from the CallArguments captured for the call; every binding is expected to cover every argument index recorded at the call site. The expect is an index-bounds panic routed through CallArguments::argument_types.","triggerScenarios":"An argument_index beyond the number of recorded argument entries: a binding whose matching overloads reference a parameter position past the provided arguments (defaults or *args miscounting), or a binding replayed against a different call's arguments.","commonSituations":"Calls combining defaults, star-args, and overloaded signatures; stale bindings after an edit changes call arity during incremental checking.","solutions":["Minimize the call (overloads plus default/star arguments) and file a ty issue with the backtrace","As a contributor: check `argument_types(index)` for None and fall back to the default argument type instead of unwrapping","Verify the binding was not cached from an earlier iteration with different arity"],"exampleFix":"// before\nlet argument_types = call_arguments.argument_types(argument_index).expect(\"argument index should be valid\");\n\n// after\nlet Some(argument_types) = call_arguments.argument_types(argument_index) else {\n    return default_type;\n};","handlingStrategy":"validation","validationCode":"if let Some(argument_types) = call_arguments.argument_types(argument_index) {\n    // proceed with the inferred type\n} else {\n    // fall back to the default argument type\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate argument_index against the recorded arguments before reading inferred types","Ensure parameter/argument counting rules match between matching and reporting for defaults and star-args","Beware replaying bindings from a cached iteration after the call's arity changed"],"tags":["rust","ty","call-inference","index-out-of-bounds","panic"],"backgroundTag":"index-out-of-bounds","analyzedSha":"15f3fe6b15a5f00172f34b0f542f8ea277f5a586","analyzedAt":"2026-08-20T16:33:49.445Z","contentChangedAt":"2026-08-20T16:33:49.445Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}