Skip to content

Do not report IgnoredReturnValue on lambda invocation that returns Unit#9192

Merged
schalkms merged 3 commits into
detekt:mainfrom
UnguidedFreedom:lambda_invoke_unit
Mar 27, 2026
Merged

Do not report IgnoredReturnValue on lambda invocation that returns Unit#9192
schalkms merged 3 commits into
detekt:mainfrom
UnguidedFreedom:lambda_invoke_unit

Conversation

@UnguidedFreedom
Copy link
Copy Markdown
Contributor

@UnguidedFreedom UnguidedFreedom commented Mar 26, 2026

Closes #9183

Check the return type from the function call's signature rather than from the symbol to remove false positives of IgnoredReturnValue on lambda invocations that return Unit.

This is because the symbol's returnType is R because the symbol itself is the invoke method, but the signature holds the actual lambda's signature and therefore correctly identified Unit as the return type.

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 27, 2026

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 85.01%. Comparing base (31af635) to head (c04dbdf).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...v/detekt/rules/potentialbugs/IgnoredReturnValue.kt 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #9192      +/-   ##
============================================
- Coverage     85.03%   85.01%   -0.02%     
+ Complexity     4439     4434       -5     
============================================
  Files           571      571              
  Lines         12335    12336       +1     
  Branches       2694     2694              
============================================
- Hits          10489    10488       -1     
  Misses          681      681              
- Partials       1165     1167       +2     

☔ View full report in Codecov by Sentry.
📢 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.

@UnguidedFreedom UnguidedFreedom marked this pull request as ready for review March 27, 2026 00:20
@schalkms schalkms added this to the 2.0.0 milestone Mar 27, 2026
@schalkms
Copy link
Copy Markdown
Member

Thank you very much!
Nice 1st PR contribution!

@schalkms schalkms merged commit 4fa9049 into detekt:main Mar 27, 2026
19 of 21 checks passed
@sschuberth
Copy link
Copy Markdown
Contributor

Just checking can it be that this change triggers a new false-positive when upgrading from v2.0.0-alpha.2 to v2.0.0-alpha.3 in code like this:

elementFunctions[qName]?.also { f ->
    currentState = f(currentState, attributes, bodyContent.toString())
}

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.

IgnoredReturnValue false positives for anonymous functions that return Unit

5 participants