Resolution diagnostic improvement
#KT-1940 fixed
This commit is contained in:
@@ -19,7 +19,6 @@ package org.jetbrains.jet.lang.resolve.calls;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
@@ -407,15 +406,17 @@ public class CallResolver {
|
||||
return;
|
||||
}
|
||||
|
||||
Set<ValueArgument> unmappedArguments = Sets.newLinkedHashSet();
|
||||
ValueArgumentsToParametersMapper.Status
|
||||
argumentMappingStatus = ValueArgumentsToParametersMapper.mapValueArgumentsToParameters(context.call, context.tracing,
|
||||
candidateCall);
|
||||
candidateCall, unmappedArguments);
|
||||
if (!argumentMappingStatus.isSuccess()) {
|
||||
candidateCall.addStatus(OTHER_ERROR);
|
||||
if (argumentMappingStatus == ValueArgumentsToParametersMapper.Status.ERROR) {
|
||||
checkTypesWithNoCallee(context.toBasic());
|
||||
return;
|
||||
}
|
||||
checkUnknownArgumentTypes(context.toBasic(), unmappedArguments);
|
||||
}
|
||||
|
||||
List<JetTypeProjection> jetTypeArguments = context.call.getTypeArguments();
|
||||
@@ -611,6 +612,15 @@ public class CallResolver {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkUnknownArgumentTypes(BasicResolutionContext context, Set<ValueArgument> unknownArguments) {
|
||||
for (ValueArgument valueArgument : unknownArguments) {
|
||||
JetExpression argumentExpression = valueArgument.getArgumentExpression();
|
||||
if (argumentExpression != null) {
|
||||
expressionTypingServices.getType(context.scope, argumentExpression, NO_EXPECTED_TYPE, context.trace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static <D extends CallableDescriptor> void replaceValueParametersWithSubstitutedOnes(
|
||||
ResolvedCallImpl<D> candidateCall, @NotNull D substitutedDescriptor) {
|
||||
|
||||
|
||||
+13
-5
@@ -71,7 +71,8 @@ import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMap
|
||||
public static <D extends CallableDescriptor> Status mapValueArgumentsToParameters(
|
||||
@NotNull Call call,
|
||||
@NotNull TracingStrategy tracing,
|
||||
@NotNull ResolvedCallImpl<D> candidateCall
|
||||
@NotNull ResolvedCallImpl<D> candidateCall,
|
||||
@NotNull Set<ValueArgument> unmappedArguments
|
||||
) {
|
||||
TemporaryBindingTrace temporaryTrace = candidateCall.getTrace();
|
||||
Map<ValueParameterDescriptor, VarargValueArgument> varargs = Maps.newHashMap();
|
||||
@@ -99,14 +100,19 @@ import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMap
|
||||
ValueParameterDescriptor valueParameterDescriptor = parameterByName.get(nameReference.getReferencedName());
|
||||
if (valueParameterDescriptor == null) {
|
||||
temporaryTrace.report(NAMED_PARAMETER_NOT_FOUND.on(nameReference));
|
||||
unmappedArguments.add(valueArgument);
|
||||
status = ERROR;
|
||||
}
|
||||
else {
|
||||
temporaryTrace.record(REFERENCE_TARGET, nameReference, valueParameterDescriptor);
|
||||
if (!usedParameters.add(valueParameterDescriptor)) {
|
||||
temporaryTrace.report(ARGUMENT_PASSED_TWICE.on(nameReference));
|
||||
unmappedArguments.add(valueArgument);
|
||||
status = WEAK_ERROR;
|
||||
}
|
||||
else {
|
||||
status = status.compose(put(candidateCall, valueParameterDescriptor, valueArgument, varargs));
|
||||
}
|
||||
temporaryTrace.record(REFERENCE_TARGET, nameReference, valueParameterDescriptor);
|
||||
status = status.compose(put(candidateCall, valueParameterDescriptor, valueArgument, varargs));
|
||||
}
|
||||
if (somePositioned) {
|
||||
temporaryTrace.report(MIXING_NAMED_AND_POSITIONED_ARGUMENTS.on(nameReference));
|
||||
@@ -134,12 +140,14 @@ import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMap
|
||||
}
|
||||
else {
|
||||
temporaryTrace.report(TOO_MANY_ARGUMENTS.on(valueArgument.asElement(), candidate));
|
||||
status = ERROR;
|
||||
unmappedArguments.add(valueArgument);
|
||||
status = WEAK_ERROR;
|
||||
}
|
||||
}
|
||||
else {
|
||||
temporaryTrace.report(TOO_MANY_ARGUMENTS.on(valueArgument.asElement(), candidate));
|
||||
status = ERROR;
|
||||
unmappedArguments.add(valueArgument);
|
||||
status = WEAK_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package a
|
||||
|
||||
fun foo(<!UNUSED_PARAMETER!>i<!>: Int, <!UNUSED_PARAMETER!>s<!>: String) {
|
||||
}
|
||||
|
||||
fun test() {
|
||||
foo(<!TYPE_MISMATCH!>""<!>, <!ERROR_COMPILE_TIME_VALUE!>1<!>, <!TOO_MANY_ARGUMENTS, UNRESOLVED_REFERENCE!>xx<!>)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
//KT-1940 Exception while repeating named parameters
|
||||
package kt1940
|
||||
|
||||
fun foo(<!UNUSED_PARAMETER!>i<!>: Int) {}
|
||||
|
||||
fun test() {
|
||||
foo(1, <!ARGUMENT_PASSED_TWICE, MIXING_NAMED_AND_POSITIONED_ARGUMENTS!>i<!> = 2) //exception
|
||||
foo(i = 1, <!ARGUMENT_PASSED_TWICE!>i<!> = 2) //exception
|
||||
}
|
||||
Reference in New Issue
Block a user