Do not report "redundant Unit return type" on expression bodies
So #KT-21983 Fixed
This commit is contained in:
@@ -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,
|
||||
|
||||
-16
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user