Skip to content

PropertyUsedBeforeDeclaration: fix false positive in nested/inner class - #6139

Merged
picklebento merged 1 commit into
detekt:mainfrom
t-kameyama:issue_6125
Jun 5, 2023
Merged

picklebento merged 1 commit into
detekt:mainfrom
t-kameyama:issue_6125

Conversation

@t-kameyama

Copy link
Copy Markdown
Contributor

Fixes #6125

@codecov

codecov Bot commented May 25, 2023

Copy link
Copy Markdown

Codecov Report

Merging #6139 (b048da0) into main (9258ea2) will not change coverage.
The diff coverage is 0.00%.

@@            Coverage Diff            @@
##               main    #6139   +/-   ##
=========================================
  Coverage     84.94%   84.94%           
- Complexity     4026     4027    +1     
=========================================
  Files           569      569           
  Lines         13498    13498           
  Branches       2381     2381           
=========================================
  Hits          11466    11466           
  Misses          869      869           
  Partials       1163     1163           
Impacted Files Coverage Δ
...detekt/rules/bugs/PropertyUsedBeforeDeclaration.kt 84.61% <0.00%> (ø)

Comment on lines +117 to +125
fun `used before declaration in inner class`() {
val code = """
class A {
inner class B {
val inner = outer
}
val outer = "value"
}
""".trimIndent()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth adding a similar test where the outer is a top-level property, and it is used from a normal class? That sounds like a normal use case.

class C {
    val inner = outer
}
val outer = "value"

in this case they're essentially not even nested, just sibling classes. Only Kotlin's syntax allows their declaration in one file.

@BraisGabin BraisGabin added this to the 2.0.0 milestone May 28, 2023
@picklebento
picklebento merged commit 8c2fe04 into detekt:main Jun 5, 2023
@t-kameyama
t-kameyama deleted the issue_6125 branch June 5, 2023 04:33
@cortinico cortinico added the pick request Marker for PRs that should be ported to the 1.0 release branch label Jul 15, 2023
cortinico pushed a commit to cortinico/detekt that referenced this pull request Jul 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pick request Marker for PRs that should be ported to the 1.0 release branch rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PropertyUsedBeforeDeclaration false positive nested usage of constant

7 participants