File tree 5 files changed +81
-16
lines changed
tests/FSharp.Compiler.ComponentTests
Conformance/BasicGrammarElements/UseBindings
5 files changed +81
-16
lines changed Original file line number Diff line number Diff line change
1
+ // #DeclarationElements #LetBindings
2
+ //<Expects status="success"></Expects>
3
+ open System
4
+
5
+ let answer =
6
+ use x: IDisposable = new System.IO.MemoryStream()
7
+ 42
Original file line number Diff line number Diff line change
1
+ open System
2
+
3
+ type private Disposable () =
4
+ [<DefaultValue>] static val mutable private disposedTimes : int
5
+ [<DefaultValue>] static val mutable private constructedTimes : int
6
+
7
+ do Disposable.constructedTimes <- Disposable.constructedTimes + 1
8
+
9
+ static member DisposeCallCount () = Disposable.disposedTimes
10
+ static member ConstructorCallCount () = Disposable.constructedTimes
11
+
12
+ interface System.IDisposable with
13
+ member _.Dispose () =
14
+ Disposable.disposedTimes <- Disposable.disposedTimes + 1
15
+
16
+ let _scope =
17
+ use x: IDisposable = new Disposable()
18
+ ()
19
+
20
+ let disposeCalls = Disposable.DisposeCallCount()
21
+ if disposeCalls <> 1 then
22
+ failwith " was not disposed or disposed too many times"
23
+
24
+ let ctorCalls = Disposable.ConstructorCallCount()
25
+ if ctorCalls <> 1 then
26
+ failwithf " unexpected constructor call count: %i " ctorCalls
Original file line number Diff line number Diff line change
1
+ open System
2
+
3
+ type private Disposable () =
4
+ [<DefaultValue>] static val mutable private disposedTimes : int
5
+ [<DefaultValue>] static val mutable private constructedTimes : int
6
+
7
+ do Disposable.constructedTimes <- Disposable.constructedTimes + 1
8
+
9
+ static member DisposeCallCount () = Disposable.disposedTimes
10
+ static member ConstructorCallCount () = Disposable.constructedTimes
11
+
12
+ interface System.IDisposable with
13
+ member _.Dispose () =
14
+ Disposable.disposedTimes <- Disposable.disposedTimes + 1
15
+
16
+ let _scope =
17
+ use _: IDisposable = new Disposable()
18
+ ()
19
+
20
+ let disposeCalls = Disposable.DisposeCallCount()
21
+ if disposeCalls <> 1 then
22
+ failwith " was not disposed or disposed too many times"
23
+
24
+ let ctorCalls = Disposable.ConstructorCallCount()
25
+ if ctorCalls <> 1 then
26
+ failwithf " unexpected constructor call count: %i " ctorCalls
Original file line number Diff line number Diff line change @@ -33,4 +33,25 @@ module UseBindings =
33
33
|> asExe
34
34
|> withLangVersion60
35
35
|> compileAndRun
36
- |> shouldSucceed
36
+ |> shouldSucceed
37
+
38
+ [<Theory; Directory(__ SOURCE_ DIRECTORY__, Includes=[| " UseBindingDiscard03.fs" |]) >]
39
+ let ``UseBindings - UseBindingDiscard03_fs - Current LangVersion`` compilation =
40
+ compilation
41
+ |> asExe
42
+ |> compileAndRun
43
+ |> shouldSucceed
44
+
45
+ [<Theory; Directory(__ SOURCE_ DIRECTORY__, Includes=[| " UseBinding01.fs" |]) >]
46
+ let ``UseBindings - UseBinding01_fs - Current LangVersion`` compilation =
47
+ compilation
48
+ |> asFsx
49
+ |> compile
50
+ |> shouldSucceed
51
+
52
+ [<Theory; Directory(__ SOURCE_ DIRECTORY__, Includes=[| " UseBinding02.fs" |]) >]
53
+ let ``UseBindings - UseBinding02_fs - Current LangVersion`` compilation =
54
+ compilation
55
+ |> asFsx
56
+ |> compile
57
+ |> shouldSucceed
Original file line number Diff line number Diff line change @@ -22,21 +22,6 @@ let x = lb {1; 2;}
22
22
|> compile
23
23
|> shouldSucceed
24
24
|> ignore
25
-
26
- [<Fact>]
27
- let ``Allow let ! and use ! binding with type annotation without parentheses.`` () =
28
- FSharp """
29
- module ComputationExpressionTests
30
- let f =
31
- async {
32
- let! (a: int) = async { return 1 }
33
- let! b: int = async { return 1 }
34
- return a
35
- }
36
- """
37
- |> typecheck
38
- |> shouldSucceed
39
- |> ignore
40
25
41
26
[<Fact>]
42
27
let ``A CE explicitly using Zero fails without a defined Zero`` () =
You can’t perform that action at this time.
0 commit comments