Repository navigation
Fix VSTHRD107 to detect unawaited tasks in using variable declarations - #1698
Austin (AustinAviv) wants to merge 1 commit into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
🟡 Changes recommended
Some offered fixes produce uncompilable code for unsupported containing functions or tasks without disposable results.
1 open finding
What changed in this PR
Expands VSTHRD107 to detect unawaited tasks in using declarations and updates its code fix.
Changes:
- Analyzes using-statement and C# 8 using-declaration initializers.
- Reworks code-fix expression replacement.
- Adds documentation and test coverage.
| File | Description |
|---|---|
VSTHRD107AwaitTaskWithinUsingExpressionAnalyzerTests.cs |
Tests new declaration forms. |
VSTHRD107AwaitTaskWithinUsingExpressionAnalyzer.cs |
Analyzes using-variable initializers. |
VSTHRD107AwaitTaskWithinUsingExpressionCodeFix.cs |
Adds await to diagnosed expressions. |
VSTHRD107.md |
Documents supported forms. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Hi, could any maintainer please review and approve this PR when you get a chance? I'd like to check the workflow test results to see how many tests passed and failed. Thank you! |
|
Hi maintainers, could you please approve the workflow run for this PR? Thank you! |
|
Austin (@AustinAviv) I approved the workflows to run. I'll defer to Andrew Arnott (@AArnott) for the actual merge. |
Hi Andrew Arnott (@AArnott) Drew Noakes (@drewnoakes), thanks, Drew, for approving the previous workflow run! Could you please approve the new workflow run as well if approval is required? Andrew, when you get a chance, I'd appreciate your review of this PR. I'm happy to address any feedback or make further changes. Thanks both for your time and support! |

Fixes #1697
Description
This PR expands VSTHRD107AwaitTaskWithinUsingExpressionAnalyzer and VSTHRD107AwaitTaskWithinUsingExpressionCodeFix to detect and fix unawaited Task / Task expressions when used within using variable declarations:
Background
Because Task implements IDisposable, storing an unawaited task in a using variable declaration compiles without warning, but disposes the unawaited task instance instead of awaiting the releaser.
Previously, VSTHRD107 only inspected UsingStatementSyntax.Expression. It missed declaration forms, and VSTHRD107AwaitTaskWithinUsingExpressionCodeFix threw an exception when .Expression was null.
Changes