KEMBAR78
[RGen] Ensure that if a parameter name is a keyword that '@' is used as a prefix. by mandel-macaque · Pull Request #22930 · dotnet/macios · GitHub
Skip to content

Conversation

@mandel-macaque
Copy link
Member

In C#, the @ symbol is used as an escape character to allow reserved keywords (like event) to be used as identifiers. However, when working with Roslyn's IParameterSymbol, the Name property returns the identifier without the @ prefix because the @ is only required in the source code to escape the keyword. Internally, the compiler treats the name as the unescaped version. The data model has to take this into account and re-escape the keyword so that we can use the same parameter name as the source code.

…as a prefix.

In C#, the @ symbol is used as an escape character to allow reserved keywords (like event) to be used as
identifiers. However, when working with Roslyn's IParameterSymbol, the Name property returns the identifier
without the @ prefix because the @ is only required in the source code to escape the keyword.
Internally, the compiler treats the name as the unescaped version. The
data model has to take this into account and re-escape the keyword so
that we can use the same parameter name as the source code.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR ensures that parameter names which are C# keywords are escaped with @ when generating source code.

  • Added GetSaveName extension to prefix @ for keyword parameter names.
  • Updated transformer and generator code to use GetSaveName instead of symbol.Name.
  • Added tests and updated project files to include the new extension.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/rgen/.../FromDeclarationTests.cs Added test case for method parameter named @event.
tests/rgen/.../DelegateInfoTests.cs Added test case for delegate parameter named @event.
src/rgen/Microsoft.Macios.Transformer/Microsoft.Macios.Transformer.csproj Included ParameterSymbolExtensions.cs in Transformer build.
src/rgen/Microsoft.Macios.Transformer/DataModel/Parameter.Transformer.cs Switched symbol.Name to symbol.GetSaveName().
src/rgen/Microsoft.Macios.Transformer/DataModel/DelegateParameter.Transformer.cs Switched symbol.Name to symbol.GetSaveName().
src/rgen/Microsoft.Macios.Generator/Extensions/ParameterSymbolExtensions.cs Added extension method GetSaveName.
src/rgen/Microsoft.Macios.Generator/DataModel/Parameter.Generator.cs Switched symbol.Name to symbol.GetSaveName().
src/rgen/Microsoft.Macios.Generator/DataModel/DelegateParameter.Generator.cs Switched symbol.Name to symbol.GetSaveName().
src/rgen/Microsoft.Macios.Bindings.Analyzer/Microsoft.Macios.Bindings.Analyzer.csproj Included ParameterSymbolExtensions.cs in Analyzer build.
Comments suppressed due to low confidence (3)

src/rgen/Microsoft.Macios.Generator/Extensions/ParameterSymbolExtensions.cs:18

  • [nitpick] The method is documented as returning a "safe name", but is named GetSaveName. Consider renaming it to GetSafeName to match the documentation and improve clarity.
public static string GetSaveName (this IParameterSymbol symbol)

src/rgen/Microsoft.Macios.Generator/DataModel/Parameter.Generator.cs:41

  • The GetSaveName extension method is defined in Microsoft.Macios.Generator.Extensions, but this file doesn't import that namespace. Add using Microsoft.Macios.Generator.Extensions; at the top to ensure it resolves.
parameter = new (symbol.Ordinal, new (symbol.Type, context.Compilation), symbol.GetSaveName ()) {

src/rgen/Microsoft.Macios.Generator/DataModel/DelegateParameter.Generator.cs:21

  • The GetSaveName extension is in Microsoft.Macios.Generator.Extensions, but this file lacks that using directive. Please add using Microsoft.Macios.Generator.Extensions; at the top.
parameter = new (symbol.Ordinal, new (symbol.Type), symbol.GetSaveName ()) {

GitHub Actions Autoformatter and others added 2 commits May 28, 2025 18:35
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #c6c4c53] Build passed (Build packages) ✅

Pipeline on Agent
Hash: c6c4c534db1985740f04633c03d949e163afab07 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #b11c676] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: b11c676af2451f8d551bfe1124c6df49ef766615 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #b11c676] Tests on macOS X64 - Mac Sonoma (14) passed 💻

All tests on macOS X64 - Mac Sonoma (14) passed.

Pipeline on Agent
Hash: b11c676af2451f8d551bfe1124c6df49ef766615 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #b11c676] Tests on macOS M1 - Mac Monterey (12) passed 💻

All tests on macOS M1 - Mac Monterey (12) passed.

Pipeline on Agent
Hash: b11c676af2451f8d551bfe1124c6df49ef766615 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #b11c676] Tests on macOS M1 - Mac Ventura (13) passed 💻

All tests on macOS M1 - Mac Ventura (13) passed.

Pipeline on Agent
Hash: b11c676af2451f8d551bfe1124c6df49ef766615 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [PR Build #c6c4c53] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: c6c4c534db1985740f04633c03d949e163afab07 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ API diff for current PR / commit

.NET ( No breaking changes )

✅ API diff vs stable

.NET ( No breaking changes )

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: c6c4c534db1985740f04633c03d949e163afab07 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🚀 [CI Build #7d4f813] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 122 tests passed 🎉

Tests counts

✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 6 tests passed. Html Report (VSDrops) Download
✅ linker: All 44 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 8 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 11 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 12 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 10 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

Pipeline on Agent
Hash: 7d4f813a7257cba2deb0dcc0ad543b729af3214a [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [CI Build #b11c676] Tests on macOS arm64 - Mac Sequoia (15) passed 💻

All tests on macOS arm64 - Mac Sequoia (15) passed.

Pipeline on Agent
Hash: b11c676af2451f8d551bfe1124c6df49ef766615 [PR build]

@mandel-macaque mandel-macaque merged commit 523e954 into main May 29, 2025
44 checks passed
@mandel-macaque mandel-macaque deleted the dev/mandel/correct-name-parameter branch May 29, 2025 00:45
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.

3 participants