{"record":{"id":"85c37108a96daf74","repo":"astral-sh/ruff","slug":"argument-index-should-be-valid","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/arguments.rs","lineNumber":217,"sourceCode":"    pub(crate) fn is_variadic(&self, index: usize) -> bool {\n        self.items.get(index).is_some_and(|argument| {\n            matches!(argument.argument, Argument::Variadic | Argument::Keywords)\n        })\n    }\n\n    pub(crate) fn argument_types(&self, index: usize) -> Option<&CallArgumentTypes<'db>> {\n        self.items.get(index).map(|item| &item.types)\n    }\n\n    pub(crate) fn insert_type(\n        &mut self,\n        index: usize,\n        tcx: impl Into<TypeContext<'db>>,\n        ty: Type<'db>,\n    ) {\n        self.items\n            .get_mut(index)\n            .expect(\"argument index should be valid\")\n            .types\n            .insert(tcx, ty);\n    }\n\n    pub(crate) fn clear_types(&mut self, index: usize) {\n        self.items\n            .get_mut(index)\n            .expect(\"argument index should be valid\")\n            .types = CallArgumentTypes::default();\n    }\n\n    pub(crate) fn iter_types(&self) -> impl Iterator<Item = &CallArgumentTypes<'db>> + '_ {\n        self.items.iter().map(|item| &item.types)\n    }\n\n    /// Returns `true` if the inferred types are equal for the given set of argument indices.\n    pub(crate) fn inferred_types_equal_at(&self, other: &Self, argument_indices: &[usize]) -> bool {\n        argument_indices.iter().all(|&index| {","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/astral-sh/ruff/blob/d1087a4b9e03d253a88703f34e0869ee4b805456/crates/ty_python_semantic/src/types/call/arguments.rs#L199-L235","documentation":"CallArguments::insert_type stores the inferred type for the argument at `index`; the items vector holds one entry per call argument, so the index must have been produced against the same arguments list. The expect is an index-bounds panic: the passed index is >= items.len().","triggerScenarios":"Replaying an argument index captured in an earlier inference pass after the arguments list changed (fixpoint re-inference, mutation between passes), or a mismatch between the number of parameters matched and the number of arguments actually recorded for the call.","commonSituations":"Nondeterministic inference order across fixpoint iterations; calls mixing defaults, *args/**kwargs, and overloads where the matcher's index arithmetic drifts from the recorded arguments.","solutions":["Minimize the call expression (defaults/star-args/overloads are common ingredients) and file a ty issue with the backtrace","As a contributor: derive indices and argument-type writes within the same pass, or use `get_mut` and skip out-of-range indices instead of unwrapping","Check for nondeterminism by re-running the file several times; intermittent behavior points at iteration-order instability"],"exampleFix":"// before\nself.items.get_mut(index).expect(\"argument index should be valid\").types.insert(tcx, ty);\n\n// after\nif let Some(item) = self.items.get_mut(index) {\n    item.types.insert(tcx, ty);\n}","handlingStrategy":"validation","validationCode":"debug_assert!(index < arguments.items_len(), \"stale argument index\");\nif index < arguments.items_len() {\n    arguments.insert_type(index, tcx, ty);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep argument indices and their reads/writes within one inference pass; recompute indices after mutating the arguments list","Prefer get/get_mut with explicit skip over unwrap for replayed indices","Re-run a file repeatedly in CI samples to catch intermittent ordering bugs early"],"tags":["rust","ty","call-inference","index-out-of-bounds","panic"],"backgroundTag":"index-out-of-bounds","analyzedSha":"d1087a4b9e03d253a88703f34e0869ee4b805456","analyzedAt":"2026-08-20T16:33:49.445Z","contentChangedAt":"2026-08-20T16:33:49.445Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}