KT-2125 Inconsistent error message on UNSAFE_CALL
#KT-2125 fixed
This commit is contained in:
@@ -288,7 +288,7 @@ public class CallResolver {
|
||||
|
||||
return results;
|
||||
}
|
||||
if (traceForFirstNonemptyCandidateSet == null && !task.getCandidates().isEmpty()) {
|
||||
if (traceForFirstNonemptyCandidateSet == null && !task.getCandidates().isEmpty() && !results.isNothing()) {
|
||||
traceForFirstNonemptyCandidateSet = temporaryTrace;
|
||||
resultsForFirstNonemptyCandidateSet = results;
|
||||
}
|
||||
@@ -380,7 +380,9 @@ public class CallResolver {
|
||||
}
|
||||
else {
|
||||
assert status != UNKNOWN_STATUS : "No resolution for " + candidateCall.getCandidateDescriptor();
|
||||
failedCandidates.add(candidateCall);
|
||||
if (candidateCall.getStatus() != STRONG_ERROR) {
|
||||
failedCandidates.add(candidateCall);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -414,8 +416,13 @@ public class CallResolver {
|
||||
argumentMappingStatus = ValueArgumentsToParametersMapper.mapValueArgumentsToParameters(context.call, context.tracing,
|
||||
candidateCall, unmappedArguments);
|
||||
if (!argumentMappingStatus.isSuccess()) {
|
||||
candidateCall.addStatus(OTHER_ERROR);
|
||||
if (argumentMappingStatus == ValueArgumentsToParametersMapper.Status.ERROR) {
|
||||
if (argumentMappingStatus == ValueArgumentsToParametersMapper.Status.STRONG_ERROR) {
|
||||
candidateCall.addStatus(STRONG_ERROR);
|
||||
}
|
||||
else {
|
||||
candidateCall.addStatus(OTHER_ERROR);
|
||||
}
|
||||
if (argumentMappingStatus != ValueArgumentsToParametersMapper.Status.WEAK_ERROR) {
|
||||
checkTypesWithNoCallee(context.toBasic());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -25,12 +25,14 @@ public enum ResolutionStatus {
|
||||
UNKNOWN_STATUS,
|
||||
UNSAFE_CALL_ERROR,
|
||||
OTHER_ERROR,
|
||||
STRONG_ERROR,
|
||||
SUCCESS(true);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static final EnumSet<ResolutionStatus>[] SEVERITY_LEVELS = new EnumSet[] {
|
||||
EnumSet.of(UNSAFE_CALL_ERROR), // weakest
|
||||
EnumSet.of(OTHER_ERROR), // most severe
|
||||
EnumSet.of(OTHER_ERROR),
|
||||
EnumSet.of(STRONG_ERROR), // most severe
|
||||
};
|
||||
|
||||
private final boolean success;
|
||||
|
||||
@@ -152,14 +152,7 @@ public class ResolutionTask<D extends CallableDescriptor, F extends D> extends R
|
||||
|
||||
@Override
|
||||
public void noReceiverAllowed(@NotNull BindingTrace trace) {
|
||||
if (reference instanceof JetSimpleNameExpression) {
|
||||
//todo temporary hack
|
||||
//should be stored that the reference is unresolved (and not trace the candidate descriptor)
|
||||
trace.report(UNRESOLVED_REFERENCE.on(reference));
|
||||
}
|
||||
else {
|
||||
trace.report(NO_RECEIVER_ADMITTED.on(reference));
|
||||
}
|
||||
trace.report(NO_RECEIVER_ADMITTED.on(reference));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+13
-11
@@ -34,6 +34,8 @@ import java.util.Set;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.REFERENCE_TARGET;
|
||||
import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMapper.Status.*;
|
||||
import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMapper.Status.ERROR;
|
||||
import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMapper.Status.STRONG_ERROR;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
@@ -41,6 +43,7 @@ import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMap
|
||||
/*package*/ class ValueArgumentsToParametersMapper {
|
||||
|
||||
public enum Status {
|
||||
STRONG_ERROR(false),
|
||||
ERROR(false),
|
||||
WEAK_ERROR(false),
|
||||
OK(true);
|
||||
@@ -56,16 +59,10 @@ import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMap
|
||||
}
|
||||
|
||||
public Status compose(Status other) {
|
||||
switch (other) {
|
||||
case ERROR:
|
||||
return ERROR;
|
||||
case WEAK_ERROR:
|
||||
if (this != ERROR) {
|
||||
return WEAK_ERROR;
|
||||
}
|
||||
default:
|
||||
return this;
|
||||
}
|
||||
if (this == STRONG_ERROR || other == STRONG_ERROR) return STRONG_ERROR;
|
||||
if (this == ERROR || other == ERROR) return ERROR;
|
||||
if (this == WEAK_ERROR || other == WEAK_ERROR) return WEAK_ERROR;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,7 +217,12 @@ import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMap
|
||||
}
|
||||
if (!receiverParameter.exists() && receiverArgument.exists()) {
|
||||
tracing.noReceiverAllowed(temporaryTrace);
|
||||
status = ERROR;
|
||||
if (call.getCalleeExpression() instanceof JetSimpleNameExpression) {
|
||||
status = STRONG_ERROR;
|
||||
}
|
||||
else {
|
||||
status = ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
assert (candidateCall.getThisObject().exists() == candidateCall.getResultingDescriptor().getExpectedThisObject().exists()) : "Shouldn't happen because of TaskPrioritizer: " + candidateCall.getCandidateDescriptor();
|
||||
|
||||
+6
-4
@@ -613,10 +613,10 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
private JetType getVariableType(@NotNull JetSimpleNameExpression nameExpression, @NotNull ReceiverDescriptor receiver,
|
||||
@Nullable ASTNode callOperationNode, @NotNull ExpressionTypingContext context, @NotNull boolean[] result) {
|
||||
|
||||
TemporaryBindingTrace temporaryTrace = TemporaryBindingTrace.create(context.trace);
|
||||
OverloadResolutionResults<VariableDescriptor> resolutionResult = context.replaceBindingTrace(temporaryTrace).resolveSimpleProperty(receiver, callOperationNode, nameExpression);
|
||||
TemporaryBindingTrace traceForVariable = TemporaryBindingTrace.create(context.trace);
|
||||
OverloadResolutionResults<VariableDescriptor> resolutionResult = context.replaceBindingTrace(traceForVariable).resolveSimpleProperty(receiver, callOperationNode, nameExpression);
|
||||
if (!resolutionResult.isNothing()) {
|
||||
temporaryTrace.commit();
|
||||
traceForVariable.commit();
|
||||
checkSuper(receiver, resolutionResult, context.trace, nameExpression);
|
||||
result[0] = true;
|
||||
return resolutionResult.isSingleResult() ? resolutionResult.getResultingDescriptor().getReturnType() : null;
|
||||
@@ -625,8 +625,10 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
ExpressionTypingContext newContext = receiver.exists()
|
||||
? context.replaceScope(receiver.getType().getMemberScope())
|
||||
: context;
|
||||
JetType jetType = lookupNamespaceOrClassObject(nameExpression, nameExpression.getReferencedNameAsName(), newContext);
|
||||
TemporaryBindingTrace traceForNamespaceOrClassObject = TemporaryBindingTrace.create(context.trace);
|
||||
JetType jetType = lookupNamespaceOrClassObject(nameExpression, nameExpression.getReferencedNameAsName(), newContext.replaceBindingTrace(traceForNamespaceOrClassObject));
|
||||
if (jetType != null) {
|
||||
traceForNamespaceOrClassObject.commit();
|
||||
|
||||
// Uncommitted changes in temp context
|
||||
context.trace.record(RESOLUTION_SCOPE, nameExpression, context.scope);
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
//KT-2125 Inconsistent error message on UNSAFE_CALL
|
||||
|
||||
package e
|
||||
|
||||
fun main() {
|
||||
val <!UNUSED_VARIABLE!>compareTo<!> = 1
|
||||
val s: String? = null
|
||||
s<!UNSAFE_CALL!>.<!>compareTo("")
|
||||
|
||||
val <!UNUSED_VARIABLE!>bar<!> = 2
|
||||
s.<!UNRESOLVED_REFERENCE!>bar<!>()
|
||||
}
|
||||
Reference in New Issue
Block a user