Cannot assign to byref-returning type functions #18313
Labels
Area-Compiler-Checking
Type checking, attributes and all aspects of logic checking
Bug
Impact-Low
(Internal MS Team use only) Describes an issue with limited impact on existing code.
Milestone
When a
let
-bound value with type parameters is of abyref
type, assignment to this value incorrectly requires abyref
value.Repro steps
Expected behavior
The assignment succeeds and results in a modification to
Storage<int>.value
.Actual behavior
The assignment fails to compile:
The compiler can detect that the value is mutable (otherwise there would be an error about assignment to non-mutable location), but a wrong type is required.
Known workarounds
Turning the value into a normal function (i.e.
let cached<'T>()
andcached<int>() <-
works fine.Related information
It seems this issue affects all uses of
cached<'T>
that involve byrefs or assignments, for example:Environment: https://sharplab.io/#v2:DYLgZgzgPgLgngBwKYAIDKMD2AnAhgcyQB4ByAFQD4UBeAWACgUUIZcYBLAYxWCRhQC2AV1YAjXigBuuYENTUUAVQB2nABZJOAayQATAHS6kYXEOBYwpSgyYs2XQUgGik2FAiHiHANRlyASsY0KABk0rJIDAwA2kQA4kjKrjLsAF644ki+ERQAugy8/Jy46npWFCAoonDYxkQA+lQKIRg4BMTkFPrZAcZR9LqYNijFpbpE7MowVEQAtCgAjMMAFACUDEA===
The text was updated successfully, but these errors were encountered: