[LLVMbugs] [Bug 22243] New: SourceRange.__contains__ may return wrong result in python bindings
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Thu Jan 15 15:08:14 PST 2015
http://llvm.org/bugs/show_bug.cgi?id=22243
Bug ID: 22243
Summary: SourceRange.__contains__ may return wrong result in
python bindings
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: libclang
Assignee: unassignedclangbugs at nondot.org
Reporter: tbao at outlook.com
CC: klimek at google.com, llvmbugs at cs.uiuc.edu
Classification: Unclassified
The function tests if a given location is inside the represented range, but it
may give wrong result when the given location is on the same line with the
current one-line range.
For example,
tu = ...
extent = tu.get_extent('test.c', ((1, 1), (1, 14)))
location = tu.get_location('test.c', (1, 20))
print location
print extent
print location in extent
It gives:
<SourceLocation file 'test.c', line 1, column 20>
<SourceRange start <SourceLocation file 'test.c', line 1, column 1>, end
<SourceLocation file 'test.c', line 1, column 14>>
True ### should be a False ###
It's due to a missing condition in SourceRange.__contains__ in cindex.py. And
here's a simple fix.
def __contains__(self, other):
...
# same file, in between lines
if self.start.line < other.line < self.end.line:
return True
+ # same file, same line
+ elif self.start.line == other.line == self.end.line:
+ if self.start.column <= other.column <= self.end.column:
+ return True
elif self.start.line == other.line:
# same file first line
if self.start.column <= other.column:
return True
elif other.line == self.end.line:
# same file last line
if other.column <= self.end.column:
return True
return False
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150115/6c506b97/attachment.html>
More information about the llvm-bugs
mailing list