Avoid asserts in CodegenAnnotatingVisitor.isAdaptedCallableReference

In light classes mode, binding context may not have all the information
and this can fail, as for example was happening in the test
`diagnostics/tests/regressions/ea76264.kt`.
This commit is contained in:
Alexander Udalov
2020-04-08 19:21:30 +02:00
parent 9f758b4f25
commit 587cce4a23
@@ -373,11 +373,13 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid {
if (!resolvedCall.getValueArguments().isEmpty()) return true;
KotlinType callableReferenceType = bindingContext.getType(expression);
assert callableReferenceType != null : "No type for callable reference: " + expression.getText();
KotlinType callableReferenceReturnType = CollectionsKt.last(callableReferenceType.getArguments()).getType();
KotlinType functionReturnType = functionDescriptor.getReturnType();
assert functionReturnType != null : "No return type for function: " + functionDescriptor;
return KotlinBuiltIns.isUnit(callableReferenceReturnType) && !KotlinBuiltIns.isUnit(functionReturnType);
if (callableReferenceType != null) {
KotlinType callableReferenceReturnType = CollectionsKt.last(callableReferenceType.getArguments()).getType();
KotlinType functionReturnType = functionDescriptor.getReturnType();
return functionReturnType != null &&
KotlinBuiltIns.isUnit(callableReferenceReturnType) && !KotlinBuiltIns.isUnit(functionReturnType);
}
return false;
}
@Override