[clang] [libclang/python] Fix bug in `SourceRange.__contains__`, add tests (PR #101802)
Jannick Kremer via cfe-commits
cfe-commits at lists.llvm.org
Sat Aug 10 06:17:38 PDT 2024
================
@@ -386,6 +386,10 @@ def __contains__(self, other):
# same file, in between lines
if self.start.line < other.line < self.end.line:
return True
+ # between columns in one-liner range
+ elif self.start.line == other.line == self.end.line:
----------------
DeinAlptraum wrote:
Okay, that was my mistake: when testing this, I created two separate TUs for the two files, and _that_ is apparently where it's sensitive. So no issue on the C-side here after al.
Going back to the Python bindings: we are now left with a pre-existing `SourceLocation.__eq__` that _is_ file-sensitive, and in order to have a clean implementation, we would like a `SourceLocation.__le__` / `SourceLOcation.__lt__` that is _not_ file-sensitive, so it can be used for `SourceRange.__contains__`.
Exposing something like this would be ugly due to inconsistency. So I guess it would be the easiest to implement such an `operator<=` function just locally inside `SourceRange.__contains__` to simplify the logic there, and not expose any new functionality at all. What do you think?
https://github.com/llvm/llvm-project/pull/101802
More information about the cfe-commits
mailing list