Skip to content

Extend PropertyUsedBeforeDeclaration to follow private init calls#9334

Open
ShubhamWorks02 wants to merge 1 commit into
detekt:mainfrom
ShubhamWorks02:indirect-property-used-before-declaration
Open

Extend PropertyUsedBeforeDeclaration to follow private init calls#9334
ShubhamWorks02 wants to merge 1 commit into
detekt:mainfrom
ShubhamWorks02:indirect-property-used-before-declaration

Conversation

@ShubhamWorks02

Copy link
Copy Markdown
Contributor

PropertyUsedBeforeDeclaration can detect direct property reads before declaration, but it can miss construction-time access when an init block or property initializer calls a private same-class helper function.

For example, this is unsafe during construction because setup() runs before isValid is initialized:

class C {
    init {
        setup()
    }

    private val isValid = true

    private fun setup() {
        println(isValid)
    }
}

@codecov

codecov Bot commented May 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.63636% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.72%. Comparing base (63e0777) to head (6546a7b).

Files with missing lines Patch % Lines
...les/potentialbugs/PropertyUsedBeforeDeclaration.kt 83.63% 2 Missing and 7 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #9334      +/-   ##
============================================
- Coverage     84.72%   84.72%   -0.01%     
+ Complexity     4486     4478       -8     
============================================
  Files           571      571              
  Lines         12423    12463      +40     
  Branches       2767     2780      +13     
============================================
+ Hits          10526    10559      +33     
- Misses          696      698       +2     
- Partials       1201     1206       +5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ShubhamWorks02 ShubhamWorks02 force-pushed the indirect-property-used-before-declaration branch from c96cca3 to f4ac770 Compare May 22, 2026 09:17
@ShubhamWorks02 ShubhamWorks02 force-pushed the indirect-property-used-before-declaration branch from f4ac770 to 50cb771 Compare June 3, 2026 05:51
@cortinico cortinico added this to the 2.0.0 milestone Jun 3, 2026
@ShubhamWorks02 ShubhamWorks02 force-pushed the indirect-property-used-before-declaration branch from 50cb771 to 48a5c98 Compare June 9, 2026 12:45
@ShubhamWorks02 ShubhamWorks02 force-pushed the indirect-property-used-before-declaration branch from 48a5c98 to 6546a7b Compare June 13, 2026 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants