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;
|
return results;
|
||||||
}
|
}
|
||||||
if (traceForFirstNonemptyCandidateSet == null && !task.getCandidates().isEmpty()) {
|
if (traceForFirstNonemptyCandidateSet == null && !task.getCandidates().isEmpty() && !results.isNothing()) {
|
||||||
traceForFirstNonemptyCandidateSet = temporaryTrace;
|
traceForFirstNonemptyCandidateSet = temporaryTrace;
|
||||||
resultsForFirstNonemptyCandidateSet = results;
|
resultsForFirstNonemptyCandidateSet = results;
|
||||||
}
|
}
|
||||||
@@ -380,7 +380,9 @@ public class CallResolver {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
assert status != UNKNOWN_STATUS : "No resolution for " + candidateCall.getCandidateDescriptor();
|
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,
|
argumentMappingStatus = ValueArgumentsToParametersMapper.mapValueArgumentsToParameters(context.call, context.tracing,
|
||||||
candidateCall, unmappedArguments);
|
candidateCall, unmappedArguments);
|
||||||
if (!argumentMappingStatus.isSuccess()) {
|
if (!argumentMappingStatus.isSuccess()) {
|
||||||
candidateCall.addStatus(OTHER_ERROR);
|
if (argumentMappingStatus == ValueArgumentsToParametersMapper.Status.STRONG_ERROR) {
|
||||||
if (argumentMappingStatus == ValueArgumentsToParametersMapper.Status.ERROR) {
|
candidateCall.addStatus(STRONG_ERROR);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
candidateCall.addStatus(OTHER_ERROR);
|
||||||
|
}
|
||||||
|
if (argumentMappingStatus != ValueArgumentsToParametersMapper.Status.WEAK_ERROR) {
|
||||||
checkTypesWithNoCallee(context.toBasic());
|
checkTypesWithNoCallee(context.toBasic());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,12 +25,14 @@ public enum ResolutionStatus {
|
|||||||
UNKNOWN_STATUS,
|
UNKNOWN_STATUS,
|
||||||
UNSAFE_CALL_ERROR,
|
UNSAFE_CALL_ERROR,
|
||||||
OTHER_ERROR,
|
OTHER_ERROR,
|
||||||
|
STRONG_ERROR,
|
||||||
SUCCESS(true);
|
SUCCESS(true);
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static final EnumSet<ResolutionStatus>[] SEVERITY_LEVELS = new EnumSet[] {
|
public static final EnumSet<ResolutionStatus>[] SEVERITY_LEVELS = new EnumSet[] {
|
||||||
EnumSet.of(UNSAFE_CALL_ERROR), // weakest
|
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;
|
private final boolean success;
|
||||||
|
|||||||
@@ -152,14 +152,7 @@ public class ResolutionTask<D extends CallableDescriptor, F extends D> extends R
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void noReceiverAllowed(@NotNull BindingTrace trace) {
|
public void noReceiverAllowed(@NotNull BindingTrace trace) {
|
||||||
if (reference instanceof JetSimpleNameExpression) {
|
trace.report(NO_RECEIVER_ADMITTED.on(reference));
|
||||||
//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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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.diagnostics.Errors.*;
|
||||||
import static org.jetbrains.jet.lang.resolve.BindingContext.REFERENCE_TARGET;
|
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.*;
|
||||||
|
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
|
* @author abreslav
|
||||||
@@ -41,6 +43,7 @@ import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMap
|
|||||||
/*package*/ class ValueArgumentsToParametersMapper {
|
/*package*/ class ValueArgumentsToParametersMapper {
|
||||||
|
|
||||||
public enum Status {
|
public enum Status {
|
||||||
|
STRONG_ERROR(false),
|
||||||
ERROR(false),
|
ERROR(false),
|
||||||
WEAK_ERROR(false),
|
WEAK_ERROR(false),
|
||||||
OK(true);
|
OK(true);
|
||||||
@@ -56,16 +59,10 @@ import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMap
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Status compose(Status other) {
|
public Status compose(Status other) {
|
||||||
switch (other) {
|
if (this == STRONG_ERROR || other == STRONG_ERROR) return STRONG_ERROR;
|
||||||
case ERROR:
|
if (this == ERROR || other == ERROR) return ERROR;
|
||||||
return ERROR;
|
if (this == WEAK_ERROR || other == WEAK_ERROR) return WEAK_ERROR;
|
||||||
case WEAK_ERROR:
|
return this;
|
||||||
if (this != ERROR) {
|
|
||||||
return WEAK_ERROR;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,7 +217,12 @@ import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMap
|
|||||||
}
|
}
|
||||||
if (!receiverParameter.exists() && receiverArgument.exists()) {
|
if (!receiverParameter.exists() && receiverArgument.exists()) {
|
||||||
tracing.noReceiverAllowed(temporaryTrace);
|
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();
|
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,
|
private JetType getVariableType(@NotNull JetSimpleNameExpression nameExpression, @NotNull ReceiverDescriptor receiver,
|
||||||
@Nullable ASTNode callOperationNode, @NotNull ExpressionTypingContext context, @NotNull boolean[] result) {
|
@Nullable ASTNode callOperationNode, @NotNull ExpressionTypingContext context, @NotNull boolean[] result) {
|
||||||
|
|
||||||
TemporaryBindingTrace temporaryTrace = TemporaryBindingTrace.create(context.trace);
|
TemporaryBindingTrace traceForVariable = TemporaryBindingTrace.create(context.trace);
|
||||||
OverloadResolutionResults<VariableDescriptor> resolutionResult = context.replaceBindingTrace(temporaryTrace).resolveSimpleProperty(receiver, callOperationNode, nameExpression);
|
OverloadResolutionResults<VariableDescriptor> resolutionResult = context.replaceBindingTrace(traceForVariable).resolveSimpleProperty(receiver, callOperationNode, nameExpression);
|
||||||
if (!resolutionResult.isNothing()) {
|
if (!resolutionResult.isNothing()) {
|
||||||
temporaryTrace.commit();
|
traceForVariable.commit();
|
||||||
checkSuper(receiver, resolutionResult, context.trace, nameExpression);
|
checkSuper(receiver, resolutionResult, context.trace, nameExpression);
|
||||||
result[0] = true;
|
result[0] = true;
|
||||||
return resolutionResult.isSingleResult() ? resolutionResult.getResultingDescriptor().getReturnType() : null;
|
return resolutionResult.isSingleResult() ? resolutionResult.getResultingDescriptor().getReturnType() : null;
|
||||||
@@ -625,8 +625,10 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
ExpressionTypingContext newContext = receiver.exists()
|
ExpressionTypingContext newContext = receiver.exists()
|
||||||
? context.replaceScope(receiver.getType().getMemberScope())
|
? context.replaceScope(receiver.getType().getMemberScope())
|
||||||
: context;
|
: 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) {
|
if (jetType != null) {
|
||||||
|
traceForNamespaceOrClassObject.commit();
|
||||||
|
|
||||||
// Uncommitted changes in temp context
|
// Uncommitted changes in temp context
|
||||||
context.trace.record(RESOLUTION_SCOPE, nameExpression, context.scope);
|
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