Skip to content

Different results in Debug + Release for byrefs #5235

@TIHan

Description

@TIHan

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions