Remove the dead Roslyn 4.4 workaround from MA0099 - #1412
Merged
Merged
Conversation
The guard was written as `#if !ROSLYN4_5_OR_GREATER`, but the constants the Meziantou.Framework.Roslyn package defines are named ROSLYN_<major>_<minor>_OR_GREATER. ROSLYN4_5_OR_GREATER, missing the underscore after ROSLYN, is never defined, and an undefined constant is not an error for the C# compiler: it is simply false. The negation therefore made the condition always true, so the workaround was compiled into every supported Roslyn version instead of none of them. The workaround comes from #526 and only applies to Roslyn 4.4 and below, where the conversion of a default parameter value in an attribute had the Attribute node as its syntax. The minimum supported version is 4.8, so spelling the constant correctly would exclude the block from all five builds: the code is dead either way, and removing it is the fix rather than repairing the typo. The block was live, not skipped, so its removal is a change to the compiled code. ImplicitParameterInAttribute, the test added with the workaround, covers both the implicit default value it was meant to ignore and the explicit zero that must still be reported; it passes on Roslyn 4.8 through 5.9, confirming the block never matched on any supported version.
meziantou
enabled auto-merge (squash)
September 6, 2026 04:22
This was referenced Sep 6, 2026
Closed
This was referenced Sep 17, 2026
Open
Open
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Removes a
#if-guarded block fromDoNotUseZeroToInitializeAnEnumValue(MA0099) whose guard used a constant that is never defined.Why
The constants come from the
Meziantou.Framework.Roslynpackage and are namedROSLYN_<major>_<minor>_OR_GREATER.ROSLYN4_5_OR_GREATERis missing the underscore afterROSLYN— it is the only one of the nineROSLYN*/CSHARP*identifiers used in a#ifacrosssrcandteststhat is misspelled.An undefined constant is not an error for the C# compiler, it is simply false, so
!made the condition always true. The block was therefore compiled into all five builds rather than excluded from them — the typo inverted the guard rather than merely disabling it.The workaround comes from #526 and only applies to Roslyn 4.4 and below, where the conversion of a default parameter value in an attribute had the
Attributenode as its syntax. The minimum supported version is now 4.8, so spelling the constant correctly would exclude the block from every supported build. The code is dead either way, which is why this removes it rather than repairing the typo.For reviewers
Because the block was live rather than skipped, removing it changes the compiled code, so this needed test evidence rather than inspection.
ImplicitParameterInAttribute— the test added alongside the workaround — covers both the implicit default value the block was meant to ignore and the explicit0that must still be reported. It passes on every supported version, confirming the block never matched.Verified:
dotnet buildsucceeds with 0 warnings across roslyn4.8, 4.14, 5.0, 5.6 and 5.9.DoNotUseZeroToInitializeAnEnumValueTestscases pass on each of the five versions.dotnet run --project src/DocumentationGeneratorexits 0 with no markdown changes.