Skip to content

Volatile.Read can no longer read ref (instead it wants inref) #16524

@radekm

Description

@radekm

Please provide a succinct description of the issue.

Repro steps

I have a following global variable defined in a module

let currentData : Data ref = ref { Timestamp = DateTimeOffset.MinValue
                                   Foo = None
                                   Bar = []
                                 }

and I read its value in some function via Volatile.Read:

// `toJson` has type `Data -> byte array`.
let json = Data.toJson (Volatile.Read currentData)

Expected behavior

The code should type check (it type checked on net7 and also initially on net8).

Actual behavior

After updating .NET 8 it doesn't type check with error:

error FS0041: No overloads match for method 'Read'. Known type of argument: Data ref
Available overloads:
- Volatile.Read(location: inref<bool>) : bool // Argument 'location' doesn't match
- Volatile.Read(location: inref<byte>) : byte // Argument 'location' doesn't match
...
- Volatile.Read<'T when 'T: not struct>(location: inref<'T>) : 'T // Argument 'location' doesn't match

I think that the last mentioned overload should work but it seems that ref<Data> argument
can't be given to inref<Data> parameter.

Known workarounds

Don't know.

Related information

Provide any related information (optional):

  • Tested under Windows, Linux, Mac (x86-64)
  • Type checked on .NET 8.0.100, doesn't work on .NET 8.0.101
  • Can it be related to 54d05be?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions