When doing method lookup for methods of generic interfaces, sort the candidates by their distance from the defining type, so that we use the closest one that matches. Fixes issue #445.
Add test for issue #445.