Fix unresolved reference to catch parameter from lambda expression

#KT-41140 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2020-08-18 10:52:45 +03:00
parent f2fba8a469
commit 6ed13ef1b6
9 changed files with 51 additions and 1 deletions
@@ -12637,6 +12637,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/inference/plusAssignInsideLambda.kt");
}
@TestMetadata("referenceToCatchParameterFromLambdaExpression.kt")
public void testReferenceToCatchParameterFromLambdaExpression() throws Exception {
runTest("compiler/testData/codegen/box/inference/referenceToCatchParameterFromLambdaExpression.kt");
}
@TestMetadata("unsafeVarianceCodegen.kt")
public void testUnsafeVarianceCodegen() throws Exception {
runTest("compiler/testData/codegen/box/inference/unsafeVarianceCodegen.kt");
@@ -728,6 +728,9 @@ class PSICallResolver(
val argumentName = valueArgument.getArgumentName()?.asName
@Suppress("NAME_SHADOWING")
val outerCallContext = outerCallContext.expandContextForCatchClause(ktExpression)
processFunctionalExpression(
outerCallContext, argumentExpression, startDataFlowInfo,
valueArgument, argumentName, builtIns, typeResolver
@@ -743,7 +746,7 @@ class PSICallResolver(
val context = outerCallContext.replaceContextDependency(ContextDependency.DEPENDENT)
.replaceDataFlowInfo(startDataFlowInfo)
.expandContextForCatchClause(ktExpression).let {
.let {
if (isSpecialFunction &&
argumentExpression is KtBlockExpression &&
ArgumentTypeResolver.getCallableReferenceExpressionIfAny(argumentExpression, it) != null
@@ -0,0 +1,12 @@
fun test(): () -> Throwable {
return try {
TODO()
} catch (e: Throwable) {
{ -> e }
}
}
fun box(): String {
val exception = test()()
return if (exception is NotImplementedError) "OK" else "fail: $exception"
}
@@ -13862,6 +13862,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/inference/plusAssignInsideLambda.kt");
}
@TestMetadata("referenceToCatchParameterFromLambdaExpression.kt")
public void testReferenceToCatchParameterFromLambdaExpression() throws Exception {
runTest("compiler/testData/codegen/box/inference/referenceToCatchParameterFromLambdaExpression.kt");
}
@TestMetadata("unsafeVarianceCodegen.kt")
public void testUnsafeVarianceCodegen() throws Exception {
runTest("compiler/testData/codegen/box/inference/unsafeVarianceCodegen.kt");
@@ -13862,6 +13862,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/inference/plusAssignInsideLambda.kt");
}
@TestMetadata("referenceToCatchParameterFromLambdaExpression.kt")
public void testReferenceToCatchParameterFromLambdaExpression() throws Exception {
runTest("compiler/testData/codegen/box/inference/referenceToCatchParameterFromLambdaExpression.kt");
}
@TestMetadata("unsafeVarianceCodegen.kt")
public void testUnsafeVarianceCodegen() throws Exception {
runTest("compiler/testData/codegen/box/inference/unsafeVarianceCodegen.kt");
@@ -12637,6 +12637,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/inference/plusAssignInsideLambda.kt");
}
@TestMetadata("referenceToCatchParameterFromLambdaExpression.kt")
public void testReferenceToCatchParameterFromLambdaExpression() throws Exception {
runTest("compiler/testData/codegen/box/inference/referenceToCatchParameterFromLambdaExpression.kt");
}
@TestMetadata("unsafeVarianceCodegen.kt")
public void testUnsafeVarianceCodegen() throws Exception {
runTest("compiler/testData/codegen/box/inference/unsafeVarianceCodegen.kt");
@@ -10812,6 +10812,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
runTest("compiler/testData/codegen/box/inference/plusAssignInsideLambda.kt");
}
@TestMetadata("referenceToCatchParameterFromLambdaExpression.kt")
public void testReferenceToCatchParameterFromLambdaExpression() throws Exception {
runTest("compiler/testData/codegen/box/inference/referenceToCatchParameterFromLambdaExpression.kt");
}
@TestMetadata("unsafeVarianceCodegen.kt")
public void testUnsafeVarianceCodegen() throws Exception {
runTest("compiler/testData/codegen/box/inference/unsafeVarianceCodegen.kt");
@@ -10812,6 +10812,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/inference/plusAssignInsideLambda.kt");
}
@TestMetadata("referenceToCatchParameterFromLambdaExpression.kt")
public void testReferenceToCatchParameterFromLambdaExpression() throws Exception {
runTest("compiler/testData/codegen/box/inference/referenceToCatchParameterFromLambdaExpression.kt");
}
@TestMetadata("unsafeVarianceCodegen.kt")
public void testUnsafeVarianceCodegen() throws Exception {
runTest("compiler/testData/codegen/box/inference/unsafeVarianceCodegen.kt");
@@ -10877,6 +10877,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/inference/plusAssignInsideLambda.kt");
}
@TestMetadata("referenceToCatchParameterFromLambdaExpression.kt")
public void testReferenceToCatchParameterFromLambdaExpression() throws Exception {
runTest("compiler/testData/codegen/box/inference/referenceToCatchParameterFromLambdaExpression.kt");
}
@TestMetadata("unsafeVarianceCodegen.kt")
public void testUnsafeVarianceCodegen() throws Exception {
runTest("compiler/testData/codegen/box/inference/unsafeVarianceCodegen.kt");