CS8618 suggests using `required` on events.
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
**Version Used**: 5.3.0-2.25603.1
Similar to #78152, but for events, both static and non-static.
**Steps to Reproduce**:
[.NET Lab](https://lab.razor.fyi/#4wrg4gooyk8vSszVSy4WciotzsxLVwiuLC5JzbXm4iooTcrJTFZIzkksLlZwVqjmUlBQUIAKppal5pUoOCaXZObnKfjnuYK41ly1XsxFpXkJjBWMAA)
```csharp
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`.
Contributor guide
Research direction
Start by reproducing diagnostic CS8618 with the linked .NET Lab example, then trace where the diagnostic message is generated for events. Update the advice so it does not suggest `required` for events, and add or adjust coverage for both static and non-static events so the expected wording is verified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100