Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Jun 5, 2023

Conversation

t-kameyama
Copy link
Contributor

Fixes #6125

@codecov
Copy link

codecov bot commented May 25, 2023

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
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
@chao2zhang chao2zhang merged commit 8c2fe04 into detekt:main Jun 5, 2023
22 of 23 checks passed
@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