Events don't require unsafe context for pointers in types
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
**Version Used**: [5.3.0-2.25619.2](https://dev.azure.com/dnceng/public/_artifacts/feed/dotnet-tools/NuGet/Microsoft.Net.Compilers.Toolset/overview/5.3.0-2.25619.2) ([6a135ea](https://github.com/dotnet/roslyn/commit/6a135ea0ca8b7332d11fa78d68f0a14a65f2644f))
**Steps to Reproduce**:
```cs
class C
{
event System.Action E; // no error
}
```
**Expected Behavior**: "error CS0214: Pointers and fixed size buffers may only be used in an unsafe context" like for example a property would get:
```cs
class C
{
System.Action P { get; set; } // error: pointers may only be used in an unsafe context
}
```
**Actual Behavior**: No errors.
Unsafe errors are intentionally suppressed (see below) but the assumption in the comment is wrong (it is valid to have a pointer inside a delegate and type argument as the example above shows):
https://github.com/dotnet/roslyn/blob/22d4d4d756c5e6e66f463c21b2c4e0e41f3d9839/src/Compilers/CSharp/Portable/Symbols/Source/SourceEventSymbol.cs#L819-L827
Fixing this would be a breaking change.
Also, using the event outside `unsafe` context fails anyway.
Contributor guide
Research direction
Start in src/Compilers/CSharp/Portable/Symbols/Source/SourceEventSymbol.cs around lines 819-827 and reproduce the C# event sample to confirm the current behavior. Trace the existing unsafe-error suppression and locate the compiler regression-test area; done means the event declaration reports the expected unsafe-context diagnostic consistently with the property case, with coverage for the sample.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100