Skip to content

Files

Latest commit

 

History

History
45 lines (30 loc) · 739 Bytes

PropertyUsedBeforeDeclaration.md

File metadata and controls

45 lines (30 loc) · 739 Bytes

Pattern: Property used before declaration

Issue: -

Description

Reports properties that are used before declaration.

Example of incorrect code:

class C {
    private val number
        get() = if (isValid) 1 else 0

    val list = listOf(number)

    private val isValid = true
}

fun main() {
    println(C().list) // [0]
}

Example of correct code:

class C {
    private val isValid = true

    private val number
        get() = if (isValid) 1 else 0

    val list = listOf(number)
}

fun main() {
    println(C().list) // [1]
}

Further Reading