roslyn icon indicating copy to clipboard operation
roslyn copied to clipboard

Fix confusing `ref` usage error messages

Open jjonescz opened this issue 1 year ago • 3 comments

Fixes #62756

jjonescz avatar Sep 21 '22 12:09 jjonescz

@dotnet/roslyn-compiler ready for review

jjonescz avatar Sep 22 '22 12:09 jjonescz

Done with review pass (commit 3)

AlekseyTs avatar Sep 22 '22 14:09 AlekseyTs

Consider an alternative approach - simply adjusting the wording of the error message to include the RHS of an assignment situation. For example, instead of saying: "Cannot assign to variable 'x' because it is a readonly variable." We could say: "Cannot assign to variable 'x' or use it as the right hand side of a ref assignment because it is a readonly variable." Then we wouldn't need to make any changes to the analysis that compiler performs.

AlekseyTs avatar Sep 22 '22 15:09 AlekseyTs

Consider an alternative approach - simply adjusting the wording of the error message to include the RHS of an assignment situation. For example, instead of saying: "Cannot assign to variable 'x' because it is a readonly variable." We could say: "Cannot assign to variable 'x' or use it as the right hand side of a ref assignment because it is a readonly variable." Then we wouldn't need to make any changes to the analysis that compiler performs.

Sounds good, I didn't realize that is a possibility. Opened a new PR for that: #64241

jjonescz avatar Sep 23 '22 10:09 jjonescz