The Wayback Machine - https://web.archive.org/web/20210609145536/https://github.com/dotnet/fsharp/pull/11630
Skip to content
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

Merged
merged 2 commits into from Jun 9, 2021
Merged

Allow _ in use bindings #11630

merged 2 commits into from Jun 9, 2021

Conversation

@lostmsu
Copy link
Contributor

@lostmsu lostmsu commented Jun 4, 2021

Adds special case check for TPat_wild in 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

@lostmsu
Copy link
Contributor Author

@lostmsu lostmsu commented Jun 4, 2021

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:

constructed
disposed!

This ensures that right the hand side of the binding is only evaluated once, and that Dispose is actually being called.

Not sure if there's a good way to make it (e.g. runtime behavior) into a feature test.

@lostmsu lostmsu force-pushed the lostmsu:UseWild branch from a96d7ce to cb8456e Jun 7, 2021
@lostmsu
Copy link
Contributor Author

@lostmsu lostmsu commented Jun 7, 2021

Added runtime test too.

Copy link
Contributor

@cartermp cartermp left a comment

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

This comment has been minimized.

@Happypig375

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 :)

@lostmsu lostmsu force-pushed the lostmsu:UseWild branch from cb8456e to 9b4c8b8 Jun 7, 2021
@lostmsu
Copy link
Contributor Author

@lostmsu lostmsu commented Jun 7, 2021

@cartermp got us a langver check.

Copy link
Contributor

@cartermp cartermp left a comment

Thanks! This looks great.

@vzarytovskii vzarytovskii merged commit 412f147 into dotnet:main Jun 9, 2021
14 checks passed
14 checks passed
@azure-pipelines
fsharp-ci Build #20210607.29 succeeded
Details
@azure-pipelines
fsharp-ci (Build EndToEndBuildTests) Build EndToEndBuildTests succeeded
Details
@azure-pipelines
fsharp-ci (Build Linux) Build Linux succeeded
Details
@azure-pipelines
fsharp-ci (Build MacOS) Build MacOS succeeded
Details
@azure-pipelines
fsharp-ci (Build MockOfficial) Build MockOfficial succeeded
Details
@azure-pipelines
fsharp-ci (Build Plain_Build_Linux) Build Plain_Build_Linux succeeded
Details
@azure-pipelines
fsharp-ci (Build Plain_Build_MacOS) Build Plain_Build_MacOS succeeded
Details
@azure-pipelines
fsharp-ci (Build Source-Build (Managed)) Build Source-Build (Managed) succeeded
Details
@azure-pipelines
fsharp-ci (Build Source-Build Complete) Build Source-Build Complete succeeded
Details
@azure-pipelines
fsharp-ci (Build Windows coreclr_release) Build Windows coreclr_release succeeded
Details
@azure-pipelines
fsharp-ci (Build Windows desktop_release) Build Windows desktop_release succeeded
Details
@azure-pipelines
fsharp-ci (Build Windows fsharpqa_release) Build Windows fsharpqa_release succeeded
Details
@azure-pipelines
fsharp-ci (Build Windows vs_release) Build Windows vs_release succeeded
Details
license/cla All CLA requirements met.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants