Repository navigation
Leave #nullable enable out of headers for consumers below C# 8 [minor] - #61
Open
matt-edmondson wants to merge 3 commits into
Open
matt-edmondson wants to merge 3 commits into
matt-edmondson wants to merge 3 commits into
Conversation
WriteFileHeader wrote #nullable enable into every generated file, so a generator with a C# 7.3-compatible body broke the build of a netstandard2.0 or .NET Framework consumer on the default C# 7.3 with CS8370. GeneratorBase now reads the consumer's language version from ParseOptionsProvider and, while Generate runs, WriteFileHeader writes the directive only for C# 8 and later. A new overload takes the version explicitly, and GeneratorHarness gains a LanguageVersion property so the older-consumer case can be tested. Fixes #59 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW3i9xsUaiPekqznVhL
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW3i9xsUaiPekqznVhL
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW3i9xsUaiPekqznVhL
|
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 #59
Summary
Since #57,
WriteFileHeaderwrites#nullable enableinto every generated file. A generator whose hand-written body is C# 7.3-compatible therefore broke anetstandard2.0or .NET Framework consumer on the default C# 7.3, with CS8370 at line 3 of every generated file.GeneratorBase.InitializecombinesParseOptionsProviderinto the pipeline and keeps the consumer'sLanguageVersionin a[ThreadStatic]field whileGenerateruns.WriteFileHeader(CodeBlocker, string?)is still static, so existing callers need no change. It writes the directive only for C# 8 and later. OutsideGeneratethe version is unknown, so it keeps writing the directive as it does today.WriteFileHeader(CodeBlocker, string?, LanguageVersion)takes the version explicitly.GeneratorHarnessgains an init-onlyLanguageVersionproperty (defaultLanguageVersion.Default), which is passed to the driver as its parse options. Tests can now run a generator as an older consumer would.Marked
[minor]for the new public overload and harness property. Nothing existing changes its signature.Tests
In
GeneratorHarnessTests:AHeaderForACSharp73ConsumerParsesWithoutCS8370: runsPairGenerator(WriteFileHeaderplus a hand-written body) at C# 7.3 and checks the output has no#nullableand no parse diagnostics. It fails with theGeneratorBase.cschange reverted and passes with it.AHeaderForACSharp8OrLaterConsumerEnablesNullable(C# 8, Default, Latest): the directive is still written, so Code written by WriteSourceFile has nullable disabled: everystring?it emits raises CS8669, and non-annotated members are null-oblivious to consumers #55 stays fixed.The existing nullable tests (
AnnotatedGeneratedMembersCompileWithoutCS8669,UnannotatedGeneratedMembersAreNotNullOblivious,TheHeaderEnablesNullableAfterTheGeneratedMarker) still pass. Full suite: 70/70. The Release build has 0 warnings. The Sonar analyzers were not run locally.Generated by Claude Code