[clang] [libclang/python] Fix bug in `SourceRange.__contains__`, add tests (PR #101802)
Jannick Kremer via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 7 10:59:55 PDT 2024
================
@@ -269,6 +269,14 @@ def _get_instantiation(self):
f = None
self._data = (f, int(l.value), int(c.value), int(o.value))
return self._data
+
+ def __le__(self, other):
+ if self.line < other.line:
+ return True
+ if self.line == other.line and self.column <= other.column:
+ return True
+ # when self.line > other.line
+ return False
----------------
DeinAlptraum wrote:
Note that this does not at all look at the location's file currently.
Imo returning `False` when `self.file != other.file` would be reasonable, but we can't do that if we want to use this in `SourceRange.__contains__`: that function allows this for half-open intervals, where `end.file` is `None`.
This is also consistent with the C interface's `SourceLocation::operator<=`: that also only takes into account the line and column number
https://github.com/llvm/llvm-project/pull/101802
More information about the cfe-commits
mailing list