mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
KTIJ-29230 [kotlin] Do not report Unit? as redundant return type in K2
`Unit?` return type does not allow empty and implicit returns, so it cannot be safely removed ^KTIJ-29230 Fixed GitOrigin-RevId: c9b593e99402cc8b5ce87dcef75fc4a97251b93b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
fb3c9478be
commit
af0c4015f3
+8
-3
@@ -42,9 +42,14 @@ internal class RedundantUnitReturnTypeInspection :
|
||||
}
|
||||
|
||||
context(KtAnalysisSession)
|
||||
override fun prepareContext(element: KtNamedFunction): TypeInfo? = when {
|
||||
element.getFunctionLikeSymbol().returnType.isUnit -> TypeInfo(TypeInfo.UNIT)
|
||||
else -> null
|
||||
override fun prepareContext(element: KtNamedFunction): TypeInfo? {
|
||||
val returnType = element.getFunctionLikeSymbol().returnType
|
||||
|
||||
if (!returnType.isMarkedNullable && returnType.isUnit) {
|
||||
return TypeInfo(TypeInfo.UNIT)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
override fun createQuickFix(
|
||||
|
||||
+5
@@ -4918,6 +4918,11 @@ public abstract class K2LocalInspectionTestGenerated extends AbstractK2LocalInsp
|
||||
runTest("../../../idea/tests/testData/inspectionsLocal/redundantUnitReturnType/expressionBodyUnitType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nullableUnit.kt")
|
||||
public void testNullableUnit() throws Exception {
|
||||
runTest("../../../idea/tests/testData/inspectionsLocal/redundantUnitReturnType/nullableUnit.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
runTest("../../../idea/tests/testData/inspectionsLocal/redundantUnitReturnType/simple.kt");
|
||||
|
||||
+5
@@ -10742,6 +10742,11 @@ public abstract class LocalInspectionTestGenerated extends AbstractLocalInspecti
|
||||
runTest("testData/inspectionsLocal/redundantUnitReturnType/expressionBodyUnitType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nullableUnit.kt")
|
||||
public void testNullableUnit() throws Exception {
|
||||
runTest("testData/inspectionsLocal/redundantUnitReturnType/nullableUnit.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
runTest("testData/inspectionsLocal/redundantUnitReturnType/simple.kt");
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// PROBLEM: none
|
||||
fun test(): <caret>Unit? {
|
||||
return null
|
||||
}
|
||||
Reference in New Issue
Block a user