Allow _
in use bindings
#11630
Allow _
in use bindings
#11630
Conversation
I also checked the runtime behavior in F# interactive with this: type Disposable() =
do printfn "constructed"
interface System.IDisposable with
member _.Dispose() = printfn "disposed!"
let answer =
use _ = new Disposable()
42 Output:
This ensures that right the hand side of the binding is only evaluated once, and that Not sure if there's a good way to make it (e.g. runtime behavior) into a feature test. |
Here is an example test with runtime testing. https://github.com/dotnet/fsharp/blob/a96d7ceb2a5b95cccee8d7febe4188369a8e14be/tests/FSharp.Compiler.ComponentTests/Language/CodeQuotationTests.fs |
Added runtime test too. |
This will require a langversion check as well. See here for an example of how to guard for the language feature: https://github.com/dotnet/fsharp/pull/11603/files Otherwise, this looks great, thanks! |
let ``Dispose called for discarded value of use binding`` () = | ||
Fsx """ | ||
type private Disposable() = | ||
[<DefaultValue>] static val mutable private disposed: bool |
Happypig375
Jun 7, 2021
Contributor
It's a bit weird that you check that the constructor is called exactly once but the Dispose method being called more than once still succeeds :)
It's a bit weird that you check that the constructor is called exactly once but the Dispose method being called more than once still succeeds :)
…n TcLetBinding implements fsharp/fslang-suggestions#881 and https://github.com/fsharp/fslang-design/blob/6c1ba3425c6129f1b6cf22ac8ddec30761136a12/RFCs/FS-1102-discards-on-use-bindings.md has basic test UseBindingDiscard01, that ensures, that `use _ = new Disposable()` type checks has runtime test "Dispose called for discarded value of use binding"
@cartermp got us a langver check. |
Thanks! This looks great. |
Adds special case check for
TPat_wild
inTcLetBinding
Implements fsharp/fslang-suggestions#881 and https://github.com/fsharp/fslang-design/blob/6c1ba3425c6129f1b6cf22ac8ddec30761136a12/RFCs/FS-1102-discards-on-use-bindings.md
Has basic test
UseBindingDiscard01
, that ensures, thatuse _ = new Disposable()
type checks