Skip to content

inref arguments imported as byref arguments in external libraries #16265

@thinkbeforecoding

Description

@thinkbeforecoding

Please provide a succinct description of the issue.

With net 8.0 rc2 installed, F# doesn't recognize inref parameters correctly and loads thems as byref.
This makes F# on net 8.0 unusable for some low level code 😬as it is impossible to create ReadOnlySpans etc..

Provide the steps required to reproduce the problem:

  1. Create a global.json with version 8.0.100-rc.2.23502.2
  2. Create a the following fsx script:
let f (x: int) =
    System.ReadOnlySpan(&x)
  1. It reports the following error:
No overloads match for method 'ReadOnlySpan`1'.

Known type of argument: inref<int>

Available overloads:
 - ReadOnlySpan(array: 'a array) : ReadOnlySpan<'a> // Argument 'array' doesn't match
 - ReadOnlySpan(reference: byref<'a>) : ReadOnlySpan<'a> // Argument 'reference' doesn't match

Notice that the second overload should be of type inref<'a>
4. Replace version in global.json with 7.0.403 and reopen the script. There is no error.

You can test it with the System.Runtime.CompilerServices.Unsafe.AsRef as well.

Expected behavior

The argument type should be inref<'a> and there should be no error

Actual behavior

The argument type is byref<'a> which is incorrect. This seems to happen with all inref arguments.

Known workarounds

Stay on net6.0/net7.0 😬

Related information

Provide any related information (optional):

  • Windows 11
  • .NET Runtime kind: net 8.0 rc2
  • Editing Tools: VS 2022 Version 17.8.0 Preview 7.0, VS Code

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions