You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/release-notes/.FSharp.Compiler.Service/9.0.200.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,5 +18,6 @@
18
18
* Better ranges for CE `do!` error reporting. ([PR #17779](https://github.com/dotnet/fsharp/pull/17779))
19
19
* Better ranges for CE `return, yield, return! and yield!` error reporting. ([PR #17792](https://github.com/dotnet/fsharp/pull/17792))
20
20
* Better ranges for CE `match!`. ([PR #17789](https://github.com/dotnet/fsharp/pull/17789))
21
+
* Better ranges for CE `use` error reporting. ([PR #17811](https://github.com/dotnet/fsharp/pull/17811))
Copy file name to clipboardExpand all lines: tests/FSharp.Compiler.ComponentTests/Language/ComputationExpressionTests.fs
+81Lines changed: 81 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -644,4 +644,85 @@ let indexHandler (): Task<string> =
644
644
'string'
645
645
but here has type
646
646
'Task<bool>' ")
647
+
]
648
+
649
+
[<Fact>]
650
+
let``use expressions may not be used in queries(SynExpr.Sequential)`` ()=
651
+
Fsx """
652
+
let x11 =
653
+
query { for c in [1..10] do
654
+
use x = { new System.IDisposable with __.Dispose() = () }
655
+
yield 1 }
656
+
"""
657
+
|> ignoreWarnings
658
+
|> typecheck
659
+
|> shouldFail
660
+
|> withDiagnostics [
661
+
(Error 3142, Line 4, Col 13, Line 4, Col 16,"'use' expressions may not be used in queries")
662
+
]
663
+
664
+
[<Fact>]
665
+
let``use,This control construct may only be used if the computation expression builder defines a 'Using' method`` ()=
666
+
Fsx """
667
+
module Result =
668
+
let zip x1 x2 =
669
+
match x1,x2 with
670
+
| Ok x1res, Ok x2res -> Ok (x1res, x2res)
671
+
| Error e, _ -> Error e
672
+
| _, Error e -> Error e
673
+
674
+
type ResultBuilder() =
675
+
member _.MergeSources(t1: Result<'T,'U>, t2: Result<'T1,'U>) = Result.zip t1 t2
676
+
member _.BindReturn(x: Result<'T,'U>, f) = Result.map f x
677
+
678
+
member _.YieldReturn(x: Result<'T,'U>) = x
679
+
member _.Return(x: 'T) = Ok x
680
+
681
+
let result = ResultBuilder()
682
+
683
+
let run r2 r3 =
684
+
result {
685
+
use b = r2
686
+
return Ok 0
687
+
}
688
+
"""
689
+
|> ignoreWarnings
690
+
|> typecheck
691
+
|> shouldFail
692
+
|> withDiagnostics [
693
+
(Error 708, Line 20, Col 9, Line 20, Col 12,"This control construct may only be used if the computation expression builder defines a 'Using' method")
694
+
]
695
+
696
+
[<Fact>]
697
+
let``This 'let' definition may not be used in a query. Only simple value definitions may be used in queries.`` ()=
698
+
Fsx """
699
+
let x18rec2 =
700
+
query {
701
+
for d in [1..10] do
702
+
let rec f x = x + 1 // error expected here - no recursive functions
703
+
and g x = f x + 2
704
+
select (f d)
705
+
}
706
+
707
+
let x18inline =
708
+
query {
709
+
for d in [1..10] do
710
+
let inline f x = x + 1 // error expected here - no inline functions
711
+
select (f d)
712
+
}
713
+
714
+
let x18mutable =
715
+
query {
716
+
for d in [1..10] do
717
+
let mutable v = 1 // error expected here - no mutable values
718
+
select (f d)
719
+
}
720
+
721
+
"""
722
+
|> typecheck
723
+
|> shouldFail
724
+
|> withDiagnostics [
725
+
(Error 3147, Line 5, Col 17, Line 5, Col 20,"This 'let' definition may not be used in a query. Only simple value definitions may be used in queries.")
726
+
(Error 3147, Line 13, Col 20, Line 13, Col 23,"This 'let' definition may not be used in a query. Only simple value definitions may be used in queries.")
727
+
(Error 3147, Line 20, Col 21, Line 20, Col 22,"This 'let' definition may not be used in a query. Only simple value definitions may be used in queries.")
0 commit comments