Repository: JetBrains/kotlin
File: compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirDeclarationCheckerUtils.kt (Kotlin)

Code before:
// Note that the class that contains the currently visiting declaration will *not* be in the context's containing declarations *yet*.
internal fun isInsideExpectClass(containingDeclaration: FirRegularClass, context: CheckerContext): Boolean =
    containingDeclaration.isExpect || context.containingDeclarations.asReversed().any { it is FirRegularClass && it.isExpect }

// TODO: check class too
internal fun checkExpectDeclarationVisibilityAndBody(
    declaration: FirMemberDeclaration,
    source: FirSourceElement,
    modifierList: FirModifierList?,
    reporter: DiagnosticReporter,
    context: CheckerContext
) {
    if (declaration.isExpect || modifierList?.modifiers?.any { it.token == KtTokens.EXPECT_KEYWORD } == true) {
        if (Visibilities.isPrivate(declaration.visibility)) {
            reporter.reportOn(source, FirErrors.EXPECTED_PRIVATE_DECLARATION, context)
        }
        if (declaration is FirSimpleFunction && declaration.hasBody) {
            reporter.reportOn(source, FirErrors.EXPECTED_DECLARATION_WITH_BODY, context)
        }
    }
}

internal fun checkProperty(
    containingClass: FirRegularClass?,
    property: FirProperty,
    modifierList: FirModifierList?,
    reporter: DiagnosticReporter,
    context: CheckerContext
) {
    val inInterface = containingClass?.isInterface == true
    val hasAbstractModifier = modifierList?.modifiers?.any { it.token == KtTokens.ABSTRACT_KEYWORD } == true
    val isAbstract = property.isAbstract || hasAbstractModifier
    if (isAbstract) {
        if (property.initializer == null && property.delegate == null && property.returnTypeRef is FirImplicitTypeRef) {
            property.source?.let {
                reporter.reportOn(it, FirErrors.PROPERTY_WITH_NO_TYPE_NO_INITIALIZER, context)
            }
        }
        return
    }

    val backingFieldRequired = property.hasBackingField
    if (inInterface && backingFieldRequired && property.hasAccessorImplementation) {
        property.source?.let {
            reporter.reportOn(it, FirErrors.BACKING_FIELD_IN_INTERFACE, context)
        }
    }

    property.setter?.source?.let {
        if (property.isVal) {
            reporter.reportOn(it, FirErrors.VAL_WITH_SETTER, context)

Review comment (suggestion):
Perhaps this is quite personal/cosmetic issue, but I still prefer to separate stuff in some logical chunk, like checkPropertyInitializer, checkPropertyAccessors, etc., then you can still use this, checkProperty, as a one entry point.

Code after:
import org.jetbrains.kotlin.fir.types.FirImplicitTypeRef
import org.jetbrains.kotlin.lexer.KtTokens

// Note that the class that contains the currently visiting declaration will *not* be in the context's containing declarations *yet*.
internal fun isInsideExpectClass(containingDeclaration: FirRegularClass, context: CheckerContext): Boolean =
    containingDeclaration.isExpect || context.containingDeclarations.asReversed().any { it is FirRegularClass && it.isExpect }

// TODO: check class too
internal fun checkExpectDeclarationVisibilityAndBody(
    declaration: FirMemberDeclaration,
    source: FirSourceElement,
    modifierList: FirModifierList?,
    reporter: DiagnosticReporter,
    context: CheckerContext
) {
    if (declaration.isExpect || modifierList?.modifiers?.any { it.token == KtTokens.EXPECT_KEYWORD } == true) {
        if (Visibilities.isPrivate(declaration.visibility)) {
            reporter.reportOn(source, FirErrors.EXPECTED_PRIVATE_DECLARATION, context)
        }
        if (declaration is FirSimpleFunction && declaration.hasBody) {
            reporter.reportOn(source, FirErrors.EXPECTED_DECLARATION_WITH_BODY, context)
        }
    }
}

internal fun checkProperty(
    containingClass: FirRegularClass?,
    property: FirProperty,
    modifierList: FirModifierList?,
    reporter: DiagnosticReporter,
    context: CheckerContext
) {
    checkPropertyInitializer(containingClass, modifierList, property, reporter, context)
    checkPropertyAccessors(property, reporter, context)
}

private fun checkPropertyInitializer(
    containingClass: FirRegularClass?,
    modifierList: FirModifierList?,
    property: FirProperty,
    reporter: DiagnosticReporter,
    context: CheckerContext
) {
    val inInterface = containingClass?.isInterface == true
    val hasAbstractModifier = modifierList?.modifiers?.any { it.token == KtTokens.ABSTRACT_KEYWORD } == true
    val isAbstract = property.isAbstract || hasAbstractModifier
    if (isAbstract) {
        if (property.initializer == null && property.delegate == null && property.returnTypeRef is FirImplicitTypeRef) {
            property.source?.let {
                reporter.reportOn(it, FirErrors.PROPERTY_WITH_NO_TYPE_NO_INITIALIZER, context)
            }