Closed
Description
Describe the bug
In the C# 7.x draft, 12.21.3 could be a bit clearer about input parameters here:
If the left operand is a writeable ref (i.e., it designates anything other than a
ref readonly
local orin
parameter), then the right operand shall be a writeable variable_reference. If the right operand variable is writeable, the left operand may be declaredref
orref readonly
.
Example
This should be valid.
class C {
int j;
void M(in int i) {
i = ref j;
}
}
Expected behavior
Say that the left operand may be declared in
as an input parameter.
Additional context
Poking this, I met the ref-safe-to-escape rules
class C {
ref readonly int M(in int i, int j) {
////i = ref j; // error CS8374
return ref i;
}
}
The ref assignment here looks benign on its own, but it must be rejected because the method could then return that ref. I have not checked whether the draft specifies an error here.