It's frustrating that we can only use `ref` for function arguments. I should be able to declare a local variable ref to capture the result of a ref function, or to simplify a long expression.
ref int fun();
void test()
{
ref int refLocal = fun();
ref int resolveExpression = thing[10].something().member.x;
}
It feels very lame to use pointers in these cases.
It may also change semantics of assignment expressions when using pointers.
Comment #1 by bugzilla — 2019-07-23T08:25:43Z
This is not allowed because it would make the memory safe checks in the compiler much harder.
Comment #2 by turkeyman — 2019-07-23T08:33:05Z
How so? ref is more restrictive than pointers if anything. The fact they can't be re-bound and don't mess with assignment semantics are desirable advantages.
It's also another case of weird asymmetry which I've had to try and explain lots of times, and there's no explanation I can give.
At very least it should be identical complexity?
Comment #3 by robert.schadek — 2024-12-13T19:04:37Z