Skip to content

Commit

Permalink
simplify union interface
Browse files Browse the repository at this point in the history
  • Loading branch information
yinwang0 committed Apr 30, 2022
1 parent 4cb9d6b commit 301d518
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
13 changes: 6 additions & 7 deletions src/main/java/org/yinwang/pysonar/types/UnionType.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;

public class UnionType extends Type {
Expand Down Expand Up @@ -112,7 +107,7 @@ public static Type union(@NotNull Type u, @NotNull Type v) {

@NotNull
public static Type union(@NotNull TupleType u, @NotNull TupleType v) {
List<Type> types = new ArrayList<Type>();
List<Type> types = new ArrayList<>();
for (int i = 0; i < u.size(); i++) {
types.add(union(u.get(i), v.get(i)));
}
Expand All @@ -127,6 +122,10 @@ public static Type union(Collection<Type> types) {
return result;
}

public static Type union(Type... types) {
return union(Arrays.asList(types));
}

@Nullable
public Type firstUseful() {
for (Type type : types) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/yinwang/pysonar/visitor/TypeInferencer.java
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ public Type visit(For node, State s)
s.merge(s2);
}

return UnionType.union(UnionType.union(t1, t2), t3);
return UnionType.union(t1, t2, t3);
}

@NotNull
Expand Down Expand Up @@ -1129,7 +1129,7 @@ public Type visit(While node, State s)
s.merge(s2);
}

return UnionType.union(UnionType.union(t1, t2), t3);
return UnionType.union(t1, t2, t3);
}

@NotNull
Expand Down

0 comments on commit 301d518

Please sign in to comment.