Skip to content

Comments

refactor: remove dead code in delegate source generation#333

Merged
vbreuss merged 2 commits intomainfrom
topic/refactor-dead-code-in-delegate
Dec 22, 2025
Merged

refactor: remove dead code in delegate source generation#333
vbreuss merged 2 commits intomainfrom
topic/refactor-dead-code-in-delegate

Conversation

@vbreuss
Copy link
Contributor

@vbreuss vbreuss commented Dec 22, 2025

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

@vbreuss vbreuss self-assigned this Dec 22, 2025
Copilot AI review requested due to automatic review settings December 22, 2025 14:11
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 new keyword is used to hide an inherited member, but this interface doesn't explicitly inherit from another interface with a MyMethod member in the visible context. If this is intentional shadowing, ensure the base interface is clearly documented; otherwise, remove the new keyword.
namespace Mockolate.SourceGenerators.Tests.Sources;

@github-actions
Copy link

github-actions bot commented Dec 22, 2025

Test Results

    14 files  ± 0      14 suites  ±0   5m 33s ⏱️ +17s
 1 786 tests + 3   1 785 ✅ + 3  1 💤 ±0  0 ❌ ±0 
11 951 runs  +13  11 950 ✅ +13  1 💤 ±0  0 ❌ ±0 

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.
Mockolate.SourceGenerators.Tests.MockGeneratorTests ‑ WhenUsingMockCreateFromOtherNamespace_ShouldNotBeIncluded
Mockolate.SourceGenerators.Tests.GeneralTests ‑ MultipleInterfacesWithSameName_ShouldAddSuffixToSetupAndVerifyMethods
Mockolate.SourceGenerators.Tests.MockGeneratorTests ‑ WhenUsingCustomMockGeneratorAttribute_ShouldNotBeIncluded
Mockolate.SourceGenerators.Tests.MockGeneratorTests ‑ WhenUsingIncorrectMockGeneratorAttribute_ShouldNotBeIncluded
Mockolate.Tests.MockTests+CreateTests ‑ With3Arguments_SecondAndThirdAreClasses_ShouldThrow

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Dec 22, 2025

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.3 LTS (Noble Numbat)
AMD EPYC 7763 2.59GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.101
[Host] : .NET 10.0.1 (10.0.1, 10.0.125.57005), X64 RyuJIT x86-64-v3

Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15
LaunchCount=1 WarmupCount=10

Method Mean Error StdDev Gen0 Gen1 Allocated
Simple_Mockolate 1.386 μs 0.0083 μs 0.0069 μs 0.2232 - 3.66 KB
Simple_Moq 179.173 μs 0.9192 μs 0.7676 μs 0.4883 - 14.55 KB
Simple_NSubstitute 5.472 μs 0.0203 μs 0.0190 μs 0.5569 0.0076 9.14 KB
Simple_FakeItEasy 6.394 μs 0.0280 μs 0.0262 μs 0.4959 - 8.11 KB

@vbreuss vbreuss enabled auto-merge (squash) December 22, 2025 14:20
@sonarqubecloud
Copy link

@vbreuss vbreuss merged commit d6d691f into main Dec 22, 2025
12 checks passed
@vbreuss vbreuss deleted the topic/refactor-dead-code-in-delegate branch December 22, 2025 14:25
@github-actions
Copy link

This is addressed in release v0.46.0.

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

Labels

state: released The issue is released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant