Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 14, 2025

Fix parsing of scoped before this in parameter list ✅

Summary

Fixed a parser bug where scoped in this int failed to parse even though the ordering of this keyword was supposed to be relaxed according to LDM notes.

Changes Made

Parser Fix (LanguageParser.cs:4884):

-// Look if ref/out/in/readonly are next
-while (this.CurrentToken.Kind is SyntaxKind.RefKeyword or SyntaxKind.OutKeyword or SyntaxKind.InKeyword or SyntaxKind.ReadOnlyKeyword)
+// Look if ref/out/in/readonly/this are next
+while (this.CurrentToken.Kind is SyntaxKind.RefKeyword or SyntaxKind.OutKeyword or SyntaxKind.InKeyword or SyntaxKind.ReadOnlyKeyword or SyntaxKind.ThisKeyword)

Parsing Tests Added (DeclarationScopeParsingTests.cs):

  • ScopedWithThis_01: scoped in this int (main failing case)
  • ScopedWithThis_02: scoped ref this int
  • ScopedWithThis_03: scoped ref readonly this int
  • ScopedWithThis_04: this scoped in int (regression test)

Attribute Tests Added (AttributeTests_LifetimeAnnotation.cs):

  • EmitAttribute_ExtensionMethodParameters_ScopedInThis
  • EmitAttribute_ExtensionMethodParameters_ScopedRefThis
  • EmitAttribute_ExtensionMethodParameters_ScopedRefReadonlyThis

Test Results

All new parsing tests pass (4/4)
All new attribute tests pass (3/3)
All existing tests pass

  • AttributeTests_ScopedRef: 19 passed (16 existing + 3 new)
  • DeclarationScopeParsingTests: 476 passed
  • Overall Syntax.UnitTests: 9,733 passed

Manual Verification

All issue scenarios now work correctly:

void M(in this int p);           // ✅ Works (before and after)
void M(this in int p);           // ✅ Works (before and after)
void M(scoped in this int p);    // ✅ NOW WORKS (failed before)
void M(this scoped in int p);    // ✅ Works (before and after)

Impact

Minimal surgical change - one line modified in parser logic to support the relaxed ordering of parameter modifiers as intended by the language design.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@Copilot Copilot AI changed the title [WIP] Fix parsing of scoped before this in parameter list Fix parsing of scoped before this in parameter list Oct 14, 2025
@Copilot Copilot AI requested a review from jcouv October 14, 2025 20:37
Copilot finished work on behalf of jcouv October 14, 2025 20:37
N(SyntaxKind.SemicolonToken);
}
EOF();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Remove extra empty lines below. And for the scenarios you've added above, add corresponding tests to AttributeTests_ScopedRef for the scenarios that aren't already covered.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Removed the extra empty lines and added three attribute tests for the extension method scenarios with this keyword combinations in commit af5f4ec.

Copilot finished work on behalf of jcouv October 14, 2025 21:27
@Copilot Copilot AI requested a review from jcouv October 14, 2025 21:27
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.

2 participants