Repository navigation
Enable nullable in every generated file's header [patch] - #57
Merged
Merged
Conversation
Roslyn compiles a file carrying the <auto-generated /> marker with the nullable context disabled, whatever the consuming project sets. Without a directive, every string? in WriteSourceFile output raised CS8669 and every unannotated member was null-oblivious to consumers. WriteFileHeader now writes #nullable enable after the marker, so WriteSourceFile inherits it. Fixes #55 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW3EdFmyBthXBAkdCiZ
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW3EdFmyBthXBAkdCiZ
|
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.



Fixes #55
What changed
Roslyn compiles any file that carries the
// <auto-generated />marker with the nullable context disabled, whatever<Nullable>the consuming project sets.WriteFileHeaderwrote no#nullabledirective, andWriteSourceFilewrites the header and body in one call, so callers couldn't add one themselves. As a result:string?in the output raised CS8669, which is an error underTreatWarningsAsErrorsWriteFileHeadernow writes#nullable enablestraight after the marker, andWriteSourceFileinherits it. The remarks onWriteFileHeaderand the README API table say why.A generator that already writes its own
#nullable enableafter the header now emits the directive twice. That is legal C# and changes nothing.Tests
TheHeaderEnablesNullableAfterTheGeneratedMarker: the header contains// <auto-generated />\n#nullable enable\n.AnnotatedGeneratedMembersCompileWithoutCS8669: compilesWriteSourceFileoutput that holds astring?field next to a consumer underNullableContextOptions.Enable, and asserts there is no CS8669.UnannotatedGeneratedMembersAreNotNullOblivious: assigningnullto the generatedstringfield raises CS8625.AMultiLineCopyrightIsCommentedOnEveryLinenow expects the directive in its exact-output check.With the one-line fix reverted, 6 tests fail (the 3 new ones and the 3
DataRows of the exact-header test). With it applied, all 63 pass on net10.0.Note
Open PR #56 (copyright splitting) also edits
WriteFileHeader, so whichever lands second may need a small rebase.Generated by Claude Code