New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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