[NI] Fix exception, recorded type for function statement can be null
See `checkStatementType`, we return `null` to reduce count of errors. Also, note that named function which is used as last statement in lambda doesn't coerce to Unit, this is a separate bug and will be addressed later, see #KT-25383 #EA-121026 Fixed
This commit is contained in:
+7
-1
@@ -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,
|
||||
|
||||
+5
-5
@@ -27,15 +27,15 @@ fun test() {
|
||||
<!SYNTAX!><!>fun named7() = 1
|
||||
|
||||
val x3 = when (1) {
|
||||
0 -> <!OI;EXPECTED_TYPE_MISMATCH!>fun <!NI;ANONYMOUS_FUNCTION_WITH_NAME!>named8<!>(): Int {return 1}<!>
|
||||
else -> <!OI;EXPECTED_TYPE_MISMATCH!>fun <!NI;ANONYMOUS_FUNCTION_WITH_NAME!>named9<!>() = 1<!>
|
||||
0 -> <!EXPECTED_TYPE_MISMATCH!>fun named8(): Int {return 1}<!>
|
||||
else -> <!EXPECTED_TYPE_MISMATCH!>fun named9() = 1<!>
|
||||
}
|
||||
|
||||
val x31 = when (1) {
|
||||
0 -> {
|
||||
<!OI;EXPECTED_TYPE_MISMATCH!>fun <!NI;ANONYMOUS_FUNCTION_WITH_NAME!>named10<!>(): Int {return 1}<!>
|
||||
<!EXPECTED_TYPE_MISMATCH!>fun named10(): Int {return 1}<!>
|
||||
}
|
||||
else -> <!OI;EXPECTED_TYPE_MISMATCH!>fun <!NI;ANONYMOUS_FUNCTION_WITH_NAME!>named11<!>() = 1<!>
|
||||
else -> <!EXPECTED_TYPE_MISMATCH!>fun named11() = 1<!>
|
||||
}
|
||||
|
||||
val x4 = {
|
||||
@@ -55,5 +55,5 @@ fun success() {
|
||||
run2 { fun named2() = 1 }
|
||||
|
||||
val x = run { fun named3() = 1 }
|
||||
x checkType { _<Unit>() }
|
||||
x checkType { <!NI;DEBUG_INFO_UNRESOLVED_WITH_TARGET, NI;UNRESOLVED_REFERENCE_WRONG_RECEIVER!>_<!><Unit>() }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
|
||||
fun bar() {
|
||||
if (true) <!TYPE_MISMATCH!>{
|
||||
<!EXPECTED_TYPE_MISMATCH!>fun local() {
|
||||
}<!>
|
||||
}<!> else {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package
|
||||
|
||||
public fun bar(): kotlin.Unit
|
||||
@@ -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");
|
||||
|
||||
Generated
+5
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user