Do not report "redundant Unit return type" on expression bodies

So #KT-21983 Fixed
This commit is contained in:
Mikhail Glukhikh
2017-12-27 13:15:23 +03:00
parent 232ec63121
commit d7807b5ae3
2 changed files with 1 additions and 25 deletions
@@ -43,15 +43,7 @@ class RedundantUnitReturnTypeInspection : AbstractKotlinInspection(), CleanupLoc
val descriptor = context[BindingContext.FUNCTION, function] ?: return
if (descriptor.returnType?.isUnit() == true) {
if (!function.hasBlockBody()) {
val bodyExpression = function.bodyExpression
if (bodyExpression != null) {
val bodyContext = bodyExpression.analyze(BodyResolveMode.PARTIAL)
if (bodyContext.getType(bodyExpression)?.isNothing() == true) return
val resolvedCall = bodyExpression.getResolvedCall(bodyContext)
if (resolvedCall != null) {
if (resolvedCall.candidateDescriptor.returnType?.isUnit() != true) return
}
}
return
}
holder.registerProblem(typeElement,
@@ -15,14 +15,6 @@
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant 'Unit' return type</problem_class>
<description>Redundant Unit return type</description>
</problem>
<problem>
<file>Test.kt</file>
<line>8</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/Test.kt" />
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant 'Unit' return type</problem_class>
<description>Redundant Unit return type</description>
</problem>
<problem>
<file>Test.kt</file>
<line>12</line>
@@ -31,12 +23,4 @@
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant 'Unit' return type</problem_class>
<description>Redundant Unit return type</description>
</problem>
<problem>
<file>WithLambda.kt</file>
<line>11</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/WithLambda.kt" />
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant 'Unit' return type</problem_class>
<description>Redundant 'Unit' return type</description>
</problem>
</problems>