dotnet/roslyn

CS8618 suggests using `required` on events.

Open

#81,679 opened on 2025年12月13日

GitHub で見る
 (2 comments) (0 reactions) (0 assignees)C# (20,414 stars) (4,257 forks)batch import
Area-CompilersConcept-Diagnostic Clarityhelp wanted

説明

Version Used: 5.3.0-2.25603.1

Similar to #78152, but for events, both static and non-static.

Steps to Reproduce:

.NET Lab

using System;

public class C {
    public event Action OnEvent;
}

Diagnostic Id:

CS8618 Non-nullable event 'OnEvent' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the event as nullable.

Expected Behavior:

The error message is:

CS8618 Non-nullable event 'OnEvent' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the event as nullable.

Actual Behavior:

The error message gives wrong advice. Adding the required modifier results in error CS0106 The modifier 'required' is not valid for this item.

コントリビューターガイド

CS8618 suggests using `required` on events. · dotnet/roslyn#81679 | Good First Issue