[FIR] Fixes for RedundantReturnUnitType checker
This commit is contained in:
+8
@@ -1,4 +1,12 @@
|
||||
data class My(val x: Unit)
|
||||
|
||||
interface I {
|
||||
val x: Unit
|
||||
}
|
||||
|
||||
class A {
|
||||
fun too(): @Annotation Unit {}
|
||||
|
||||
fun foo(): <!REDUNDANT_RETURN_UNIT_TYPE!>Unit<!>
|
||||
{
|
||||
}
|
||||
|
||||
+21
@@ -1,9 +1,30 @@
|
||||
FILE: RedundantReturnUnitTypeChecker.kt
|
||||
public final data class My : R|kotlin/Any| {
|
||||
public constructor(x: R|kotlin/Unit|): R|My| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final val x: R|kotlin/Unit| = R|<local>/x|
|
||||
public get(): R|kotlin/Unit|
|
||||
|
||||
public final fun component1(): R|kotlin/Unit|
|
||||
|
||||
public final fun copy(x: R|kotlin/Unit| = this@R|/My|.R|/My.x|): R|My|
|
||||
|
||||
}
|
||||
public abstract interface I : R|kotlin/Any| {
|
||||
public abstract val x: R|kotlin/Unit|
|
||||
public get(): R|kotlin/Unit|
|
||||
|
||||
}
|
||||
public final class A : R|kotlin/Any| {
|
||||
public constructor(): R|A| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final fun too(): @R|kotlin/Annotation|() R|kotlin/Unit| {
|
||||
}
|
||||
|
||||
public final fun foo(): R|kotlin/Unit| {
|
||||
}
|
||||
|
||||
|
||||
+6
-1
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.extended
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirFakeSourceElement
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirBasicDeclarationChecker
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||
@@ -19,8 +20,12 @@ object RedundantReturnUnitType : FirBasicDeclarationChecker() {
|
||||
if (declaration !is FirSimpleFunction) return
|
||||
if (declaration.body is FirSingleExpressionBlock) return
|
||||
if (declaration.returnTypeRef.source == null) return
|
||||
if (declaration.source is FirFakeSourceElement<*>) return
|
||||
|
||||
if (declaration.returnTypeRef.isUnit) {
|
||||
val returnType = declaration.returnTypeRef
|
||||
if (returnType.annotations.isNotEmpty()) return
|
||||
|
||||
if (returnType.isUnit) {
|
||||
reporter.report(declaration.returnTypeRef.source, FirErrors.REDUNDANT_RETURN_UNIT_TYPE)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -20,4 +20,4 @@ abstract class AbstractDiagnosticCollectorComponent(private val collector: Abstr
|
||||
protected fun runCheck(block: (DiagnosticReporter) -> Unit) {
|
||||
collector.runCheck(block)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user