diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt index bb30debdd5d..ad480d09256 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt @@ -15,6 +15,7 @@ import org.jetbrains.kotlin.descriptors.impl.FunctionDescriptorImpl import org.jetbrains.kotlin.descriptors.impl.ReceiverParameterDescriptorImpl import org.jetbrains.kotlin.psi.KtElement import org.jetbrains.kotlin.psi.KtExpression +import org.jetbrains.kotlin.psi.KtNamedFunction import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.BindingTrace import org.jetbrains.kotlin.resolve.DeprecationResolver @@ -139,7 +140,12 @@ class ResolvedAtomCompleter( ?: throw AssertionError("No function descriptor for resolved lambda argument") functionDescriptor.setReturnType(returnType) - val existingLambdaType = trace.getType(ktArgumentExpression) ?: throw AssertionError("No type for resolved lambda argument") + val existingLambdaType = trace.getType(ktArgumentExpression) + if (existingLambdaType == null) { + if (ktFunction is KtNamedFunction && ktFunction.nameIdentifier != null) return // it's a statement + + throw AssertionError("No type for resolved lambda argument: ${ktArgumentExpression.text}") + } val substitutedFunctionalType = createFunctionType( builtIns, existingLambdaType.annotations, diff --git a/compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.kt b/compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.kt index 848417f9a07..1862f1452d5 100644 --- a/compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.kt +++ b/compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.kt @@ -27,15 +27,15 @@ fun test() { fun named7() = 1 val x3 = when (1) { - 0 -> fun named8(): Int {return 1} - else -> fun named9() = 1 + 0 -> fun named8(): Int {return 1} + else -> fun named9() = 1 } val x31 = when (1) { 0 -> { - fun named10(): Int {return 1} + fun named10(): Int {return 1} } - else -> fun named11() = 1 + else -> fun named11() = 1 } val x4 = { @@ -55,5 +55,5 @@ fun success() { run2 { fun named2() = 1 } val x = run { fun named3() = 1 } - x checkType { _() } + x checkType { _() } } diff --git a/compiler/testData/diagnostics/tests/inference/localFunctionInsideIfBlock.kt b/compiler/testData/diagnostics/tests/inference/localFunctionInsideIfBlock.kt new file mode 100644 index 00000000000..424704c3e7a --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/localFunctionInsideIfBlock.kt @@ -0,0 +1,10 @@ +// !LANGUAGE: +NewInference + +fun bar() { + if (true) { + fun local() { + } + } else { + + } +} diff --git a/compiler/testData/diagnostics/tests/inference/localFunctionInsideIfBlock.txt b/compiler/testData/diagnostics/tests/inference/localFunctionInsideIfBlock.txt new file mode 100644 index 00000000000..19a5b8840b9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/localFunctionInsideIfBlock.txt @@ -0,0 +1,3 @@ +package + +public fun bar(): kotlin.Unit diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index e5620dbdbaa..a43a2eab0e6 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -9385,6 +9385,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { runTest("compiler/testData/diagnostics/tests/inference/listConstructor.kt"); } + @TestMetadata("localFunctionInsideIfBlock.kt") + public void testLocalFunctionInsideIfBlock() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/localFunctionInsideIfBlock.kt"); + } + @TestMetadata("mapFunction.kt") public void testMapFunction() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/mapFunction.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index a271d92d536..3356f585411 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -9385,6 +9385,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/inference/listConstructor.kt"); } + @TestMetadata("localFunctionInsideIfBlock.kt") + public void testLocalFunctionInsideIfBlock() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/localFunctionInsideIfBlock.kt"); + } + @TestMetadata("mapFunction.kt") public void testMapFunction() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/mapFunction.kt");