Avoid pathological case where getExampleMethodName picks a very common method name

This commit is contained in:
Chris Smowton 2024-10-04 10:30:36 +01:00
Родитель ed9a6bd820
Коммит c79da8b2b5
1 изменённых файлов: 11 добавлений и 2 удалений

Просмотреть файл

@ -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))
}