Skip to content

Commit

Permalink
Avoid pathological case where getExampleMethodName picks a very commo…
Browse files Browse the repository at this point in the history
…n method name
  • Loading branch information
smowton committed Oct 8, 2024
1 parent ed9a6bd commit c79da8b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions go/ql/lib/semmle/go/Types.qll
Original file line number Diff line number Diff line change
Expand Up @@ -1064,10 +1064,19 @@ class ErrorType extends Type {
ErrorType() { this.implements(Builtin::error().getType().getUnderlyingType()) }
}

/**
* Gets the number of types with method `name`.
*/
bindingset[name]
int numberOfTypesWithMethodName(string name) { result = count(Type t | t.hasMethod(name, _)) }

/**
* Gets the name of a method in the method set of `i`.
*
* This is used to restrict the set of interfaces to consider in the definition of `implements`,
* so it does not matter which method name is chosen (we use the lexicographically least).
* so it does not matter which method name is chosen (we use the most unusual name the interface
* require; this is the most discriminating and so shrinks the search space the most).
*/
private string getExampleMethodName(InterfaceType i) { result = min(string m | i.hasMethod(m, _)) }
private string getExampleMethodName(InterfaceType i) {
result = min(string m | i.hasMethod(m, _) | m order by numberOfTypesWithMethodName(m))
}

0 comments on commit c79da8b

Please sign in to comment.