dotnet / dotnet/fsharp

[From VSTS] Getting ref to static mutable field is an error in F# 4.5

Open
#5,420 6 comments 0 reactions 0 assignees View on GitHub
Feature Request Needs-RFC
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

Referencing a class static mutable field via & stopped compiling in F# 4.5. Example:

```fsharp
type MyClass () =
[]
static val mutable private nextInstanceIndex : int
static do
MyClass.nextInstanceIndex <- 1
let instanceIndex = System.Threading.Interlocked.Increment(&MyClass.nextInstanceIndex) - 1
```

Compilation results in error FS3236: Cannot take the address of the value returned from the expression. Assign the returned value to a let-bound value before taking the address.

_This issue has been moved from https://developercommunity.visualstudio.com/content/problem/301281/getting-ref-to-static-mutable-field-is-an-error-in.html
VSTS ticketId: 655347_
_These are the original issue comments:_

James Horvath on 7/27/2018, 08:32 AM (3 days ago):

Here's that code formatted:

type MyClass () =

[<DefaultValue>]
static val mutable private nextInstanceIndex : int
static do
MyClass.nextInstanceIndex <- 1
let instanceIndex = System.Threading.Interlocked.Increment(&MyClass.nextInstanceIndex) - 1

_These are the original issue solutions:_
(no solutions)

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.