Add missing #pragma warning disable to generated code headers#210
Merged
Conversation
Skymly
commented
Jul 4, 2026
Skymly
left a comment
Owner
Author
There was a problem hiding this comment.
Review: PR #210 — Add #pragma warning disable to generated code headers
Clean implementation. Adds #pragma warning disable CS1591,CS8019,CS0162,CS0612,CS0618 to the auto-generated header, suppressing warnings that generated code may trigger but consumers shouldn't see.
What's good
PragmaWarningDisableCodesconstant centralizes the warning codes — easy to maintain.- Warning code selection is reasonable:
CS1591— missing XML doc comment (generated code doesn't have XML docs)CS8019— unnecessary using directive (generated code may include usings that aren't always needed)CS0162— unreachable code (generated code may have conditional branches)CS0612/CS0618— obsolete member usage (generated code may reference APIs marked obsolete)
ParseLeadingTriviacorrectly parses the pragma directive with newline.- All Verify snapshots updated to include the new pragma line.
Observation
- The pragma is added to the header trivia (before
#nullable enable), which means it's in scope for the entire generated file. This is correct — the pragma should cover all generated code. - Note: this PR and PR #208 both modify
GeneratedCodeHelper.csand the same verified.txt files. They will need to be merged sequentially with a rebase in between.
No blocking issues. Approve.
The GeneratedCodeHelper XML doc claimed to add #pragma warning disable directives but the implementation had none. Generated code can trigger warnings (CS1591 missing XML doc, CS8019 unused using, CS0162 unreachable code, CS0612/CS0618 obsolete) that become errors in consumer projects with TreatWarningsAsErrors=true. Add #pragma warning disable CS1591,CS8019,CS0162,CS0612,CS0618 to the auto-generated header trivia, emitted before the using directives. This is independent of the #nullable enable placement (issue #207) and applies to all generators using CreateAutoGeneratedHeader. 55 Verify snapshots updated. Closes #209
f135793 to
0db4336
Compare
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.
Summary
#pragma warning disable CS1591,CS8019,CS0162,CS0612,CS0618to the auto-generated header trivia inGeneratedCodeHelper.CreateAutoGeneratedHeader. This is emitted before theusingdirectives and applies to all generated code.GeneratedCodeHelperclaimed to add#pragma warning disablebut the implementation had none. Generated code can trigger warnings (CS1591 missing XML doc, CS8019 unused using, CS0162 unreachable code, CS0612/CS0618 obsolete) that become errors in consumer projects withTreatWarningsAsErrors=true.#pragmaline is not visible in snapshots but is present in the actual generated source — verified via a temporary assertion test).Suppressed warning codes
#ifpaths)Related Issue
Closes #209
Solution module
DesignPatterns.SourceGenerators/)Type of change
Test plan
dotnet build DesignPatterns.slnx -c Release— 0 errors, 0 warningsdotnet test DesignPatterns.slnx -c Release --no-build— all tests pass#pragma warning disablepresent in generated source text (test removed before commit)Breaking changes