Skip to content

Commit

Permalink
Add more test
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarfgp committed Sep 19, 2024
1 parent 499cb6e commit 16e300b
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1589,10 +1589,10 @@ let rec TryTranslateComputationExpression
Some(TranslateComputationExpression ceenv CompExprTranslationPass.Initial q varSpace innerComp2 translatedCtxt)

else

if ceenv.isQuery && not (innerComp1.IsArbExprAndThusAlreadyReportedError) then
match innerComp1 with
| SynExpr.JoinIn _ -> () // an error will be reported later when we process innerComp1 as a sequential
| SynExpr.JoinIn _ -> ()
| SynExpr.DoBang(range = m) -> errorR (Error(FSComp.SR.tcBindMayNotBeUsedInQueries (), m))
| _ -> errorR (Error(FSComp.SR.tcUnrecognizedQueryOperator (), innerComp1.RangeOfFirstPortion))

match
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,130 @@ let run r2 r3 =
|> shouldFail
|> withDiagnostics [
(Error 708, Line 23, Col 9, Line 23, Col 13, "This control construct may only be used if the computation expression builder defines a 'Bind' method")
]

[<Fact>]
let ``do! expressions may not be used in queries`` () =
Fsx """
query {
do! failwith ""
yield 1
}
"""
|> ignoreWarnings
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 3143, Line 3, Col 5, Line 3, Col 20, "'let!', 'use!' and 'do!' expressions may not be used in queries")
]

[<Fact>]
let ``let! expressions may not be used in queries`` () =
Fsx """
query {
let! x = failwith ""
yield 1
}
"""
|> ignoreWarnings
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 3143, Line 3, Col 5, Line 3, Col 9, "'let!', 'use!' and 'do!' expressions may not be used in queries")
]

[<Fact>]
let ``let!, and! expressions may not be used in queries`` () =
Fsx """
query {
let! x = failwith ""
and! y = failwith ""
yield 1
}
"""
|> ignoreWarnings
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 3143, Line 3, Col 5, Line 3, Col 9, "'let!', 'use!' and 'do!' expressions may not be used in queries")
]

[<Fact>]
let ``use! expressions may not be used in queries`` () =
Fsx """
query {
use! x = failwith ""
yield 1
}
"""
|> ignoreWarnings
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 3143, Line 3, Col 5, Line 3, Col 9, "'let!', 'use!' and 'do!' expressions may not be used in queries")
]

[<Fact>]
let ``do! expressions may not be used in queries(SynExpr.Sequential)`` () =
Fsx """
query {
for c in [1..10] do
do! failwith ""
yield 1
}
"""
|> ignoreWarnings
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 3143, Line 4, Col 5, Line 4, Col 20, "'let!', 'use!' and 'do!' expressions may not be used in queries")
]

[<Fact>]
let ``let! expressions may not be used in queries(SynExpr.Sequential)`` () =
Fsx """
query {
for c in [1..10] do
let! x = failwith ""
yield 1
}
"""
|> ignoreWarnings
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 3143, Line 4, Col 5, Line 4, Col 9, "'let!', 'use!' and 'do!' expressions may not be used in queries")
]

[<Fact>]
let ``let!, and! expressions may not be used in queries(SynExpr.Sequential)`` () =
Fsx """
query {
for c in [1..10] do
let! x = failwith ""
and! y = failwith ""
yield 1
}
"""
|> ignoreWarnings
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 3143, Line 4, Col 5, Line 4, Col 9, "'let!', 'use!' and 'do!' expressions may not be used in queries")
]

[<Fact>]
let ``use! expressions may not be used in queries(SynExpr.Sequential)`` () =
Fsx """
query {
for c in [1..10] do
use! x = failwith ""
yield 1
}
"""
|> ignoreWarnings
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 3143, Line 4, Col 5, Line 4, Col 9, "'let!', 'use!' and 'do!' expressions may not be used in queries")
]
2 changes: 0 additions & 2 deletions tests/fsharp/typecheck/sigs/neg61.bsl
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ neg61.fs(92,13,92,70): typecheck error FS3142: 'use' expressions may not be used

neg61.fs(97,13,97,17): typecheck error FS3143: 'let!', 'use!' and 'do!' expressions may not be used in queries

neg61.fs(102,13,102,28): typecheck error FS3145: This is not a known query operator. Query operators are identifiers such as 'select', 'where', 'sortBy', 'thenBy', 'groupBy', 'groupValBy', 'join', 'groupJoin', 'sumBy' and 'averageBy', defined using corresponding methods on the 'QueryBuilder' type.

neg61.fs(102,13,102,28): typecheck error FS3143: 'let!', 'use!' and 'do!' expressions may not be used in queries

neg61.fs(107,13,107,21): typecheck error FS3144: 'return' and 'return!' may not be used in queries
Expand Down

0 comments on commit 16e300b

Please sign in to comment.