[generator] Do the right thing when [ReleaseAttribute] is applied to a member that returns a managed array
- Dominant language
- C#
- Stars
- 2.9k
- Forks
- 576
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 123
Description
While updating [NetworkExtension](https://github.com/xamarin/xamarin-macios/pull/8126#discussion_r393570319) we uncovered a generator bug that produces incorrect code:
```csharp
[return: Release]
[return: NullAllowed]
[Export ("copyAppRules")]
NEAppRule[] CopyAppRules ();
```
which generates:
```csharp
[Export ("copyAppRules")]
[return: ReleaseAttribute ()]
[BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)]
public virtual NEAppRule[] CopyAppRules ()
{
NEAppRule[] ret;
if (IsDirectBinding) {
ret = NSArray.ArrayFromHandle(global::ObjCRuntime.Messaging.IntPtr_objc_msgSend (this.Handle, Selector.GetHandle ("copyAppRules")));
} else {
ret = NSArray.ArrayFromHandle(global::ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper (this.SuperHandle, Selector.GetHandle ("copyAppRules")));
}
if (ret != null)
global::ObjCRuntime.Messaging.void_objc_msgSend (ret.Handle, Selector.GetHandle ("release"));
return ret;
}
```
`ret` will not have the `Handle` property at this point since it is already too late it is a managed array.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.