Fix nullable collection assertion constraints - #11374
Amaury Levé (Evangelink) merged 3 commits into
Conversation
Allow nullable elements in the concrete Contains and DoesNotContain overloads while preserving comparer contracts and C# 12 overload compatibility. Add nullable consumer compilation coverage and runtime regressions. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
The constraint changes are focused, compatibility-aware, and adequately covered by runtime and consumer-compilation tests.
Pull request overview
Fixes nullable collection constraints for MSTest containment assertions while preserving overload compatibility and behavior.
Changes:
- Allows nullable collection elements in concrete collection overloads.
- Adds runtime and C# 12 source-compatibility regressions.
- Verifies comparer, message, expression, and collection-comparer behavior.
File summaries
| File | Description |
|---|---|
Assert.Contains.cs |
Updates nullable constraints and forwarding. |
Assert.DoesNotContain.cs |
Applies equivalent nullable support. |
AssertTests.Contains.cs |
Adds runtime regression tests. |
AssertSourceCompatibilityTests.cs |
Expands C# 12 consumer call coverage. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Final test-triage resolution — Azure Pipelines build 1602049 This is a final (completed-build) analysis; no earlier preliminary comment was found to supersede. Result: 1 failing test out of 43 flagged candidates; all others passed or were skipped/slow-only.
Conclusion: Below the durable-issue threshold (single occurrence, clean history, no reproducible fail-then-pass or deterministic signature). No issue created. Recommend re-running the affected leg if it recurs; if it does, this looks like an async timing/cancellation race worth investigating in
|
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Amaury Levé (Evangelink)
left a comment
There was a problem hiding this comment.
Review result
No actionable findings. The nullable constraint change preserves the C# 12 overload-resolution fix, reference/value nullable call shapes, comparer behavior, caller expressions, and failure messages.
The original Azure Pipelines build 1602049 was red only because two Windows jobs failed while enabling local dumps and Linux hit the unrelated HotReloadTests.ShouldRunAsync_WaiterIsBlockedAndCancellationIsRequested_StopsNextRun timing failure. A fresh validation build (1602198) has been queued.
Coverage inventory
- Public API/source compatibility: generic constraints, explicit and implicit inference, arrays, interfaces, concrete collections, span-convertible collections, nullable reference/value elements, C# 12 consumers.
- Runtime behavior: default/custom comparers, collection-owned comparers, null elements, predicates, diagnostics, caller argument expressions, telemetry forwarding.
- Tests: assertion strength, negative paths, target-framework coverage, isolation/parallel safety, source-compatibility fixture effectiveness.
- Repository checks: XML documentation, API baselines, linked source, localization, security boundaries, dependencies, formatting/diff hygiene.
- Validation: focused framework unit tests passed on net48, net8.0, net8.0-windows, and net9.0; full build/pack completed with 0 warnings and 0 errors; both package-consuming C# 12 compatibility cases passed for net8.0 and net10.0.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Amaury Levé (Evangelink)
left a comment
There was a problem hiding this comment.
Note
🤖 Automated review by GitHub Copilot. To request a follow-up action, reply by tagging @copilot directly.
Review result
No actionable findings on current head aac076cd4.
The nullable TCollection constraint change fixes the C# 12 warning for non-null values used with nullable reference collections without changing the CLR generic constraint. The forwarding paths preserve default, collection-owned, nullable, and explicitly supplied comparer behavior, caller expressions, and failure messages. The added source-compatibility matrix exercises implicit overload resolution across arrays, interfaces, concrete collections, span-convertible collections, nullable references, and nullable values.
The separate Azure Pipelines change is also sound and documented in the PR description: it creates the WER LocalDumps registry key before assigning DumpFolder and DumpCount. Validation build 1602211 is green.
Verdict: ready for maintainer approval.
Coverage inventory
- Public API and source compatibility: generic constraints, nullable annotations, explicit/implicit inference, comparer variance, C# 12 package consumers, API baselines.
- Runtime behavior: default/custom comparers,
HashSet<T>collection comparer preservation, null elements, predicates, diagnostics, caller expressions, telemetry forwarding. - Tests: all 10 added regressions are present and passing on net8.0 and net48; both package-consuming source-compatibility cases pass.
- Cross-targeting: modern concrete-collection overloads and unchanged netstandard/.NET Framework fallback paths reviewed.
- CI change: registry provider behavior, idempotency, and successful Windows/Linux/macOS validation reviewed.
- Other dimensions: no concurrency, security-boundary, localization, dependency, serialization, or resource-lifetime impact.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
/backport to rel/4.4 |
|
Started backporting to rel/4.4: https://github.com/microsoft/testfx/actions/runs/35595117794 |
…(backport to rel/4.4) (#11408) Co-authored-by: Sergio Pedri <sergio0694@live.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Co-authored-by: Amaury Levé <amauryleve@microsoft.com>
Summary
Fix CS8631 when a non-null value is asserted against a collection of nullable elements, such as:
Assert.ContainsandAssert.DoesNotContainvalue overloads, including comparer overloads.ArraySegment,ImmutableArray, and dual-convertible collections.Verification
net8.0/net9.0) and unit tests (net8.0/net48)./*/*/AssertTests/*Contain*.AssertSourceCompatibilityTests.ConsumerSourcefixture directly against the locally built framework assemblies with SDK 8.0.424 / C# 12 /net8.0and SDK 10.0.401 / C# 12 and C# 14 /net10.0. This was direct consumer compilation, not a claim that the entire acceptance test harness was run.CI follow-up
The Azure Pipelines retry showed that the Windows agent image no longer pre-creates the WER
LocalDumpsregistry key. The pipeline now creates that key before configuringDumpFolderandDumpCount, allowing the Windows build legs to reach the actual build and test steps.Validation build
1602211passed all Windows, Linux, and macOS legs.