KT-1781 Can't distinguish between two constructors

#KT-1781 Fixed

 Now, if foo() and foo(vararg bar) both match the call site, the first one is preferred
This commit is contained in:
Andrey Breslav
2012-04-16 15:56:19 +04:00
parent d549e9d3a5
commit 0f98c281ab
7 changed files with 75 additions and 3 deletions
@@ -94,10 +94,24 @@ public class OverloadingConflictResolver {
List<ValueParameterDescriptor> gParams = g.getValueParameters();
int fSize = fParams.size();
if (fSize != gParams.size()) return false;
for (int i = 0; i < fSize; i++) {
int gSize = gParams.size();
if (fSize > gSize) return false;
for (int i = 0; i < gSize; i++) {
ValueParameterDescriptor gParam = gParams.get(i);
JetType gParamType = gParam.getType();
if (i >= fSize) {
// f() has fewer parameters than g()
// The point is: g() may have a last vararg that doesn't get any arguments
// In this case f() is more specific, because one can explicitly pass
// an empty array to g() and make it preferred
if (i != gSize - 1 || gParam.getVarargElementType() == null) {
return false;
}
return true;
}
JetType fParamType = fParams.get(i).getType();
JetType gParamType = gParams.get(i).getType();
if (!typeMoreSpecific(fParamType, gParamType)) {
return false;