Skip to content

Implicit Action/Func conversion captures extra expressions #18953

@kerams

Description

@kerams

Repro steps

let x (f: System.Action<int>) =
    f.Invoke 99
    f.Invoke 98
    printfn "here"

let y () =
    printfn  "one time"
    fun num -> printfn "%d" num
    
x (y ())

Expected behavior

Prints

one time
99
98
here

which is what would've been printed with (f: int -> unit) instead of Action<int>

Actual behavior

Prints

one time
99
one time
98
here

because x (y ()) is unexpectedly(?) expanded into x (Action<int> (fun num -> y () num)).

Known workarounds

Bind y () first, manually wrap fun num ... in an Action, etc.

Related information

  • SDK 10.0.100-rc.1.25451.107

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Compiler-CodeGenIlxGen, ilwrite and things at the backendArea-Diagnosticsmistakes and possible improvements to diagnosticsBug

    Type

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions