Fixed one part of 'Resolution error of this type shouldn't occur for...'
Result for "IF<T>(T, T)" can be "hasUnknownParameters" if both arguments have types 'uninferred type parameter' (incomplete resolve case), no constraints are added to the system.
This commit is contained in:
+29
-25
@@ -19,6 +19,8 @@ package org.jetbrains.jet.lang.types.expressions;
|
|||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.intellij.lang.ASTNode;
|
import com.intellij.lang.ASTNode;
|
||||||
|
import com.intellij.openapi.diagnostic.Logger;
|
||||||
|
import com.intellij.psi.util.PsiTreeUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
@@ -50,6 +52,7 @@ import static org.jetbrains.jet.lang.resolve.BindingContext.CALL;
|
|||||||
import static org.jetbrains.jet.lang.resolve.BindingContext.RESOLVED_CALL;
|
import static org.jetbrains.jet.lang.resolve.BindingContext.RESOLVED_CALL;
|
||||||
|
|
||||||
public class ControlStructureTypingUtils {
|
public class ControlStructureTypingUtils {
|
||||||
|
private static final Logger LOG = Logger.getInstance(ControlStructureTypingUtils.class);
|
||||||
|
|
||||||
private final ExpressionTypingServices expressionTypingServices;
|
private final ExpressionTypingServices expressionTypingServices;
|
||||||
|
|
||||||
@@ -346,7 +349,7 @@ public class ControlStructureTypingUtils {
|
|||||||
ConstraintSystemStatus status = constraintSystem.getStatus();
|
ConstraintSystemStatus status = constraintSystem.getStatus();
|
||||||
assert !status.isSuccessful() : "Report error only for not successful constraint system";
|
assert !status.isSuccessful() : "Report error only for not successful constraint system";
|
||||||
|
|
||||||
if (status.hasErrorInConstrainingTypes()) {
|
if (status.hasErrorInConstrainingTypes() || status.hasUnknownParameters()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
JetExpression expression = (JetExpression) call.getCallElement();
|
JetExpression expression = (JetExpression) call.getCallElement();
|
||||||
@@ -354,8 +357,9 @@ public class ControlStructureTypingUtils {
|
|||||||
expression.accept(checkTypeVisitor, new CheckTypeContext(trace, data.expectedType));
|
expression.accept(checkTypeVisitor, new CheckTypeContext(trace, data.expectedType));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throwError("Expression: " + expression.getText() + ".\nConstraint system status: \n" + ConstraintsUtil.getDebugMessageForStatus(status));
|
JetDeclaration parentDeclaration = PsiTreeUtil.getParentOfType(expression, JetNamedDeclaration.class);
|
||||||
super.typeInferenceFailed(trace, data);
|
logError("Expression: " + (parentDeclaration != null ? parentDeclaration.getText() : expression.getText()) +
|
||||||
|
"\nConstraint system status: \n" + ConstraintsUtil.getDebugMessageForStatus(status));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -367,92 +371,92 @@ public class ControlStructureTypingUtils {
|
|||||||
this.debugName = debugName;
|
this.debugName = debugName;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void throwError() {
|
private void logError() {
|
||||||
throwError(null);
|
logError(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void throwError(@Nullable String additionalInformation) {
|
protected void logError(@Nullable String additionalInformation) {
|
||||||
String errorMessage = "Resolution error of this type shouldn't occur for " + debugName;
|
String errorMessage = "Resolution error of this type shouldn't occur for " + debugName;
|
||||||
if (additionalInformation != null) {
|
if (additionalInformation != null) {
|
||||||
errorMessage += ".\n" + additionalInformation;
|
errorMessage += ".\n" + additionalInformation;
|
||||||
}
|
}
|
||||||
throw new IllegalStateException(errorMessage);
|
LOG.error(errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unresolvedReference(@NotNull BindingTrace trace) {
|
public void unresolvedReference(@NotNull BindingTrace trace) {
|
||||||
throwError();
|
logError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <D extends CallableDescriptor> void unresolvedReferenceWrongReceiver(
|
public <D extends CallableDescriptor> void unresolvedReferenceWrongReceiver(
|
||||||
@NotNull BindingTrace trace, @NotNull Collection<? extends ResolvedCall<D>> candidates
|
@NotNull BindingTrace trace, @NotNull Collection<? extends ResolvedCall<D>> candidates
|
||||||
) {
|
) {
|
||||||
throwError();
|
logError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <D extends CallableDescriptor> void recordAmbiguity(
|
public <D extends CallableDescriptor> void recordAmbiguity(
|
||||||
@NotNull BindingTrace trace, @NotNull Collection<? extends ResolvedCall<D>> candidates
|
@NotNull BindingTrace trace, @NotNull Collection<? extends ResolvedCall<D>> candidates
|
||||||
) {
|
) {
|
||||||
throwError();
|
logError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void missingReceiver(
|
public void missingReceiver(
|
||||||
@NotNull BindingTrace trace, @NotNull ReceiverParameterDescriptor expectedReceiver
|
@NotNull BindingTrace trace, @NotNull ReceiverParameterDescriptor expectedReceiver
|
||||||
) {
|
) {
|
||||||
throwError();
|
logError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void wrongReceiverType(
|
public void wrongReceiverType(
|
||||||
@NotNull BindingTrace trace, @NotNull ReceiverParameterDescriptor receiverParameter, @NotNull ReceiverValue receiverArgument
|
@NotNull BindingTrace trace, @NotNull ReceiverParameterDescriptor receiverParameter, @NotNull ReceiverValue receiverArgument
|
||||||
) {
|
) {
|
||||||
throwError();
|
logError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void noReceiverAllowed(@NotNull BindingTrace trace) {
|
public void noReceiverAllowed(@NotNull BindingTrace trace) {
|
||||||
throwError();
|
logError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void noValueForParameter(
|
public void noValueForParameter(
|
||||||
@NotNull BindingTrace trace, @NotNull ValueParameterDescriptor valueParameter
|
@NotNull BindingTrace trace, @NotNull ValueParameterDescriptor valueParameter
|
||||||
) {
|
) {
|
||||||
throwError();
|
logError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void wrongNumberOfTypeArguments(@NotNull BindingTrace trace, int expectedTypeArgumentCount) {
|
public void wrongNumberOfTypeArguments(@NotNull BindingTrace trace, int expectedTypeArgumentCount) {
|
||||||
throwError();
|
logError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <D extends CallableDescriptor> void ambiguity(
|
public <D extends CallableDescriptor> void ambiguity(
|
||||||
@NotNull BindingTrace trace, @NotNull Collection<? extends ResolvedCall<D>> descriptors
|
@NotNull BindingTrace trace, @NotNull Collection<? extends ResolvedCall<D>> descriptors
|
||||||
) {
|
) {
|
||||||
throwError();
|
logError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <D extends CallableDescriptor> void noneApplicable(
|
public <D extends CallableDescriptor> void noneApplicable(
|
||||||
@NotNull BindingTrace trace, @NotNull Collection<? extends ResolvedCall<D>> descriptors
|
@NotNull BindingTrace trace, @NotNull Collection<? extends ResolvedCall<D>> descriptors
|
||||||
) {
|
) {
|
||||||
throwError();
|
logError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <D extends CallableDescriptor> void cannotCompleteResolve(
|
public <D extends CallableDescriptor> void cannotCompleteResolve(
|
||||||
@NotNull BindingTrace trace, @NotNull Collection<? extends ResolvedCall<D>> descriptors
|
@NotNull BindingTrace trace, @NotNull Collection<? extends ResolvedCall<D>> descriptors
|
||||||
) {
|
) {
|
||||||
throwError();
|
logError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void instantiationOfAbstractClass(@NotNull BindingTrace trace) {
|
public void instantiationOfAbstractClass(@NotNull BindingTrace trace) {
|
||||||
throwError();
|
logError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -460,42 +464,42 @@ public class ControlStructureTypingUtils {
|
|||||||
@NotNull BindingTrace trace, @NotNull ClassDescriptor classDescriptor,
|
@NotNull BindingTrace trace, @NotNull ClassDescriptor classDescriptor,
|
||||||
@NotNull ExplicitReceiverKind explicitReceiverKind
|
@NotNull ExplicitReceiverKind explicitReceiverKind
|
||||||
) {
|
) {
|
||||||
throwError();
|
logError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unsafeCall(
|
public void unsafeCall(
|
||||||
@NotNull BindingTrace trace, @NotNull JetType type, boolean isCallForImplicitInvoke
|
@NotNull BindingTrace trace, @NotNull JetType type, boolean isCallForImplicitInvoke
|
||||||
) {
|
) {
|
||||||
throwError();
|
logError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unnecessarySafeCall(
|
public void unnecessarySafeCall(
|
||||||
@NotNull BindingTrace trace, @NotNull JetType type
|
@NotNull BindingTrace trace, @NotNull JetType type
|
||||||
) {
|
) {
|
||||||
throwError();
|
logError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void danglingFunctionLiteralArgumentSuspected(
|
public void danglingFunctionLiteralArgumentSuspected(
|
||||||
@NotNull BindingTrace trace, @NotNull List<JetFunctionLiteralArgument> functionLiteralArguments
|
@NotNull BindingTrace trace, @NotNull List<JetFunctionLiteralArgument> functionLiteralArguments
|
||||||
) {
|
) {
|
||||||
throwError();
|
logError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invisibleMember(
|
public void invisibleMember(
|
||||||
@NotNull BindingTrace trace, @NotNull DeclarationDescriptorWithVisibility descriptor
|
@NotNull BindingTrace trace, @NotNull DeclarationDescriptorWithVisibility descriptor
|
||||||
) {
|
) {
|
||||||
throwError();
|
logError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void typeInferenceFailed(
|
public void typeInferenceFailed(
|
||||||
@NotNull BindingTrace trace, @NotNull InferenceErrorData inferenceErrorData
|
@NotNull BindingTrace trace, @NotNull InferenceErrorData inferenceErrorData
|
||||||
) {
|
) {
|
||||||
throwError();
|
logError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
fun test1() {
|
||||||
|
if (<!UNRESOLVED_REFERENCE!>rr<!>) {
|
||||||
|
if (<!UNRESOLVED_REFERENCE!>l<!>) {
|
||||||
|
<!UNRESOLVED_REFERENCE!>a<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>q<!>()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
<!UNRESOLVED_REFERENCE!>a<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>w<!>()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (<!UNRESOLVED_REFERENCE!>n<!>) {
|
||||||
|
<!UNRESOLVED_REFERENCE!>a<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>t<!>()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
<!UNRESOLVED_REFERENCE!>a<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>u<!>()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test2(l: List<<!UNRESOLVED_REFERENCE!>AA<!>>) {
|
||||||
|
<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>l<!>.<!UNRESOLVED_REFERENCE!>map<!> {
|
||||||
|
<!UNRESOLVED_REFERENCE!>it<!>!!
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3781,6 +3781,11 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
|||||||
doTest("compiler/testData/diagnostics/tests/incompleteCode/checkNothingIsSubtype.kt");
|
doTest("compiler/testData/diagnostics/tests/incompleteCode/checkNothingIsSubtype.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("controlStructuresErrors.kt")
|
||||||
|
public void testControlStructuresErrors() throws Exception {
|
||||||
|
doTest("compiler/testData/diagnostics/tests/incompleteCode/controlStructuresErrors.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("inExpr.kt")
|
@TestMetadata("inExpr.kt")
|
||||||
public void testInExpr() throws Exception {
|
public void testInExpr() throws Exception {
|
||||||
doTest("compiler/testData/diagnostics/tests/incompleteCode/inExpr.kt");
|
doTest("compiler/testData/diagnostics/tests/incompleteCode/inExpr.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user