Skip to content

fix: preserve protected internal accessibility on overridden members#788

Merged
vbreuss merged 1 commit into
mainfrom
fix/protected-internal-override-accessibility
May 21, 2026
Merged

fix: preserve protected internal accessibility on overridden members#788
vbreuss merged 1 commit into
mainfrom
fix/protected-internal-override-accessibility

Conversation

@vbreuss
Copy link
Copy Markdown
Member

@vbreuss vbreuss commented May 21, 2026

When overriding a protected internal virtual member, the override must remain protected internal whenever the overriding code can see the declaring assembly's internals (same assembly or InternalsVisibleTo). Mapping unconditionally to protected produced CS0507 in those cases.

Resolve the override accessibility once at entity construction with the source assembly in scope, and emit the resolved string from the method, property, accessor, and event sites.

When overriding a `protected internal virtual` member, the override must remain `protected internal` whenever the overriding code can see the declaring assembly's internals (same assembly or InternalsVisibleTo). Mapping unconditionally to `protected` produced CS0507 in those cases.

Resolve the override accessibility once at entity construction with the source assembly in scope, and emit the resolved string from the method, property, accessor, and event sites.
@vbreuss vbreuss self-assigned this May 21, 2026
@vbreuss vbreuss added the bug Something isn't working label May 21, 2026
@vbreuss vbreuss enabled auto-merge (squash) May 21, 2026 16:48
@sonarqubecloud
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown

Test Results

    24 files  ±0      24 suites  ±0   9m 27s ⏱️ - 2m 36s
 4 149 tests +1   4 147 ✅ +1  2 💤 ±0  0 ❌ ±0 
26 691 runs  +3  26 687 ✅ +3  4 💤 ±0  0 ❌ ±0 

Results for commit 79dcd86. ± Comparison against base commit e61557f.

@vbreuss vbreuss merged commit 40c98b2 into main May 21, 2026
17 checks passed
@vbreuss vbreuss deleted the fix/protected-internal-override-accessibility branch May 21, 2026 16:54
@github-actions
Copy link
Copy Markdown

🚀 Benchmark Results

Details

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

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

CreateMock Mean Error StdDev Ratio Allocated Alloc Ratio
baseline* 62.69 ns 1.883 ns 1.761 ns 0.91 440 B 1.00
Mockolate 68.53 ns 2.066 ns 1.933 ns 1.00 440 B 1.00
Imposter 325.00 ns 10.851 ns 10.150 ns 4.75 2248 B 5.11
TUnitMocks 38.15 ns 0.633 ns 0.592 ns 0.56 192 B 0.44
Moq 1,476.43 ns 4.010 ns 3.555 ns 21.56 2096 B 4.76
NSubstitute 2,107.11 ns 30.251 ns 28.297 ns 30.77 5048 B 11.47
FakeItEasy 1,903.72 ns 31.910 ns 29.849 ns 27.80 2763 B 6.28
Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
Intel Xeon Platinum 8370C CPU 2.80GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.300
[Host] : .NET 10.0.8 (10.0.8, 10.0.826.23019), X64 RyuJIT x86-64-v4

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

Indexer N Mean Error StdDev Ratio Allocated Alloc Ratio
baseline* 1 925.6 ns 29.30 ns 25.97 ns 0.88 3.82 KB 1.00
Mockolate 1 1.046 μs 0.0181 μs 0.0169 μs 1.00 3.82 KB 1.00
Imposter 1 1.028 μs 0.0331 μs 0.0293 μs 0.98 5.16 KB 1.35
Moq 1 167.384 μs 0.5777 μs 0.4824 μs 160.11 20.47 KB 5.36
NSubstitute 1 9.430 μs 0.0211 μs 0.0187 μs 9.02 12.84 KB 3.36
FakeItEasy 1 11.983 μs 0.0430 μs 0.0402 μs 11.46 13.95 KB 3.65
baseline* 10 2,355.9 ns 7.12 ns 6.31 ns 0.82 4.88 KB 1.00
Mockolate 10 2.859 μs 0.0062 μs 0.0051 μs 1.00 4.88 KB 1.00
Imposter 10 2.476 μs 0.0141 μs 0.0132 μs 0.87 7.97 KB 1.63
Moq 10 178.707 μs 1.7028 μs 1.5928 μs 62.51 30 KB 6.15
NSubstitute 10 22.864 μs 0.0411 μs 0.0343 μs 8.00 26.13 KB 5.36
FakeItEasy 10 25.006 μs 0.0961 μs 0.0803 μs 8.75 33.31 KB 6.83
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.300
[Host] : .NET 10.0.8 (10.0.8, 10.0.826.23019), X64 RyuJIT x86-64-v3

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

Callback Mean Error StdDev Ratio Allocated Alloc Ratio
baseline* 324.6 ns 3.66 ns 3.24 ns 0.82 1.68 KB 1.00
Mockolate 397.3 ns 9.54 ns 8.92 ns 1.00 1.68 KB 1.00
Imposter 520.0 ns 9.77 ns 9.14 ns 1.31 2.38 KB 1.42
TUnitMocks 545.8 ns 11.48 ns 10.74 ns 1.37 1.86 KB 1.11
Moq 102,721.3 ns 1,165.24 ns 1,089.97 ns 258.65 8.88 KB 5.29
NSubstitute 4,820.7 ns 33.51 ns 31.35 ns 12.14 7.74 KB 4.61
FakeItEasy 5,248.7 ns 34.53 ns 30.61 ns 13.22 6.81 KB 4.05
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.300
[Host] : .NET 10.0.8 (10.0.8, 10.0.826.23019), X64 RyuJIT x86-64-v3

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

Property N Mean Error StdDev Ratio Allocated Alloc Ratio
baseline* 1 805.7 ns 2.86 ns 2.53 ns 1.53 2.47 KB 1.00
Mockolate 1 525.4 ns 16.09 ns 15.05 ns 1.00 2.47 KB 1.00
Imposter 1 448.6 ns 5.51 ns 4.60 ns 0.85 3.13 KB 1.27
TUnitMocks 1 403.9 ns 4.86 ns 4.30 ns 0.77 1.49 KB 0.60
Moq 1 10,325.0 ns 79.49 ns 74.36 ns 19.67 10.39 KB 4.21
NSubstitute 1 6,746.7 ns 35.97 ns 33.64 ns 12.85 11.45 KB 4.64
FakeItEasy 1 7,096.3 ns 92.55 ns 82.04 ns 13.52 11.24 KB 4.55
baseline* 10 991.3 ns 5.96 ns 5.29 ns 0.98 2.96 KB 1.00
Mockolate 10 1,009.9 ns 12.14 ns 10.14 ns 1.00 2.96 KB 1.00
Imposter 10 1,056.7 ns 9.08 ns 8.49 ns 1.05 4.67 KB 1.58
TUnitMocks 10 1,408.6 ns 17.08 ns 15.98 ns 1.39 3.65 KB 1.23
Moq 10 17,135.9 ns 284.94 ns 266.53 ns 16.97 18.28 KB 6.17
NSubstitute 10 16,369.1 ns 114.85 ns 101.81 ns 16.21 21.08 KB 7.12
FakeItEasy 10 17,723.8 ns 122.71 ns 102.46 ns 17.55 30.81 KB 10.40
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.300
[Host] : .NET 10.0.8 (10.0.8, 10.0.826.23019), X64 RyuJIT x86-64-v3

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

Method N Mean Error StdDev Ratio Allocated Alloc Ratio
baseline* 1 342.7 ns 2.36 ns 1.97 ns 0.94 2.04 KB 1.00
Mockolate 1 364.6 ns 6.55 ns 6.13 ns 1.00 2.04 KB 1.00
Imposter 1 530.3 ns 4.69 ns 4.16 ns 1.45 4.04 KB 1.98
TUnitMocks 1 456.1 ns 4.97 ns 4.41 ns 1.25 1.88 KB 0.92
Moq 1 130,670.2 ns 755.64 ns 669.85 ns 358.47 14.58 KB 7.15
NSubstitute 1 5,333.9 ns 79.35 ns 74.22 ns 14.63 9.12 KB 4.47
FakeItEasy 1 5,359.6 ns 51.99 ns 48.64 ns 14.70 8.05 KB 3.95
baseline* 10 651.8 ns 4.79 ns 4.48 ns 1.00 2.25 KB 1.00
Mockolate 10 653.0 ns 4.52 ns 4.22 ns 1.00 2.25 KB 1.00
Imposter 10 1,081.1 ns 11.83 ns 11.06 ns 1.66 5.52 KB 2.45
TUnitMocks 10 1,254.5 ns 10.94 ns 10.23 ns 1.92 3.52 KB 1.57
Moq 10 135,467.0 ns 548.94 ns 458.39 ns 207.46 18.48 KB 8.21
NSubstitute 10 7,842.0 ns 85.79 ns 80.24 ns 12.01 12.07 KB 5.37
FakeItEasy 10 8,255.8 ns 41.63 ns 36.90 ns 12.64 15.42 KB 6.85
Details

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

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

Event Mean Error StdDev Ratio Allocated Alloc Ratio
baseline* 337.2 ns 13.64 ns 12.76 ns 1.09 1.78 KB 1.00
Mockolate 310.4 ns 4.47 ns 3.96 ns 1.00 1.78 KB 1.00
Imposter 1,292.4 ns 9.03 ns 7.54 ns 4.16 8.8 KB 4.94
TUnitMocks 170.7 ns 1.12 ns 0.99 ns 0.55 1.34 KB 0.75
Moq 13,994.3 ns 95.51 ns 84.67 ns 45.09 12.51 KB 7.02
NSubstitute 5,002.4 ns 10.85 ns 9.62 ns 16.12 9.05 KB 5.08
FakeItEasy 229,548.2 ns 731.79 ns 611.08 ns 739.64 15.26 KB 8.57

baseline* rows show the corresponding Mockolate benchmark from the most recent successful main branch build with results, for regression comparison.

github-actions Bot added a commit that referenced this pull request May 21, 2026
…ibility on overridden members (#788) by Valentin Breuß
github-actions Bot added a commit that referenced this pull request May 21, 2026
…ibility on overridden members (#788) by Valentin Breuß
@github-actions
Copy link
Copy Markdown

This is addressed in release v3.2.1.

@github-actions github-actions Bot added the state: released The issue is released label May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working state: released The issue is released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant