Fable
Fable copied to clipboard
[<FSharp.Core.DefaultValue>] not handled properly on static fields
Description
When a static field has the [<FSharp.Core.DefaultValue>] attribute, Fable leaves its value as undefined, which can have different behavior than the .NET default value.
Repro code
type Foo() =
[<FSharp.Core.DefaultValue>]
static val mutable private count : int
static member IncrCount() =
Foo.count <- Foo.count + 1
Foo.count
printfn "%d" (Foo.IncrCount())
Expected and actual results
dotnet fsi prints: 1
Fable REPL prints: 0
Related information
- Fable version: 3.7.0-beta-011
- Operating system: macOS 10.15.7
I found a workaround: save the static field to a local first. This works as expected:
static member IncrCount() =
let count = Foo.count
Foo.count <- count + 1
Foo.count