提交 7dab62ec 编写于 作者: S Svetlana Isakova

KT-2125 Inconsistent error message on UNSAFE_CALL

 #KT-2125 fixed
上级 423ed30e
...@@ -288,7 +288,7 @@ public class CallResolver { ...@@ -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,9 +380,11 @@ public class CallResolver { ...@@ -380,9 +380,11 @@ public class CallResolver {
} }
else { else {
assert status != UNKNOWN_STATUS : "No resolution for " + candidateCall.getCandidateDescriptor(); assert status != UNKNOWN_STATUS : "No resolution for " + candidateCall.getCandidateDescriptor();
if (candidateCall.getStatus() != STRONG_ERROR) {
failedCandidates.add(candidateCall); failedCandidates.add(candidateCall);
} }
} }
}
OverloadResolutionResultsImpl<F> results = computeResultAndReportErrors(task.trace, task.tracing, successfulCandidates, failedCandidates); OverloadResolutionResultsImpl<F> results = computeResultAndReportErrors(task.trace, task.tracing, successfulCandidates, failedCandidates);
if (!results.isSingleResult()) { if (!results.isSingleResult()) {
...@@ -414,8 +416,13 @@ public class CallResolver { ...@@ -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()) {
if (argumentMappingStatus == ValueArgumentsToParametersMapper.Status.STRONG_ERROR) {
candidateCall.addStatus(STRONG_ERROR);
}
else {
candidateCall.addStatus(OTHER_ERROR); candidateCall.addStatus(OTHER_ERROR);
if (argumentMappingStatus == ValueArgumentsToParametersMapper.Status.ERROR) { }
if (argumentMappingStatus != ValueArgumentsToParametersMapper.Status.WEAK_ERROR) {
checkTypesWithNoCallee(context.toBasic()); checkTypesWithNoCallee(context.toBasic());
return; return;
} }
......
...@@ -25,12 +25,14 @@ public enum ResolutionStatus { ...@@ -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,15 +152,8 @@ public class ResolutionTask<D extends CallableDescriptor, F extends D> extends R ...@@ -152,15 +152,8 @@ 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) {
//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 @Override
public void wrongNumberOfTypeArguments(@NotNull BindingTrace trace, int expectedTypeArgumentCount) { public void wrongNumberOfTypeArguments(@NotNull BindingTrace trace, int expectedTypeArgumentCount) {
......
...@@ -34,6 +34,8 @@ import java.util.Set; ...@@ -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 ...@@ -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,18 +59,12 @@ import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMap ...@@ -56,18 +59,12 @@ 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:
if (this != ERROR) {
return WEAK_ERROR;
}
default:
return this; return this;
} }
} }
}
public static <D extends CallableDescriptor> Status mapValueArgumentsToParameters( public static <D extends CallableDescriptor> Status mapValueArgumentsToParameters(
@NotNull Call call, @NotNull Call call,
...@@ -220,8 +217,13 @@ import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMap ...@@ -220,8 +217,13 @@ 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);
if (call.getCalleeExpression() instanceof JetSimpleNameExpression) {
status = STRONG_ERROR;
}
else {
status = ERROR; 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();
......
...@@ -613,10 +613,10 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { ...@@ -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 { ...@@ -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);
......
//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<!>()
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册