Skip to content

Currying and byref are not friends #819

@manofstick

Description

@manofstick

I though when I had tried this in the past I had got some compiler error, but I'm either mistaken or maybe crafting my function in a different way? (The thought that maybe I was doing something dubious should had stop my inclination to do it, but that is neither here not there) Anyway the following code compiles, but creates invalid IL:

let f (x:byref<bool>) () =
    x <- true

let mutable b = false

let ok () =
    printfn "this is ok!"
    f &b ()
    printfn "%b" b

let notok () =
    // System.Runtime.InteropServices.COMException: Field of ByRef type. (Exception from HRESULT: 0x801312E4)
    printfn "never get here!"
    let f' = f &b 
    f' ()
    printfn "%b" b

ok ()
notok ()

It dies whilst the poor JIT is trying to deal with the notok with the exception as listed in that method..

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions