Field Name Matches Class
ID |
kotlin.field_name_matches_class |
Severity |
info |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Naming Convention |
Language |
Kotlin |
Tags |
naming, readability |
Description
Reports a property declared inside a class whose name is identical (case-sensitive) to the enclosing class name. The compiler accepts the code, but the duplicated identifier creates visual ambiguity between the type and the property at every reference site.
Rationale
Identifier collisions between a class and one of its members make the code harder to read and harder to refactor: tools that operate on identifiers (rename, find-usages) must disambiguate by symbol kind, and human readers must mentally do the same. Choosing a different name for the property removes the ambiguity at no cost.
class Foo {
val Foo = 0 // FLAW — property name equals class name
val foo = 1 // OK — different identifier
}