{"record":{"id":"fced2ed7cb2ebf00","repo":"mono/mono","slug":"must-supply-a-non-negative-int","errorCode":null,"errorMessage":"Must supply a non-negative int.","messagePattern":"Must supply a non-negative int\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"mono/tools/offsets-tool/clang/cindex.py","lineNumber":2210,"sourceCode":"\n        The returned object is iterable and indexable. Each item in the\n        container is a Type instance.\n        \"\"\"\n        class ArgumentsIterator(collections_abc.Sequence):\n            def __init__(self, parent):\n                self.parent = parent\n                self.length = None\n\n            def __len__(self):\n                if self.length is None:\n                    self.length = conf.lib.clang_getNumArgTypes(self.parent)\n\n                return self.length\n\n            def __getitem__(self, key):\n                # FIXME Support slice objects.\n                if not isinstance(key, int):\n                    raise TypeError(\"Must supply a non-negative int.\")\n\n                if key < 0:\n                    raise IndexError(\"Only non-negative indexes are accepted.\")\n\n                if key >= len(self):\n                    raise IndexError(\"Index greater than container length: \"\n                                     \"%d > %d\" % ( key, len(self) ))\n\n                result = conf.lib.clang_getArgType(self.parent, key)\n                if result.kind == TypeKind.INVALID:\n                    raise IndexError(\"Argument could not be retrieved.\")\n\n                return result\n\n        assert self.kind == TypeKind.FUNCTIONPROTO\n        return ArgumentsIterator(self)\n\n    @property","sourceCodeStart":2192,"sourceCodeEnd":2228,"githubUrl":"https://github.com/mono/mono/blob/0f53e9e151d92944cacab3e24ac359410c606df6/mono/tools/offsets-tool/clang/cindex.py#L2192-L2228","documentation":"Raised by ArgumentsIterator.__getitem__ when the indexing key is not an int. The function-argument-type iterator only supports integer indexing; a non-int key (slice, str, None) hits the first guard before any bounds checks and raises TypeError. The inline FIXME notes slice support is intentionally unimplemented.","triggerScenarios":"Indexing a function Type's argument iterator with anything other than an int — e.g. func_type.argument_types[0:2] (slice), func_type.argument_types['name'], or iterating with a non-integer accessor. The 'Must supply a non-negative int.' guard fires before the negative/out-of-range checks.","commonSituations":"Treating the iterator like a list and using slice syntax expecting a sub-list. Passing a numpy integer or other int-like object whose type is not literally int (isinstance(np.int64(0), int) is False). Scripting argument traversal with a loop variable that is accidentally a string.","solutions":["Index with a plain Python int (0 <= i < len(iterator)); iterate via 'for i in range(len(...))' or enumerate.","If you need a sub-range, build it manually: [iterator[i] for i in range(start, end)].","If holding a numpy/typed integer, cast with int(...) before indexing.","Avoid slice syntax until the FIXME is resolved upstream."],"exampleFix":"# before\nargs = func_type.argument_types[0:2]  # TypeError: Must supply a non-negative int.\n\n# after\nit = func_type.argument_types\nargs = [it[i] for i in range(0, min(2, len(it)))]","handlingStrategy":"type-guard","validationCode":"def arg_at(it, i):\n    if not isinstance(i, int): raise TypeError('index must be int')\n    return it[i]","typeGuard":"def isIntIndex(k): return isinstance(k, int) and not isinstance(k, bool)","tryCatchPattern":null,"preventionTips":["Index the iterator only with plain ints from range(len(...)).","Never use slice syntax (unsupported, per the FIXME).","Cast numpy/typed ints with int(...) first."],"tags":["libclang","iterator","indexing","type-guard","cindex"],"backgroundTag":null,"analyzedSha":"0f53e9e151d92944cacab3e24ac359410c606df6","analyzedAt":"2026-08-13T18:54:37.190Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}