From 067ac5c94aabd59e5d19004a3528cb0390cc2a20 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Mon, 1 Sep 2014 22:17:48 +0400 Subject: [PATCH] Fixed one part of 'Resolution error of this type shouldn't occur for...' Result for "IF(T, T)" can be "hasUnknownParameters" if both arguments have types 'uninferred type parameter' (incomplete resolve case), no constraints are added to the system. --- .../ControlStructureTypingUtils.java | 54 ++++++++++--------- .../incompleteCode/controlStructuresErrors.kt | 24 +++++++++ .../checkers/JetDiagnosticsTestGenerated.java | 5 ++ 3 files changed, 58 insertions(+), 25 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/incompleteCode/controlStructuresErrors.kt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingUtils.java index 11e80ed9092..410cbc2e354 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingUtils.java @@ -19,6 +19,8 @@ package org.jetbrains.jet.lang.types.expressions; import com.google.common.collect.Lists; import com.google.common.collect.Maps; 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.Nullable; 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; public class ControlStructureTypingUtils { + private static final Logger LOG = Logger.getInstance(ControlStructureTypingUtils.class); private final ExpressionTypingServices expressionTypingServices; @@ -346,7 +349,7 @@ public class ControlStructureTypingUtils { ConstraintSystemStatus status = constraintSystem.getStatus(); assert !status.isSuccessful() : "Report error only for not successful constraint system"; - if (status.hasErrorInConstrainingTypes()) { + if (status.hasErrorInConstrainingTypes() || status.hasUnknownParameters()) { return; } JetExpression expression = (JetExpression) call.getCallElement(); @@ -354,8 +357,9 @@ public class ControlStructureTypingUtils { expression.accept(checkTypeVisitor, new CheckTypeContext(trace, data.expectedType)); return; } - throwError("Expression: " + expression.getText() + ".\nConstraint system status: \n" + ConstraintsUtil.getDebugMessageForStatus(status)); - super.typeInferenceFailed(trace, data); + JetDeclaration parentDeclaration = PsiTreeUtil.getParentOfType(expression, JetNamedDeclaration.class); + 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; } - private void throwError() { - throwError(null); + private void logError() { + 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; if (additionalInformation != null) { errorMessage += ".\n" + additionalInformation; } - throw new IllegalStateException(errorMessage); + LOG.error(errorMessage); } @Override public void unresolvedReference(@NotNull BindingTrace trace) { - throwError(); + logError(); } @Override public void unresolvedReferenceWrongReceiver( @NotNull BindingTrace trace, @NotNull Collection> candidates ) { - throwError(); + logError(); } @Override public void recordAmbiguity( @NotNull BindingTrace trace, @NotNull Collection> candidates ) { - throwError(); + logError(); } @Override public void missingReceiver( @NotNull BindingTrace trace, @NotNull ReceiverParameterDescriptor expectedReceiver ) { - throwError(); + logError(); } @Override public void wrongReceiverType( @NotNull BindingTrace trace, @NotNull ReceiverParameterDescriptor receiverParameter, @NotNull ReceiverValue receiverArgument ) { - throwError(); + logError(); } @Override public void noReceiverAllowed(@NotNull BindingTrace trace) { - throwError(); + logError(); } @Override public void noValueForParameter( @NotNull BindingTrace trace, @NotNull ValueParameterDescriptor valueParameter ) { - throwError(); + logError(); } @Override public void wrongNumberOfTypeArguments(@NotNull BindingTrace trace, int expectedTypeArgumentCount) { - throwError(); + logError(); } @Override public void ambiguity( @NotNull BindingTrace trace, @NotNull Collection> descriptors ) { - throwError(); + logError(); } @Override public void noneApplicable( @NotNull BindingTrace trace, @NotNull Collection> descriptors ) { - throwError(); + logError(); } @Override public void cannotCompleteResolve( @NotNull BindingTrace trace, @NotNull Collection> descriptors ) { - throwError(); + logError(); } @Override public void instantiationOfAbstractClass(@NotNull BindingTrace trace) { - throwError(); + logError(); } @Override @@ -460,42 +464,42 @@ public class ControlStructureTypingUtils { @NotNull BindingTrace trace, @NotNull ClassDescriptor classDescriptor, @NotNull ExplicitReceiverKind explicitReceiverKind ) { - throwError(); + logError(); } @Override public void unsafeCall( @NotNull BindingTrace trace, @NotNull JetType type, boolean isCallForImplicitInvoke ) { - throwError(); + logError(); } @Override public void unnecessarySafeCall( @NotNull BindingTrace trace, @NotNull JetType type ) { - throwError(); + logError(); } @Override public void danglingFunctionLiteralArgumentSuspected( @NotNull BindingTrace trace, @NotNull List functionLiteralArguments ) { - throwError(); + logError(); } @Override public void invisibleMember( @NotNull BindingTrace trace, @NotNull DeclarationDescriptorWithVisibility descriptor ) { - throwError(); + logError(); } @Override public void typeInferenceFailed( @NotNull BindingTrace trace, @NotNull InferenceErrorData inferenceErrorData ) { - throwError(); + logError(); } } } diff --git a/compiler/testData/diagnostics/tests/incompleteCode/controlStructuresErrors.kt b/compiler/testData/diagnostics/tests/incompleteCode/controlStructuresErrors.kt new file mode 100644 index 00000000000..c3a8ef074b0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/incompleteCode/controlStructuresErrors.kt @@ -0,0 +1,24 @@ +fun test1() { + if (rr) { + if (l) { + a.q() + } + else { + a.w() + } + } + else { + if (n) { + a.t() + } + else { + a.u() + } + } +} + +fun test2(l: List<AA>) { + l.map { + it!! + } +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 86d3be366be..7525ea46635 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -3781,6 +3781,11 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { 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") public void testInExpr() throws Exception { doTest("compiler/testData/diagnostics/tests/incompleteCode/inExpr.kt");