[NI] Fix exception on incomplete try/catch block
There was an inconsistency on creating PSI call and corresponding descriptor. See variable `catchBlocks` from visitor, it's created only if PSI elements are not null, but for descriptor parameters there wasn't such check #KT-32134 Fixed #EA-139748 Fixed
This commit is contained in:
+5
@@ -9297,6 +9297,11 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok
|
|||||||
runTest("compiler/testData/diagnostics/tests/incompleteCode/incompleteEquals.kt");
|
runTest("compiler/testData/diagnostics/tests/incompleteCode/incompleteEquals.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("incompleteTryCatchBlock.kt")
|
||||||
|
public void testIncompleteTryCatchBlock() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/incompleteCode/incompleteTryCatchBlock.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt1955.kt")
|
@TestMetadata("kt1955.kt")
|
||||||
public void testKt1955() throws Exception {
|
public void testKt1955() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/incompleteCode/kt1955.kt");
|
runTest("compiler/testData/diagnostics/tests/incompleteCode/kt1955.kt");
|
||||||
|
|||||||
+13
-7
@@ -123,24 +123,30 @@ public class ControlStructureTypingUtils {
|
|||||||
|
|
||||||
/*package*/ ResolvedCall<FunctionDescriptor> resolveTryAsCall(
|
/*package*/ ResolvedCall<FunctionDescriptor> resolveTryAsCall(
|
||||||
@NotNull Call call,
|
@NotNull Call call,
|
||||||
@NotNull KtTryExpression tryExpression,
|
|
||||||
@NotNull List<Pair<KtExpression, VariableDescriptor>> catchedExceptions,
|
@NotNull List<Pair<KtExpression, VariableDescriptor>> catchedExceptions,
|
||||||
@NotNull ExpressionTypingContext context,
|
@NotNull ExpressionTypingContext context,
|
||||||
@Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments
|
@Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments
|
||||||
) {
|
) {
|
||||||
List<String> argumentNames = Lists.newArrayList("tryBlock");
|
List<String> argumentNames = Lists.newArrayList("tryBlock");
|
||||||
List<Boolean> argumentsNullability = Lists.newArrayList(false);
|
List<Boolean> argumentsNullability = Lists.newArrayList(false);
|
||||||
for (int i = 0; i < tryExpression.getCatchClauses().size(); i++) {
|
|
||||||
argumentNames.add("catchBlock" + i);
|
int counter = 0;
|
||||||
argumentsNullability.add(false);
|
|
||||||
}
|
|
||||||
SimpleFunctionDescriptorImpl function =
|
|
||||||
createFunctionDescriptorForSpecialConstruction(ResolveConstruct.TRY, argumentNames, argumentsNullability);
|
|
||||||
for (Pair<KtExpression, VariableDescriptor> descriptorPair : catchedExceptions) {
|
for (Pair<KtExpression, VariableDescriptor> descriptorPair : catchedExceptions) {
|
||||||
|
// catchedExceptions are corresponding to PSI arguments that were used to create a call
|
||||||
|
// therefore, it's important to use only them to have consistent parameters
|
||||||
|
argumentNames.add("catchBlock" + counter);
|
||||||
|
argumentsNullability.add(false);
|
||||||
|
|
||||||
KtExpression catchBlock = descriptorPair.getFirst();
|
KtExpression catchBlock = descriptorPair.getFirst();
|
||||||
VariableDescriptor catchedExceptionDescriptor = descriptorPair.getSecond();
|
VariableDescriptor catchedExceptionDescriptor = descriptorPair.getSecond();
|
||||||
context.trace.record(BindingContext.NEW_INFERENCE_CATCH_EXCEPTION_PARAMETER, catchBlock, Ref.create(catchedExceptionDescriptor));
|
context.trace.record(BindingContext.NEW_INFERENCE_CATCH_EXCEPTION_PARAMETER, catchBlock, Ref.create(catchedExceptionDescriptor));
|
||||||
|
|
||||||
|
counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SimpleFunctionDescriptorImpl function =
|
||||||
|
createFunctionDescriptorForSpecialConstruction(ResolveConstruct.TRY, argumentNames, argumentsNullability);
|
||||||
|
|
||||||
return resolveSpecialConstructionAsCall(call, function, ResolveConstruct.TRY, context, dataFlowInfoForArguments);
|
return resolveSpecialConstructionAsCall(call, function, ResolveConstruct.TRY, context, dataFlowInfoForArguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -611,7 +611,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
dataFlowInfoForArguments = createDataFlowInfoForArgumentsOfTryCall(callForTry, dataFlowInfoBeforeTry, dataFlowInfoBeforeTry);
|
dataFlowInfoForArguments = createDataFlowInfoForArgumentsOfTryCall(callForTry, dataFlowInfoBeforeTry, dataFlowInfoBeforeTry);
|
||||||
}
|
}
|
||||||
ResolvedCall<FunctionDescriptor> resolvedCall = components.controlStructureTypingUtils
|
ResolvedCall<FunctionDescriptor> resolvedCall = components.controlStructureTypingUtils
|
||||||
.resolveTryAsCall(callForTry, tryExpression, catchClausesBlocksAndParameters, tryInputContext, dataFlowInfoForArguments);
|
.resolveTryAsCall(callForTry, catchClausesBlocksAndParameters, tryInputContext, dataFlowInfoForArguments);
|
||||||
KotlinType resultType = resolvedCall.getResultingDescriptor().getReturnType();
|
KotlinType resultType = resolvedCall.getResultingDescriptor().getReturnType();
|
||||||
|
|
||||||
BindingContext bindingContext = tryInputContext.trace.getBindingContext();
|
BindingContext bindingContext = tryInputContext.trace.getBindingContext();
|
||||||
|
|||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
fun test1() {
|
||||||
|
try {
|
||||||
|
|
||||||
|
} catch (<!SYNTAX!><!>)<!SYNTAX!><!>
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test2() {
|
||||||
|
try { }<!SYNTAX!><!>
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test3() {
|
||||||
|
try {
|
||||||
|
} catch (<!SYNTAX!><!>{}<!SYNTAX!>)<!> <!UNUSED_LAMBDA_EXPRESSION!>{}<!>
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun test1(): kotlin.Unit
|
||||||
|
public fun test2(): kotlin.Unit
|
||||||
|
public fun test3(): kotlin.Unit
|
||||||
@@ -9304,6 +9304,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/incompleteCode/incompleteEquals.kt");
|
runTest("compiler/testData/diagnostics/tests/incompleteCode/incompleteEquals.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("incompleteTryCatchBlock.kt")
|
||||||
|
public void testIncompleteTryCatchBlock() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/incompleteCode/incompleteTryCatchBlock.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt1955.kt")
|
@TestMetadata("kt1955.kt")
|
||||||
public void testKt1955() throws Exception {
|
public void testKt1955() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/incompleteCode/kt1955.kt");
|
runTest("compiler/testData/diagnostics/tests/incompleteCode/kt1955.kt");
|
||||||
|
|||||||
Generated
+5
@@ -9299,6 +9299,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
|||||||
runTest("compiler/testData/diagnostics/tests/incompleteCode/incompleteEquals.kt");
|
runTest("compiler/testData/diagnostics/tests/incompleteCode/incompleteEquals.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("incompleteTryCatchBlock.kt")
|
||||||
|
public void testIncompleteTryCatchBlock() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/incompleteCode/incompleteTryCatchBlock.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt1955.kt")
|
@TestMetadata("kt1955.kt")
|
||||||
public void testKt1955() throws Exception {
|
public void testKt1955() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/incompleteCode/kt1955.kt");
|
runTest("compiler/testData/diagnostics/tests/incompleteCode/kt1955.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user