I check these slices in this order
•
bindingContext.get(BindingContext.EXPRESSION_TYPE_INFO, functionExpression)
•
bindingContext.get(BindingContext.EXPRESSION_TYPE_INFO, functionExpression.bodyExpression)
•
bindingContext.get(BindingContext.EXPECTED_RETURN_TYPE, functionExpression)
• Get the type of the last expression in the block body (unwrapping certain expressions like returns to get the actual type other than Nothing) But then I get the true type, not the type of what’s downcast.
• If there’s a body with no statements then I assume it’s Unit, for my purposes
• If it’s
still null then: if its a KtNamedFunction I assume it’s Unit, otherwise it’s returning a class that isn’t in the Detekt classpath (Android SDK). Based on what I found during testing.
It
works but I can’t help but think there’s a better way/