refactor: remove dead code in delegate source generation#333
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors delegate source generation code by removing dead/unreachable code paths, specifically eliminating unnecessary generic parameter constraint handling. The changes also include test updates to use nullable types and verify additional scenarios.
Key changes:
- Removed dead code for generic parameter constraints in delegate verification methods
- Updated tests to use nullable types (bool?) instead of non-nullable types
- Added new test cases for protected virtual members and duplicate type arguments
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/Mockolate.Tests/MockTests.CreateTests.cs | Added test for duplicate class type arguments in Mock.Create |
| Tests/Mockolate.SourceGenerators.Tests/TestHelpers/Generator.cs | Added CS0109 to ignored errors list for test validation |
| Tests/Mockolate.SourceGenerators.Tests/Sources/ForMockTests.ImplementClassTests.cs | Added MyProtectedService test cases and changed bool to bool? in indexer tests |
| Tests/Mockolate.SourceGenerators.Tests/Sources/ForMockTests.DelegateTests.cs | Updated delegate test to include out parameter instead of simple parameters |
| Tests/Mockolate.SourceGenerators.Tests/MockGeneratorTests.cs | Renamed test method and added new test for incorrect MockGenerator attribute usage |
| Tests/Mockolate.SourceGenerators.Tests/GeneralTests.cs | Added test for multiple interfaces with same name and reformatted typeof parameters |
| Source/Mockolate.SourceGenerators/Sources/Sources.ForMock.cs | Changed constructor count check from > 0 to is not null |
| Source/Mockolate.SourceGenerators/Sources/Sources.ForMock.Extensions.cs | Removed dead code for generic parameter constraints in delegate methods and simplified property name handling |
Comments suppressed due to low confidence (1)
Tests/Mockolate.SourceGenerators.Tests/Sources/ForMockTests.ImplementClassTests.cs:1
- The
newkeyword is used to hide an inherited member, but this interface doesn't explicitly inherit from another interface with aMyMethodmember in the visible context. If this is intentional shadowing, ensure the base interface is clearly documented; otherwise, remove thenewkeyword.
namespace Mockolate.SourceGenerators.Tests.Sources;
Tests/Mockolate.SourceGenerators.Tests/Sources/ForMockTests.ImplementClassTests.cs
Show resolved
Hide resolved
Test Results 14 files ± 0 14 suites ±0 5m 33s ⏱️ +17s Results for commit d2400e1. ± Comparison against base commit ad48888. This pull request removes 1 and adds 4 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
🚀 Benchmark ResultsDetails
|
|
|
This is addressed in release v0.46.0. |



This PR refactors delegate source generation code by removing dead/unreachable code paths, specifically eliminating unnecessary generic parameter constraint handling. The changes also include test updates to use nullable types and verify additional scenarios.
Key changes: