[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:
Mikhail Zarechenskiy
2018-07-10 13:13:03 +03:00
parent eb745133c9
commit 2be08f4d60
6 changed files with 35 additions and 6 deletions
@@ -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,