dotnet / dotnet/roslyn

Improve parser error recovery for misplaced `ref` modifier of a struct declaration

Open
#84,734 5 comments 0 reactions 0 assignees View on GitHub
Area-Compilers Feature - Ref Fields help wanted
Dominant language
C#
Stars
20.7k
Forks
4.3k
PR merge metrics
PR metrics pending

Description

**Case 1:**

**Snippet:**
```cs
ref public struct MyStruct;
```

**Expected:**
`ref` is in the modifiers list for `MyStruct`, error about its misplacement

**Actual:**
`ref` is a part of `RefTypeSyntax` of `IncompleteMemberSyntax` while `StructDeclarationSyntax` starts from a `public` token. The error is 'Type expected' on `public` token

**Case 2:**

**Snippet:**
```cs
partial ref struct MyStruct;
```

**Expected:**
`partial` is in the modifiers list for `MyStruct`, error about its misplacement

**Actual:**
`partial` is its own `IncompleteMemberSyntax`. The error is on `ref` keyword saying about its misplacement instead

Contributor guide

Open the contributing guide

Research direction

Reproduce the two C# snippets from the issue and compare the parser's syntax trees and diagnostics with the expected modifier placement. Trace the parser entry points for struct declarations and incomplete members; done means both snippets retain the intended modifiers on MyStruct and report the misplacement on ref.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.