dotnet / dotnet/fsharp

Unable to create a byref-like DU holding a ref type

Open
#18,512 3 comments 0 reactions 0 assignees View on GitHub
Area-Compiler-Checking Area-Compiler-Checking-Byref Feature Improvement
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

Please provide a succinct description of the issue.

Try to create a byref-like discriminated union holding a byref type (ex. Span)

Provide the steps required to reproduce the problem:

```fs
open System
open System.Runtime.CompilerServices

[]
type Record = { inner: ReadOnlySpan }

[]
type Discrim = | Case of ReadOnlySpan

let record (x: ReadOnlySpan) = { inner = x } // Works!
let discrim (x: ReadOnlySpan) = Case(x) // Does not :(
```

**Expected behavior**

No errors

**Actual behavior**

`error FS0418: The byref typed value 'x' cannot be used at this point`

**Known workarounds**

None so far.

**Related information**

Provide any related information (optional):

* Operating system
* .NET Runtime kind (.NET Core, .NET Framework, Mono)
* Editing Tools (e.g. Visual Studio Version, Visual Studio)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.