Skip to content

struct's modifiers are too sensitive to order #361

Open

Description

@danzat

For example, the following generates a parse error (ref is not adjacent to struct):

ref partial struct S {}

Error:

compilation_unit [0, 0] - [2, 0]
  ERROR [0, 0] - [0, 20]
    variable_declaration [0, 0] - [0, 18]
      type: ref_type [0, 0] - [0, 11]
        type: identifier [0, 4] - [0, 11]
      variable_declarator [0, 12] - [0, 18]
        name: identifier [0, 12] - [0, 18]
  global_statement [0, 21] - [0, 23]
    block [0, 21] - [0, 23]

Whereas (ref is adjacent to struct):

partial ref struct S {}

Is fine:

compilation_unit [0, 0] - [1, 0]
  struct_declaration [0, 0] - [0, 23]
    modifier [0, 0] - [0, 7]
    name: identifier [0, 19] - [0, 20]
    body: declaration_list [0, 21] - [0, 23]

It's enough to have just one such error in a file to completely mess up its parsing.

Activity

  1. sharpchen commented on Mar 21, 2026

    @sharpchen
    Contributor

    Bump. partial ref struct is actually not valid btw?

    // CS1585: Member modifier 'ref' must precede the member type and name
    partial ref struct Foo { }
    
    ref partial struct Bar { } // this is the correct one
    readonly ref partial struct Baz { }
  2. added a commit that references this issue on Sep 10, 2026
    dd85547
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions