-
Notifications
You must be signed in to change notification settings - Fork 90
C# 7.x ref assignment to input parameter #839
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
Comments
At the start of 12.21.3 we already have:
The bit you've quoted is only meant to be restricting what's used for the right operand, e.g. to prevent: static void M(in int i)
{
ref int j = ref i;
} For the second part, the error occurs even without 12.21.3: "It is a compile time error if the ref-safe-context (§9.7.2) of the left operand is wider than the ref-safe-context of the right operand." 9.7.2.2: "If p is a ref, or in parameter, its ref-safe-context is the caller-context. If p is an in parameter, it can’t be returned as a writable ref but can be returned as ref readonly." (So the ref-safe-context of 9.7.2.2: (After things that don't apply to caller-context is wider than function-member, so it's prohibited. Proposal for the meeting: check my logic, then close the issue without further spec changes. |
So you're saying that this
is not meant to disallow other ways of declaring the left operand. |
Correct. If it required the left operand to be declared |
I think we can improve this a little, I'll put out a PR… |
@KalleOlaviNiemitalo, @jskeet – see PR #917. I think that addresses it, I think it was a “typo” |
The distinction between read-only and writable refs, or more generally variable_references, still seems inadequately specified but I guess it's better to fix that as part of #894. |
@KalleOlaviNiemitalo: So just to check we're on the same page, are you happy for us to merge #917 and then take a bigger swing at read-only/writable refs in a separate PR to address #894? |
Yes that's fine. |
The original text appeared to restrict the left operand to variables declared `ref` or `ref readonly` when a writeable or read-only ref is allowed.
Notes for 9/6 meeting: I read through the comments, and #917. I agree that this can be closed without further action. |
Closing. |
Describe the bug
In the C# 7.x draft, 12.21.3 could be a bit clearer about input parameters here:
Example
This should be valid.
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
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.
The text was updated successfully, but these errors were encountered: