This is something @tannergooding found.
The code below:
open System
let cool (doIt) =
let mutable x = 42
let r =
if doIt then
let mutable y = 1
&y
else
&x
let c =
if doIt then
let mutable z = 2
&z
else
&x
x + r + c
[<EntryPoint>]
let main argv =
printfn "Hello World from F#!"
let x = cool(false)
printfn "%i" x
let y = cool(true)
printfn "%i" y
0 // return an integer exit code
Outputs 45 in debug, 46 in release.
Two ways to fix it:
Add scoping for byrefs.
Or.
Fix the optimizer.
This is something @tannergooding found.
The code below:
Outputs
45in debug,46in release.Two ways to fix it:
Add scoping for byrefs.
Or.
Fix the optimizer.