Possibly unintended reuse of ref
local to in
/ref readonly
parameters causes unexpected mutation
#73438
Labels
ref
local to in
/ref readonly
parameters causes unexpected mutation
#73438
Version Used:
8.0.204
and9.0.100-preview.3.24204.13
.Steps to Reproduce:
false
, which causes the program to outputFalse
twice.This was discovered while I was writing a library, and finally narrowed it down to these two problematic lines.
Changing this would technically be a breaking change, and I assume that perhaps this is in some way intended for optimization reasons. If altering behavior is not desired, I would strongly suggest there to be a warning when two
in
parameters are used within the same scope and of the same type.Diagnostic Id:
N/A
Expected Behavior:
A reference is generated for every value separately, unless it can be proven that sharing the same reference won't affect the program, such as if both variables live in separate scopes and do not have their lifetimes overlap.
Actual Behavior:
A shared reference is used between multiple seemingly unrelated values, causing unexpected changes when a different
in
/ref readonly
method is invoked.The text was updated successfully, but these errors were encountered: