Skip to content

Commit c79da8b

Browse files
committed
Avoid pathological case where getExampleMethodName picks a very common method name
1 parent ed9a6bd commit c79da8b

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

go/ql/lib/semmle/go/Types.qll

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,10 +1064,19 @@ class ErrorType extends Type {
10641064
ErrorType() { this.implements(Builtin::error().getType().getUnderlyingType()) }
10651065
}
10661066

1067+
/**
1068+
* Gets the number of types with method `name`.
1069+
*/
1070+
bindingset[name]
1071+
int numberOfTypesWithMethodName(string name) { result = count(Type t | t.hasMethod(name, _)) }
1072+
10671073
/**
10681074
* Gets the name of a method in the method set of `i`.
10691075
*
10701076
* This is used to restrict the set of interfaces to consider in the definition of `implements`,
1071-
* so it does not matter which method name is chosen (we use the lexicographically least).
1077+
* so it does not matter which method name is chosen (we use the most unusual name the interface
1078+
* require; this is the most discriminating and so shrinks the search space the most).
10721079
*/
1073-
private string getExampleMethodName(InterfaceType i) { result = min(string m | i.hasMethod(m, _)) }
1080+
private string getExampleMethodName(InterfaceType i) {
1081+
result = min(string m | i.hasMethod(m, _) | m order by numberOfTypesWithMethodName(m))
1082+
}

0 commit comments

Comments
 (0)