Skip to content
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

Add support for returning an array field (or its clone) from methods (HAST-258) #63

Open
sarahelsaig opened this issue Dec 20, 2021 · 1 comment

Comments

@sarahelsaig
Copy link
Member

sarahelsaig commented Dec 20, 2021

As mentioned here:

[...] if you return an array from a method instead of a property it won't work even if the two are functionally equivalent. For example Quire.Segments is an array returning property which is not suggested for performance reasons. But if I replace it with a ulong[] GetSegments() => _segments; method, I will get the The length of the array holder System.Void Lombiq.Arithmetics.Quire::.ctor(System.UInt64[],System.UInt16).Lombiq.Arithmetics.Quire.GetSegments (@this)[82..87) couldn't be statically determined. error. Checking if a method returns a trivial reference could resolve that problem.

We need:

  • ulong[] GetSegments() => _segments.Clone(); : return the clone of an array backing field from a function.
  • IReadOnlyList<ulong> GetSegments() => _segments; : return the backing field directly as an immutable collection.
  • public IReadOnlyList<ulong> Segments => _segments; : do the same from a get-only property.

Jira issue

@Piedone
Copy link
Member

Piedone commented Dec 20, 2021

Following up here. Yep, we'd need to support those three scenarios indeed. IReadOnlyList<T> should be fairly straightforward since we don't actually need to do anything with it on the hardware, it can be an array (since write access to it is prevented in the .NET level already).

@github-actions github-actions bot changed the title Add support for returning an array field (or its clone) from methods Add support for returning an array field (or its clone) from methods (HAST-258) Sep 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants