Repository navigation
fix(mocks): preserve nullable base-class constraints - #7829
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Review of #7829The change is small and targeted, and I found nothing that needs fixing.
One optional follow-up: add a test for a type parameter constrained to another reference-type parameter (for example I read the diff and did not run the tests. LGTM. |
[Medium impact] This PR appears safe to merge; no actionable issues were found. SummaryThis PR fixes generated mock methods that use nullable generic values with base-class constraints.
No actionable issues found. Tests were inspected but not run during this review. Reviews (1) · Last reviewed commit: "fix(mocks): preserve nullable base-class..." · Reviewed by Greptile |
Description
Generic mock methods returning or accepting
T?failed to compile whenThad a base-class constraint. For example,Task<(T? act, string error)> ActFromInvoice<T>() where T : BaseAct, new()generated an explicit forward withoutwhere T : class, causing CS0453, CS9334, and CS0535.Record Roslyn's semantic
IsReferenceTypeclassification separately from the explicitclassconstraint and use it when formatting explicit implementations. Ordinary declarations retain their full original constraints, and interface-only or unconstrained parameters retaindefaulthandling.Related Issue
Fixes #7820
Type of Change
Checklist
Testing
Both affected suites pass on net10.0 and net11.0 with SDK 11.0.100:
dotnet test --project tests/TUnit.Mocks.SourceGenerator.Tests --framework <framework>: 254 passed per framework.dotnet test --project tests/TUnit.Mocks.Tests --framework <framework>: 1,542 passed per framework.New coverage includes:
Object.The generator test compiler predates C# 14, so compilation guards exclude diagnostics from static-extension convenience files only. Runtime tests compile the complete generated output with the SDK.
Additional Notes
This changes mock source generation; it adds no runtime reflection or public library API. Existing build warnings remain tracked in #7410, #7412, and #7828.
Summary by CodeRabbit