-
Notifications
You must be signed in to change notification settings - Fork 542
[RGen] Correctly cast enum results from the native invocation. #23079
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Generate a simple cast when the result is a non-native non-smart enum.
There was a problem hiding this 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 aCastExpression
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
;
afterCallback()
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)); |
There was a problem hiding this comment.
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 uses AI. Check for mistakes.
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)); |
There was a problem hiding this comment.
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 uses AI. Check for mistakes.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ [CI Build #41f18f0] Build passed (Build packages) ✅Pipeline on Agent |
✅ [PR Build #41f18f0] Build passed (Detect API changes) ✅Pipeline on Agent |
✅ API diff for current PR / commit.NET ( No breaking changes )✅ API diff vs stable.NET ( No breaking changes )ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
✅ [CI Build #41f18f0] Build passed (Build macOS tests) ✅Pipeline on Agent |
💻 [CI Build #41f18f0] Tests on macOS X64 - Mac Sonoma (14) passed 💻✅ All tests on macOS X64 - Mac Sonoma (14) passed. Pipeline on Agent |
💻 [CI Build #41f18f0] Tests on macOS M1 - Mac Monterey (12) passed 💻✅ All tests on macOS M1 - Mac Monterey (12) passed. Pipeline on Agent |
💻 [CI Build #41f18f0] Tests on macOS arm64 - Mac Sequoia (15) passed 💻✅ All tests on macOS arm64 - Mac Sequoia (15) passed. Pipeline on Agent |
💻 [CI Build #41f18f0] Tests on macOS M1 - Mac Ventura (13) passed 💻✅ All tests on macOS M1 - Mac Ventura (13) passed. Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
🚀 [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 Pipeline on Agent |
Generate a simple cast when the result is a non-native non-smart enum.