fix(mocks): CS9262 in generated mock members on VS 17.14 (Roslyn 4.14)#6392
Conversation
… polyfills VS 17.14 (Roslyn 4.14) rejects the attribute on non-indexer extension properties with CS9262, so the generated *_MockMembers.g.cs failed to compile for any mocked type on that compiler. The attribute ranked nothing anyway: the polyfill is skipped entirely when the mocked type declares a member of the same name, so no same-name competition can exist within the containing type. Method polyfills keep the attribute (legal on methods since Roslyn 4.12). Fixes #6370
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. Summary: This is a narrowly-scoped fix for #6370 (CS9262 under VS 17.14/Roslyn 4.14). Verified independently:
🤖 Generated with automated code review |
Summary
Fixes #6370 — since v1.44.0, any
Type.Mock()usage failed to compile under Visual Studio 17.14 with:Root cause
The
*_MockMembers.g.cspolyfills introduced in #5881 apply[OverloadResolutionPriority(-1)]to the three extension-block properties (Invocations,Behavior,DefaultValueProvider) — hence exactly three errors. Roslyn 4.14 (VS 17.14) rejects the attribute on non-indexer extension properties with CS9262; the Roslyn shipped with the .NET 10 SDK accepts it, which is why CI and local builds never caught it.Fix
Remove the attribute from the property polyfills only. It was inert there: the polyfill is skipped whenever the mocked type declares a member of the same name, so no same-name member can coexist in the containing type for the attribute to rank against. Method polyfills keep it — the attribute is legal on ordinary static methods since Roslyn 4.12.
Testing
TUnit.Mocks.SourceGenerator.Tests: 76/76 pass; all 58 affected snapshots re-verified — every diff is purely the three attribute-line removals.TUnit.Mocks.Tests(net10.0): 1158/1158 pass —mock.Invocations/mock.Behavior/mock.DefaultValueProviderergonomics unchanged.