Allow forwarding ref readonly
arguments using ref
or ref readonly
#8962
Replies: 1 comment 1 reply
-
Well, as you know "in" is an existing keyword that represents an "inref" - a kind of byref argument that doesn't allow mutation of ref's content. You declare an "in" parameter and pass a value via using an explicit "in" or an implicit one. Now the provlem with "in" arguments is that it doesn't require caller to assign a storage for the argument. E.g. you can easily pass literals to "in" for example. "ref readonly" is conceptually similar to "in" - a reference content of which can't be mutated. But the important difference is that it requires caller to first assign a storage (a variable, heap/stack memory). So "in" was a natural choice because it clearly indicates a readonly behavior. It's just that "ref readonly" is a stricter version. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
It seems odd to me that
ref readonly
function arguments can only be passed to another function taking aref readonly
argument by usingin
instead ofref
orref readonly
.ref
at the call site would be more consistent with the syntax for forwarding non-readonly arguments, assuming that the compiler can propagate thereadonly
-ness.ref readonly
at the call site would be more consistent with the function argument modifiers.I tried searching for the reason why
in
was chosen for this scenario but couldn't find it. Is it too late to consider allowing eitherref
orref readonly
as well?Beta Was this translation helpful? Give feedback.
All reactions