Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 20, 2025

The readonly keyword was not being highlighted when used as an accessor modifier for getters in properties and indexers (C# 8.0+).

struct M
{
    public int Counter
    {
        get => counter;
        readonly set { }  // readonly is not valid on setters
    }
    
    public int this[int i]
    {
        readonly get => counter;  // readonly was not highlighted
        set { }
    }
}

Changes

  • Grammar: Added readonly as an optional modifier specifically for get accessors only (not set or init, as per C# language specification)
  • Tests: Added coverage for readonly getters with both expression bodies and block bodies

The readonly modifier is now correctly restricted to getter accessors, matching C# 8.0+ language semantics for readonly instance members in structs.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Textmate] readonly getter and setter in struct</issue_title>
<issue_description>## Details

What editor are you seeing the problem in? (e.g. Atom, Visual Studio Code, etc.)
vscode
What version of the editor are you using?
1.85.1
What color theme are you using?
dark plus

Repro

struct M
{
    private int counter;
    public int Counter
    {
        get => counter;
        readonly set { }
    }
    public int this[int i]
    {
        readonly get => counter;
        set { }
    }
    public readonly void Method()
    {
        counter++;
    }
}

image

Please provide a code example and (optionally) a screenshot demonstrating the problem.</issue_description>

<agent_instructions>From the example, it appears that readonly is not being classified in readonly getters</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

- Added readonly to accessor modifier pattern in property-accessors
- Added three comprehensive tests for readonly getters and setters
- All 896 tests passing

Co-authored-by: JoeRobich <[email protected]>
Copilot AI changed the title [WIP] Fix readonly getter and setter classification in struct Add readonly modifier support for property accessors Dec 20, 2025
Copilot AI requested a review from JoeRobich December 20, 2025 02:39
Per reviewer feedback, readonly is only applicable to getters, not setters.
- Moved readonly pattern from general accessor modifiers to getter-specific pattern
- Updated tests to only validate readonly on getters (removed invalid readonly setter tests)
- All 895 tests passing

Co-authored-by: JoeRobich <[email protected]>
Copilot AI changed the title Add readonly modifier support for property accessors Add readonly modifier support for property getters Dec 20, 2025
Copilot AI requested a review from JoeRobich December 20, 2025 03:06
@JoeRobich JoeRobich marked this pull request as ready for review December 20, 2025 03:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Textmate] readonly getter and setter in struct

2 participants