Fixed nondeterministic ordering in union types, added test data (PY-3496, CR-PY-170)

This commit is contained in:
Andrey Vlasovskikh
2011-08-09 21:16:44 +04:00
parent 577e716856
commit 694dadf51a
3 changed files with 9 additions and 14 deletions

View File

@@ -33,21 +33,9 @@ public class PyDefUseUtil {
throw new InstructionNotFoundException();
}
final boolean[] visited = new boolean[instructions.length];
final Collection<PyElement> result = new HashSet<PyElement>();
final Collection<PyElement> result = new LinkedHashSet<PyElement>();
getLatestDefs(var, instructions, instr, visited, result);
final List<PyElement> sortedResult = new ArrayList<PyElement>();
sortedResult.addAll(result);
Collections.sort(sortedResult, new Comparator<PyElement>() {
@Override
public int compare(PyElement e1, PyElement e2) {
final String n1 = e1.getName();
if (n1 != null) {
return n1.compareTo(e2.getName());
}
return 0;
}
});
return sortedResult.toArray(new PyElement[sortedResult.size()]);
return result.toArray(new PyElement[result.size()]);
}
private static void getLatestDefs(final PyElement var,

View File

@@ -0,0 +1 @@
<html><body><small>Assigned to <code>y</code><br></small><code><br>Inferred&nbsp;type:&nbsp;one&nbsp;of&nbsp;(str,&nbsp;int)</code></body></html>

View File

@@ -0,0 +1,6 @@
def f(x):
if x:
y = 1
else:
y = 'foo'
return <the_ref>y