You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a let-bound value with type parameters is of a byref type, assignment to this value incorrectly requires a byref value.
Repro steps
typeStorage<'T>=static let mutablevalue= Unchecked.defaultof<'T>static memberpublicValueRef=&value
[<GeneralizableValue>]letcached<'T>:byref<_>=&Storage<'T>.ValueRef
do
cached<int><-1()
Expected behavior
The assignment succeeds and results in a modification to Storage<int>.value.
Actual behavior
The assignment fails to compile:
error FS0001: This expression was expected to have type
'byref<int>'
but here has type
'int'
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>() and cached<int>() <- works fine.
Related information
It seems this issue affects all uses of cached<'T> that involve byrefs or assignments, for example:
dolet mutabler:byref<_>=&cached<int>// Expecting a 'byref<byref<int>>' but given a 'inref<byref<int>>'let mutablea=1
a <- cached<int>// expected to have type 'int' but here has type 'byref<int>'
cached<int><-&a // Type 'byref<byref<int>>' is illegal because in byref<T>, T cannot contain byref types.
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: