Fix CS8618 suggesting 'required' on events#82424
Open
apoorvdarshan wants to merge 2 commits intodotnet:mainfrom
Open
Fix CS8618 suggesting 'required' on events#82424apoorvdarshan wants to merge 2 commits intodotnet:mainfrom
apoorvdarshan wants to merge 2 commits intodotnet:mainfrom
Conversation
Add new warning CS9360 (WRN_UninitializedNonNullableEvent) for non-nullable events that omits the invalid 'required' modifier suggestion, since 'required' is not valid on events (CS0106).
jjonescz
approved these changes
Feb 18, 2026
Member
|
Looks like some more tests need updating, see failing CI. |
Three tests used #pragma warning disable 8618 to suppress the old event warning but not the new CS9360. Add 9360 to those pragmas.
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
Fixes #81679
CS8618 fires for non-nullable events with the message suggesting
required, butrequiredis not valid on events (CS0106). This PR adds a new dedicated warning CS9360 (WRN_UninitializedNonNullableEvent) that omits the invalidrequiredsuggestion:WRN_UninitializedNonNullableBackingField(CS9264)WRN_UninitializedNonNullableEvent = 9360with event-specific messageNullableWalkernow selects the new code whensymbol.Kind == SymbolKind.EventTest plan
eng/generate-compiler-code.csregeneratesErrorFacts.Generated.cscorrectlydotnet build src/Compilers/CSharp/Portable— 0 warnings, 0 errorsUninitializedNonNullableFieldTests— 100 tests passDiagnosticTest— 68 tests passNullableContextTests— 2615 tests passAttributeTests_Nullable— 169 tests passSymbolEqualityTests,NullablePublicAPITests,FieldKeywordTests— all pass