Skip to content

fix: rename methodSetup local in setup impl to avoid parameter name collision#722

Merged
vbreuss merged 1 commit into
mainfrom
topic/avoid-parameter-name-collision
Apr 29, 2026
Merged

fix: rename methodSetup local in setup impl to avoid parameter name collision#722
vbreuss merged 1 commit into
mainfrom
topic/avoid-parameter-name-collision

Conversation

@vbreuss
Copy link
Copy Markdown
Member

@vbreuss vbreuss commented Apr 29, 2026

This pull request addresses a variable naming collision issue in the generated mock setup code, ensuring that local variables do not conflict with method parameter names. It also adds a test to verify that methods with parameters named setup or methodSetup compile correctly.

Fixes for variable naming collisions in generated code:

  • Updated AppendMethodSetupImplementation in Sources.MockClass.cs to generate unique local variable names for method setup variables, preventing conflicts with parameter names.
  • Replaced hardcoded "methodSetup" variable names with a unique name throughout the method setup code, including in return statements and registry setup calls.

@vbreuss vbreuss self-assigned this Apr 29, 2026
@vbreuss vbreuss added the bug Something isn't working label Apr 29, 2026
@vbreuss vbreuss enabled auto-merge (squash) April 29, 2026 18:35
@github-actions
Copy link
Copy Markdown

Test Results

    21 files  ±0      21 suites  ±0   9m 53s ⏱️ + 1m 20s
 3 849 tests +1   3 848 ✅ +1  1 💤 ±0  0 ❌ ±0 
25 061 runs  +3  25 060 ✅ +3  1 💤 ±0  0 ❌ ±0 

Results for commit 35439d9. ± Comparison against base commit d8827bb.

@vbreuss vbreuss merged commit 78fe402 into main Apr 29, 2026
14 checks passed
@vbreuss vbreuss deleted the topic/avoid-parameter-name-collision branch April 29, 2026 18:43
@sonarqubecloud
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 9V74 3.69GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.203
[Host] : .NET 10.0.7 (10.0.7, 10.0.726.21808), X64 RyuJIT x86-64-v4

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

Method Mean Error StdDev Ratio RatioSD Gen0 Gen1 Allocated Alloc Ratio
Event_Mockolate 273.2 ns 3.73 ns 3.49 ns 1.00 0.02 0.1254 0.0005 2.05 KB 1.00
Event_Moq 10,830.7 ns 147.98 ns 138.42 ns 39.65 0.69 0.7324 - 12.51 KB 6.09
Event_NSubstitute 4,061.1 ns 41.05 ns 38.40 ns 14.87 0.23 0.5493 0.0076 9.05 KB 4.40
Event_FakeItEasy 183,569.0 ns 703.20 ns 657.77 ns 672.01 8.58 0.7324 0.4883 15.39 KB 7.49
Event_Imposter 1,047.0 ns 16.36 ns 14.50 ns 3.83 0.07 0.5379 0.0153 8.8 KB 4.29
Event_TUnitMocks 135.7 ns 2.09 ns 1.96 ns 0.50 0.01 0.0837 0.0002 1.37 KB 0.67
Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 7763 2.85GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.203
[Host] : .NET 10.0.7 (10.0.7, 10.0.726.21808), X64 RyuJIT x86-64-v3

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

Method N Mean Error StdDev Ratio RatioSD Gen0 Gen1 Allocated Alloc Ratio
Indexer_Mockolate 1 1,000.3 ns 24.79 ns 23.19 ns 1.00 0.03 0.2460 0.0019 4.03 KB 1.00
Indexer_Moq 1 217,179.4 ns 1,699.04 ns 1,506.16 ns 217.22 5.04 0.9766 0.4883 20.48 KB 5.08
Indexer_NSubstitute 1 9,665.8 ns 158.42 ns 148.19 ns 9.67 0.26 0.7782 - 12.78 KB 3.17
Indexer_FakeItEasy 1 12,127.0 ns 148.44 ns 138.85 ns 12.13 0.30 0.8392 0.0305 13.88 KB 3.44
Indexer_Imposter 1 914.4 ns 35.48 ns 33.19 ns 0.91 0.04 0.3147 0.0038 5.16 KB 1.28
Indexer_Mockolate 10 2,529.8 ns 62.55 ns 58.51 ns 1.00 0.03 0.3090 - 5.09 KB 1.00
Indexer_Moq 10 228,237.4 ns 1,468.08 ns 1,301.41 ns 90.27 2.06 1.7090 1.4648 30 KB 5.90
Indexer_NSubstitute 10 24,024.6 ns 370.25 ns 346.33 ns 9.50 0.25 1.5564 0.0305 25.58 KB 5.03
Indexer_FakeItEasy 10 26,036.9 ns 442.07 ns 413.52 ns 10.30 0.28 2.1667 0.0610 35.47 KB 6.97
Indexer_Imposter 10 2,170.1 ns 24.29 ns 22.73 ns 0.86 0.02 0.4845 0.0076 7.97 KB 1.57
Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 9V74 2.60GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.203
[Host] : .NET 10.0.7 (10.0.7, 10.0.726.21808), X64 RyuJIT x86-64-v3

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

Method N Mean Error StdDev Ratio RatioSD Gen0 Gen1 Allocated Alloc Ratio
Method_Mockolate 1 463.6 ns 4.89 ns 4.57 ns 1.00 0.01 0.1416 0.0010 2.32 KB 1.00
Method_Moq 1 130,157.9 ns 658.98 ns 584.16 ns 280.75 2.98 0.4883 - 14.58 KB 6.28
Method_NSubstitute 1 5,383.9 ns 49.53 ns 46.33 ns 11.61 0.15 0.5569 0.0076 9.12 KB 3.93
Method_FakeItEasy 1 5,471.1 ns 52.40 ns 49.01 ns 11.80 0.15 0.4959 - 8.11 KB 3.50
Method_Imposter 1 575.1 ns 7.61 ns 7.12 ns 1.24 0.02 0.2470 0.0029 4.04 KB 1.74
Method_TUnitMocks 1 728.9 ns 5.64 ns 4.71 ns 1.57 0.02 0.1774 0.0010 2.9 KB 1.25
Method_Mockolate 10 754.3 ns 4.95 ns 4.13 ns 1.00 0.01 0.1545 0.0010 2.53 KB 1.00
Method_Moq 10 135,939.2 ns 499.32 ns 467.06 ns 180.23 1.13 0.9766 0.7324 18.48 KB 7.30
Method_NSubstitute 10 8,068.2 ns 56.12 ns 52.50 ns 10.70 0.09 0.7324 0.0153 12.07 KB 4.77
Method_FakeItEasy 10 8,541.3 ns 92.38 ns 81.90 ns 11.32 0.12 0.9766 0.0305 16.05 KB 6.34
Method_Imposter 10 1,220.7 ns 7.92 ns 7.41 ns 1.62 0.01 0.3376 0.0057 5.52 KB 2.18
Method_TUnitMocks 10 1,821.8 ns 9.67 ns 8.57 ns 2.42 0.02 0.2747 0.0019 4.49 KB 1.77
Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 7763 2.45GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.203
[Host] : .NET 10.0.7 (10.0.7, 10.0.726.21808), X64 RyuJIT x86-64-v3

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

Method N Mean Error StdDev Ratio RatioSD Gen0 Gen1 Allocated Alloc Ratio
Property_Mockolate 1 525.8 ns 3.86 ns 3.43 ns 1.00 0.01 0.1574 0.0010 2.58 KB 1.00
Property_Moq 1 11,822.8 ns 162.47 ns 151.97 ns 22.48 0.31 0.6104 - 10.39 KB 4.03
Property_NSubstitute 1 7,501.2 ns 49.93 ns 46.70 ns 14.27 0.12 0.6943 0.0076 11.45 KB 4.44
Property_FakeItEasy 1 8,322.6 ns 59.84 ns 53.04 ns 15.83 0.14 0.6866 - 11.24 KB 4.36
Property_Imposter 1 447.5 ns 2.61 ns 2.44 ns 0.85 0.01 0.1912 0.0019 3.13 KB 1.21
Property_TUnitMocks 1 848.7 ns 4.39 ns 4.11 ns 1.61 0.01 0.1526 0.0010 2.51 KB 0.97
Property_Mockolate 10 1,000.4 ns 6.79 ns 6.01 ns 1.00 0.01 0.1869 - 3.07 KB 1.00
Property_Moq 10 18,092.0 ns 62.87 ns 58.81 ns 18.09 0.12 1.0986 - 18.28 KB 5.95
Property_NSubstitute 10 17,040.2 ns 109.85 ns 102.75 ns 17.03 0.14 1.2817 0.0305 21.08 KB 6.87
Property_FakeItEasy 10 19,783.2 ns 128.76 ns 120.44 ns 19.78 0.16 1.8616 - 30.81 KB 10.03
Property_Imposter 10 1,083.5 ns 8.97 ns 8.39 ns 1.08 0.01 0.2842 0.0019 4.67 KB 1.52
Property_TUnitMocks 10 2,243.8 ns 12.03 ns 11.25 ns 2.24 0.02 0.2823 - 4.66 KB 1.52
Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 7763 2.69GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.203
[Host] : .NET 10.0.7 (10.0.7, 10.0.726.21808), X64 RyuJIT x86-64-v3

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

Method Mean Error StdDev Ratio RatioSD Gen0 Gen1 Allocated Alloc Ratio
Callback_Mockolate 434.5 ns 15.57 ns 14.57 ns 1.00 0.05 0.1197 - 1.96 KB 1.00
Callback_Moq 99,258.9 ns 466.86 ns 436.70 ns 228.67 7.39 0.4883 0.2441 8.88 KB 4.53
Callback_NSubstitute 4,703.3 ns 56.37 ns 47.07 ns 10.84 0.36 0.4730 0.0076 7.74 KB 3.95
Callback_FakeItEasy 4,987.2 ns 93.12 ns 87.10 ns 11.49 0.42 0.4120 0.0153 6.81 KB 3.47
Callback_Imposter 448.6 ns 15.82 ns 14.03 ns 1.03 0.05 0.1454 0.0010 2.38 KB 1.22
Callback_TUnitMocks 641.5 ns 33.60 ns 31.43 ns 1.48 0.08 0.1602 0.0010 2.63 KB 1.34

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant