Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow
_
in use bindings by checking for special case of TPat_wild i…
…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"
- Loading branch information
Showing
4 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...FSharp.Compiler.ComponentTests/Conformance/DeclarationElements/LetBindings/UseBindings.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. | ||
|
||
namespace FSharp.Compiler.ComponentTests.Conformance.DeclarationElements.LetBindings | ||
|
||
open Xunit | ||
open FSharp.Test.Utilities.Compiler | ||
open FSharp.Test.Utilities.Xunit.Attributes | ||
|
||
module UseBindings = | ||
|
||
[<Theory; Directory(__SOURCE_DIRECTORY__ + "/../../../resources/tests/Conformance/DeclarationElements/LetBindings", Includes=[|"UseBindingDiscard01.fs"|])>] | ||
let ``UseBindings - UseBindingDiscard01.fs - `` compilation = | ||
compilation | ||
|> asFsx | ||
|> compile | ||
|> shouldSucceed | ||
|> ignore | ||
|
||
[<Fact>] | ||
let ``Dispose called for discarded value of use binding`` () = | ||
Fsx """ | ||
type private Disposable() = | ||
[<DefaultValue>] static val mutable private disposed: bool | ||
[<DefaultValue>] static val mutable private constructedTimes: int | ||
do Disposable.constructedTimes <- Disposable.constructedTimes + 1 | ||
static member WasDisposed() = Disposable.disposed | ||
static member ConsturctorCallCount() = Disposable.constructedTimes | ||
interface System.IDisposable with | ||
member _.Dispose() = | ||
Disposable.disposed <- true | ||
let _scope = | ||
use _ = new Disposable() | ||
() | ||
if not(Disposable.WasDisposed()) then | ||
failwith "was not disposed" | ||
let ctorCalls = Disposable.ConsturctorCallCount() | ||
if ctorCalls <> 1 then | ||
failwithf "unexpected constructor call count: %i" ctorCalls | ||
""" | ||
|> asExe | ||
|> withLangVersionPreview | ||
|> compileAndRun | ||
|> shouldSucceed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...tTests/resources/tests/Conformance/DeclarationElements/LetBindings/UseBindingDiscard01.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// #DeclarationElements #LetBindings | ||
//<Expects status="success"></Expects> | ||
|
||
let answer = | ||
use _ = new System.IO.MemoryStream() | ||
42 |