Skip to content

Remove the dead Roslyn 4.4 workaround from MA0099 - #1412

Merged
meziantou merged 1 commit into
mainfrom
feature/roslyn-version-guard-typo-949f1f
Sep 6, 2026
Merged

Remove the dead Roslyn 4.4 workaround from MA0099#1412
meziantou merged 1 commit into
mainfrom
feature/roslyn-version-guard-typo-949f1f

Conversation

@meziantou

Copy link
Copy Markdown
Owner

What

Removes a #if-guarded block from DoNotUseZeroToInitializeAnEnumValue (MA0099) whose guard used a constant that is never defined.

#if !ROSLYN4_5_OR_GREATER
    if (operation.Syntax.IsKind(Microsoft.CodeAnalysis.CSharp.SyntaxKind.Attribute))
        return;
#endif

Why

The constants come from the Meziantou.Framework.Roslyn package and are named ROSLYN_<major>_<minor>_OR_GREATER. ROSLYN4_5_OR_GREATER is missing the underscore after ROSLYN — it is the only one of the nine ROSLYN*/CSHARP* identifiers used in a #if across src and tests that 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 Attribute node 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 explicit 0 that must still be reported. It passes on every supported version, confirming the block never matched.

Verified:

  • dotnet build succeeds with 0 warnings across roslyn4.8, 4.14, 5.0, 5.6 and 5.9.
  • The 248 DoNotUseZeroToInitializeAnEnumValueTests cases pass on each of the five versions.
  • dotnet run --project src/DocumentationGenerator exits 0 with no markdown changes.

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
meziantou enabled auto-merge (squash) September 6, 2026 04:22
@meziantou
meziantou merged commit 9a30a7c into main Sep 6, 2026
13 checks passed
@meziantou
meziantou deleted the feature/roslyn-version-guard-typo-949f1f branch September 6, 2026 04:22
This was referenced Sep 6, 2026
This was referenced Sep 8, 2026
IhateTrains pushed a commit to ParadoxGameConverters/ImperatorToCK3 that referenced this pull request Sep 8, 2026
Updated
[Meziantou.Analyzer](https://github.com/meziantou/Meziantou.Analyzer)
from 3.0.203 to 3.0.228.

<details>
<summary>Release notes</summary>

_Sourced from [Meziantou.Analyzer's
releases](https://github.com/meziantou/Meziantou.Analyzer/releases)._

## 3.0.228

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.228>

## What's Changed
* Detect the ProcessStartInfo properties set outside of the initializer
by @​meziantou in
meziantou/Meziantou.Analyzer#1437


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.227...3.0.228

## 3.0.227

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.227>

## What's Changed
* Cover the untested analyzer and fixer paths and remove the dead ones
by @​meziantou in
meziantou/Meziantou.Analyzer#1436


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.226...3.0.227

## 3.0.226

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.226>

## What's Changed
* Do not report MA0046 on events of type EventHandler<TSender,
TEventArgs> by @​meziantou in
meziantou/Meziantou.Analyzer#1435


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.225...3.0.226

## 3.0.225

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.225>

## What's Changed
* Add MA0224 and MA0225 to require the Respect* options on
JsonSerializerOptions by @​meziantou in
meziantou/Meziantou.Analyzer#1433


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.224...3.0.225

## 3.0.224

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.224>

## What's Changed
* Add MA0222 and MA0223 to require the System.Text.Json Respect* options
to be configured by @​meziantou in
meziantou/Meziantou.Analyzer#1432


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.223...3.0.224

## 3.0.223

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.223>

## What's Changed
* Remove the GetAllMembers extension methods superseded by
Meziantou.Framework.Roslyn by @​meziantou in
meziantou/Meziantou.Analyzer#1428


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.222...3.0.223

## 3.0.222

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.222>

## What's Changed
* Do not report MA0004, MA0068, MA0070, MA0160 and MA0176 in generated
code by @​meziantou in
meziantou/Meziantou.Analyzer#1430


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.221...3.0.222

## 3.0.221

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.221>

## What's Changed
* Do not report MA0028 on StringBuilder.Insert with a Substring argument
by @​meziantou in
meziantou/Meziantou.Analyzer#1429


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.220...3.0.221

## 3.0.220

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.220>

## What's Changed
* Reduce the allocations of OverloadFinder by @​meziantou in
meziantou/Meziantou.Analyzer#1426


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.219...3.0.220

## 3.0.219

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.219>

## What's Changed
* Make the analysis of generated code opt-in by @​meziantou in
meziantou/Meziantou.Analyzer#1425


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.218...3.0.219

## 3.0.218

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.218>

## What's Changed
* Gate the analysis of generated code behind
MEZIANTOU_ANALYZER_GENERATED_CODE by @​meziantou in
meziantou/Meziantou.Analyzer#1423


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.217...3.0.218

## 3.0.217

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.217>

## What's Changed
* Close the gaps in the documentation generator's configuration key
extractor by @​meziantou in
meziantou/Meziantou.Analyzer#1421


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.216...3.0.217

## 3.0.216

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.216>

## What's Changed
* Add tests for the .editorconfig options that were never set by a test
by @​meziantou in
meziantou/Meziantou.Analyzer#1419
* Report MA0130 on System.Type instances by @​meziantou in
meziantou/Meziantou.Analyzer#1422


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.215...3.0.216

## 3.0.215

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.215>

## What's Changed
* chore(deps): update dependency meziantou.framework.roslyn to 1.0.13 by
@​renovate[bot] in
meziantou/Meziantou.Analyzer#1420


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.214...3.0.215

## 3.0.214

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.214>

## What's Changed
* Resolve the NuGet packages of the tests from the global packages
folder by @​meziantou in
meziantou/Meziantou.Analyzer#1415
* Return the pooled StringBuilder on every path by @​meziantou in
meziantou/Meziantou.Analyzer#1416
* Split the TryGetValue part of MA0186 into a new rule MA0221 by
@​meziantou in meziantou/Meziantou.Analyzer#1417
* Report MA0153 when the type of a logged property or field is
classified by @​meziantou in
meziantou/Meziantou.Analyzer#1418


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.213...3.0.214

## 3.0.213

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.213>

## What's Changed
* Create the configured regexes from the options by @​meziantou in
meziantou/Meziantou.Analyzer#1414


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.212...3.0.213

## 3.0.212

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.212>

## What's Changed
* chore(deps): update all dependencies by @​renovate[bot] in
meziantou/Meziantou.Analyzer#1317


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.211...3.0.212

## 3.0.211

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.211>

## What's Changed
* Fix MA0065/MA0066 never checking for a GetHashCode override by
@​meziantou in meziantou/Meziantou.Analyzer#1391
* Report MA0124/MA0125/MA0126 on [LoggerMessage(Message = "...")] by
@​meziantou in meziantou/Meziantou.Analyzer#1392
* Report MA0179 on the array-returning GetCustomAttributes overloads by
@​meziantou in meziantou/Meziantou.Analyzer#1393
* Give MA0107 its own exclude_tostring_methods configuration key by
@​meziantou in meziantou/Meziantou.Analyzer#1394
* Report MA0060 on ignored return values behind a conditional access by
@​meziantou in meziantou/Meziantou.Analyzer#1395
* Cache the culture sensitivity of the types by @​meziantou in
meziantou/Meziantou.Analyzer#1396
* Discover the regex-valued options validated by MA0220 by @​meziantou
in meziantou/Meziantou.Analyzer#1397
* Apply the syntactic filter of MA0003 before binding the arguments by
@​meziantou in meziantou/Meziantou.Analyzer#1398
* Load the MA0104 BCL type tables lazily by @​meziantou in
meziantou/Meziantou.Analyzer#1399
* Remove the dnceng dotnet-tools NuGet source by @​meziantou in
meziantou/Meziantou.Analyzer#1400
* Share the diagnostic property keys between the analyzers and the
fixers by @​meziantou in
meziantou/Meziantou.Analyzer#1401
* Avoid the control flow analysis of MA0004 when the context is
irrelevant by @​meziantou in
meziantou/Meziantou.Analyzer#1402
* Remove dead VSIX release scripts by @​meziantou in
meziantou/Meziantou.Analyzer#1404
* Rename tests that assert no diagnostic but are named *_ShouldReport*
by @​meziantou in
meziantou/Meziantou.Analyzer#1405
* Remove the two NuGet audit suppressions by @​meziantou in
meziantou/Meziantou.Analyzer#1406
* Match the annotation attributes by name in MA0060, MA0124 and MA0139
by @​meziantou in
meziantou/Meziantou.Analyzer#1407
* Fix MA0183 false positive and missed diagnostic when named arguments
are reordered by @​meziantou in
meziantou/Meziantou.Analyzer#1408
* Do not report MA0106 on a lambda already reported by MA0105 by
@​meziantou in meziantou/Meziantou.Analyzer#1410
* Add tests for MA0080 by @​meziantou in
meziantou/Meziantou.Analyzer#1411
* Avoid walking the whole operation tree in IsInExpressionContext by
@​meziantou in meziantou/Meziantou.Analyzer#1409
* Fix two broken documentation links by @​meziantou in
meziantou/Meziantou.Analyzer#1413
* Remove the dead Roslyn 4.4 workaround from MA0099 by @​meziantou in
meziantou/Meziantou.Analyzer#1412
* Clear the pooled queue of UseLangwordInXmlCommentAnalyzer on return by
@​meziantou in meziantou/Meziantou.Analyzer#1403


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.210...3.0.211

## 3.0.210

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.210>

## What's Changed
* Fix MA0113 NullReferenceException and named-argument false negatives
by @​meziantou in
meziantou/Meziantou.Analyzer#1382
* Fix MA0078 false positive when the cast targets a captured parameter
by @​meziantou in
meziantou/Meziantou.Analyzer#1383
* Do not report MA0063 on the indexed Where overload by @​meziantou in
meziantou/Meziantou.Analyzer#1384
* Parenthesize the expressions produced by the MA0112 and MA0128 fixers
by @​meziantou in
meziantou/Meziantou.Analyzer#1385
* Do not report MA0179 on user-defined GetCustomAttribute(s) methods by
@​meziantou in meziantou/Meziantou.Analyzer#1386
* Fix MA0151 false positive on System.Object members of interface-typed
members by @​meziantou in
meziantou/Meziantou.Analyzer#1387


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.209...3.0.210

## 3.0.209

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.209>

## What's Changed
* chore(deps): update dependency meziantou.framework.roslyn to 1.0.12 by
@​renovate[bot] in
meziantou/Meziantou.Analyzer#1390
* Create the GitHub release from the commit that was built by
@​meziantou in meziantou/Meziantou.Analyzer#1389


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.208...3.0.209

## 3.0.208

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.208>

## What's Changed
* Do not offer the MA0028 Substring fix when it would duplicate side
effects by @​meziantou in
meziantou/Meziantou.Analyzer#1381


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.207...3.0.208

## 3.0.207

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.207>

## What's Changed
* Remove Feedz publishing from CI by @​meziantou in
meziantou/Meziantou.Analyzer#1380


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.206...3.0.207

## 3.0.206

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.206>

## What's Changed
* Add MA0048 options to skip parts of the file name by @​meziantou in
meziantou/Meziantou.Analyzer#1379
* Configure the reporting in generated code per rule by @​meziantou in
meziantou/Meziantou.Analyzer#1376


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.205...3.0.206

## 3.0.205

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.205>

## What's Changed
* chore(deps): update dependency meziantou.framework.roslyn to 1.0.11 by
@​renovate[bot] in
meziantou/Meziantou.Analyzer#1378


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.204...3.0.205

## 3.0.204

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.204>

## What's Changed
* chore(deps): update dependency meziantou.framework.roslyn to 1.0.10 by
@​renovate[bot] in
meziantou/Meziantou.Analyzer#1377


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.203...3.0.204

Commits viewable in [compare
view](meziantou/Meziantou.Analyzer@3.0.203...3.0.228).
</details>

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=Meziantou.Analyzer&package-manager=nuget&previous-version=3.0.203&new-version=3.0.228)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant