KEMBAR78
[RGen] Correctly cast enum results from the native invocation. by mandel-macaque · Pull Request #23079 · dotnet/macios · GitHub
Skip to content

Conversation

@mandel-macaque
Copy link
Member

Generate a simple cast when the result is a non-native non-smart enum.

Generate a simple cast when the result is a non-native non-smart enum.
@mandel-macaque mandel-macaque requested a review from Copilot June 18, 2025 20:01
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 non-smart, non-native enums returned from native invocations are explicitly cast back to their enum type.

  • Adds a new test case for enum return types in the trampoline syntax factory tests.
  • Updates expected trampoline outputs to include an explicit cast to AudioUnitStatus.
  • Implements a new switch arm in BindingSyntaxFactory.Trampoline to emit a CastExpression for normal enums.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tests/rgen/Microsoft.Macios.Generator.Tests/Emitters/BindingSyntaxFactoryTrampolineTests.cs Added a test input string and expected output for enum return type casting.
tests/rgen/Microsoft.Macios.Generator.Tests/Classes/Data/ExpectedTrampolinePropertyTestsTrampolines.cs Changed trampoline implementation to cast ret to AudioUnitStatus.
src/rgen/Microsoft.Macios.Generator/Emitters/BindingSyntaxFactory.Trampoline.cs Added a new pattern match arm to generate a CastExpression for non-smart enums.
Comments suppressed due to low confidence (1)

tests/rgen/Microsoft.Macios.Generator.Tests/Emitters/BindingSyntaxFactoryTrampolineTests.cs:763

  • The delegate declaration in the test input string is missing a terminating semicolon. Add ; after Callback() to make the code syntactically valid.
	public delegate TestEnum Callback()

if (realtimeEventListHead is null)
global::ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (realtimeEventListHead));
var realtimeEventListHead__handle__ = realtimeEventListHead.GetHandle ();
var outputData__handle__ = outputData!.GetNonNullHandle (nameof (outputData));
Copy link

Copilot AI Jun 18, 2025

Choose a reason for hiding this comment

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

Avoid using the null-forgiving operator !. Per nullable reference guidelines, replace this with an explicit null check or use ArgumentNullException.ThrowIfNull(outputData) before calling GetNonNullHandle.

Copilot generated this review using guidance from repository custom instructions.

global::ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (realtimeEventListHead));
var realtimeEventListHead__handle__ = realtimeEventListHead.GetHandle ();
var outputData__handle__ = outputData!.GetNonNullHandle (nameof (outputData));
var realtimeEventListHead__handle__ = realtimeEventListHead!.GetNonNullHandle (nameof (realtimeEventListHead));
Copy link

Copilot AI Jun 18, 2025

Choose a reason for hiding this comment

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

Avoid using the null-forgiving operator !. Per nullable reference guidelines, replace this with an explicit null check or use ArgumentNullException.ThrowIfNull(realtimeEventListHead) before calling GetNonNullHandle.

Copilot generated this review using guidance from repository custom instructions.

@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

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

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

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

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

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #41f18f0] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 41f18f062f2f23fb9911c5abadd7d1ff53fccbe8 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

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

Pipeline on Agent
Hash: 41f18f062f2f23fb9911c5abadd7d1ff53fccbe8 [PR build]

@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: 41f18f062f2f23fb9911c5abadd7d1ff53fccbe8 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #41f18f0] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 41f18f062f2f23fb9911c5abadd7d1ff53fccbe8 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

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

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

Pipeline on Agent
Hash: 41f18f062f2f23fb9911c5abadd7d1ff53fccbe8 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

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

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

Pipeline on Agent
Hash: 41f18f062f2f23fb9911c5abadd7d1ff53fccbe8 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

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

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

Pipeline on Agent
Hash: 41f18f062f2f23fb9911c5abadd7d1ff53fccbe8 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

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

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

Pipeline on Agent
Hash: 41f18f062f2f23fb9911c5abadd7d1ff53fccbe8 [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

🚀 [CI Build #41f18f0] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 115 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 4 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 9 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 8 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: 41f18f062f2f23fb9911c5abadd7d1ff53fccbe8 [PR build]

@mandel-macaque mandel-macaque merged commit 38e4bc3 into main Jun 19, 2025
44 checks passed
@mandel-macaque mandel-macaque deleted the dev/mandel/cast-return-enumerator branch June 19, 2025 13: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.

4 participants