Skip to content

Audit analyzers for ValueTask support (#414) - #1675

Open
Andrew Arnott (AArnott) wants to merge 1 commit into
mainfrom
aarnott-valuetask-analyzer-support
Open

Audit analyzers for ValueTask support (#414)#1675
Andrew Arnott (AArnott) wants to merge 1 commit into
mainfrom
aarnott-valuetask-analyzer-support

Conversation

@AArnott

Copy link
Copy Markdown
Member

Fixes #414.

Audited all analyzers in Microsoft.VisualStudio.Threading.Analyzers for ValueTask/ValueTask<T> support:

  • VSTHRD111 (ConfigureAwait): already explicitly handles ValueTask.
  • VSTHRD011, VSTHRD109, VSTHRD200: use HasAsyncCompatibleReturnType/IsAsyncCompatibleReturnType, which already recognize ValueTask via its AsyncMethodBuilderAttribute.
  • VSTHRD110 and the "remove Async suffix" check in VSTHRD200: use AwaitableTypeTester, which discovers any type with a GetAwaiter method (including ValueTask) dynamically from the compilation.
  • VSTHRD012, VSTHRD108, VSTHRD001, VSTHRD004, VSTHRD100, VSTHRD106, VSTHRD116/117: not Task-type-specific to begin with; no gap applies.
  • VSTHRD114 (avoid returning null Task): its doc comment incorrectly claimed ValueTask support (likely copy-pasted from VSTHRD111). In reality, ValueTask/ValueTask<T> are value types, so return null; is a compile error (CS0037) and this code path can never be reached for them. Corrected the doc comment to explain why ValueTask isn't applicable here instead of implying non-existent support.

No behavioral analyzer gaps were found — only a misleading doc comment was corrected. All existing VSTHRD114 tests (24) continue to pass.

Audited all analyzers for issue #414 (ValueTask support). Found:
- VSTHRD111 (ConfigureAwait): already handles ValueTask explicitly.
- VSTHRD011, VSTHRD109, VSTHRD200: use HasAsyncCompatibleReturnType/IsAsyncCompatibleReturnType, which already recognize ValueTask via its AsyncMethodBuilderAttribute.
- VSTHRD110, VSTHRD200 Remove-suffix check: use AwaitableTypeTester, which discovers any type with a GetAwaiter method, including ValueTask.
- VSTHRD012, VSTHRD108, VSTHRD001, VSTHRD004, VSTHRD100, VSTHRD106, VSTHRD116/117: not Task-type-specific; no gap.
- VSTHRD114 (avoid returning null Task): its doc comment incorrectly claimed ValueTask support, but ValueTask/ValueTask<T> are value types so \
eturn null;\ is a compile error (CS0037) and can never reach this analyzer. Corrected the doc comment to explain this instead of implying non-existent support.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The change is limited to an accurate documentation correction and aligns with the stated PR intent without introducing behavioral risk.

Pull request overview

This PR addresses issue #414 by auditing the Microsoft.VisualStudio.Threading.Analyzers package for ValueTask/ValueTask<T> support, and concludes there were no analyzer behavior gaps. The only code change is a documentation correction for VSTHRD114 to remove misleading claims about ValueTask applicability.

Changes:

  • Corrected the XML documentation on AbstractVSTHRD114AvoidReturningNullTaskAnalyzer to accurately describe what the analyzer checks.
  • Added remarks explaining why ValueTask/ValueTask<T> are not applicable to the “return null task” pattern (value types; compiler prevents it).
File summaries
File Description
src/Microsoft.VisualStudio.Threading.Analyzers/AbstractVSTHRD114AvoidReturningNullTaskAnalyzer.cs Fixes incorrect/misleading doc comment and clarifies ValueTask non-applicability for VSTHRD114.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ValueTask support comprehensively to our analyzers

2 participants