[clang] [libclang/python] Fix bug in `SourceRange.__contains__`, add tests (PR #101802)

Vlad Serebrennikov via cfe-commits cfe-commits at lists.llvm.org
Sat Aug 10 06:52:53 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:
----------------
Endilll wrote:

> and in order to have a clean implementation, we would like a SourceLocation.__le__ / SourceLOcation.__lt__ that is not file-sensitive

I'm against anything non file-sensitive, because that's buggy and is going to surprise everyone. I'm less concerned with cleanliness of implementation in the face of this concern.

At this point I'm even more concerned by amount of places that interpret raw encoding of `SourceLocation`, even though (in my understanding) `SourceManager` is the only entity that should do so. I'd like to hear from Aaron on Monday on this. After that it should be more clear how we should proceed on all three levels of our API.

https://github.com/llvm/llvm-project/pull/101802


More information about the cfe-commits mailing list