Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions its/ruling/src/test/resources/expected/python-S4143.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,4 @@
'project:twisted-12.1.0/twisted/test/test_dirdbm.py':[
26,
],
'project:twisted-12.1.0/twisted/words/protocols/irc.py':[
2910,
],
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ private static CollectionWrite collectionWrite(AssignmentStatement assignment, E
if (collection.is(Kind.SLICE_EXPR, Kind.SUBSCRIPTION)) {
CollectionWrite nested = collectionWrite(assignment, collection);
if (nested != null) {
return new CollectionWrite(nested.collectionKey.nest(key), nested.leftBracket, rBracket, assignment);
return new CollectionWrite(nested.collectionKey.nest(key), nested.leftBracket, rBracket, assignment, collection);
}
}

if (collection instanceof HasSymbol) {
Symbol symbol = ((HasSymbol) collection).symbol();
if (symbol != null) {
CollectionKey collectionKey = new CollectionKey(symbol, key);
return new CollectionWrite(collectionKey, lBracket, rBracket, assignment);
return new CollectionWrite(collectionKey, lBracket, rBracket, assignment, collection);
}
}

Expand Down Expand Up @@ -163,8 +163,7 @@ private static void reportOverwrites(SubscriptionContext ctx, Map<CollectionKey,
CollectionWrite firstWrite = writes.get(0);
CollectionWrite secondWrite = writes.get(1);
AssignmentStatement assignment = secondWrite.assignment;
Expression lhs = lhs(assignment);
if (TreeUtils.hasDescendant(assignment.assignedValue(), t -> CheckUtils.areEquivalent(lhs, t))) {
if (TreeUtils.hasDescendant(assignment.assignedValue(), t -> CheckUtils.areEquivalent(firstWrite.collection, t))) {
return;
}
String message = String.format(
Expand Down Expand Up @@ -192,12 +191,14 @@ private static class CollectionWrite {
private final Token leftBracket;
private final Token rightBracket;
private final AssignmentStatement assignment;
private final Expression collection;

private CollectionWrite(CollectionKey collectionKey, Token leftBracket, Token rightBracket, AssignmentStatement assignment) {
private CollectionWrite(CollectionKey collectionKey, Token leftBracket, Token rightBracket, AssignmentStatement assignment, Expression collection) {
this.collectionKey = collectionKey;
this.leftBracket = leftBracket;
this.rightBracket = rightBracket;
this.assignment = assignment;
this.collection = collection;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,13 @@ def non_trivial_collections(f, obj1, obj2):
def valid_replacement(list1, foo, x):
list1["foo"] = foo(x)
list1["foo"] = list1["foo"].replace("a", "b")

def used_collection(list1):
list1[1] = 42
list1[1] = foo(list1[1])

list1[2] = 42
list1[2] = foo(list1)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you document the fact that the following snippet would now be a FN ?

    list[3] = 42
    list[3] = list[1] # FN


list[3] = 42
list[3] = list[1] # FN