<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - SourceRange.__contains__ may return wrong result in python bindings"
href="http://llvm.org/bugs/show_bug.cgi?id=22243">22243</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>SourceRange.__contains__ may return wrong result in python bindings
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>libclang
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>tbao@outlook.com
</td>
</tr>
<tr>
<th>CC</th>
<td>klimek@google.com, llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>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</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>