Skip to content

Commit b3f4baa

Browse files
committed
Add CE test that uses let! and and!
1 parent 549f961 commit b3f4baa

File tree

1 file changed

+119
-1
lines changed

1 file changed

+119
-1
lines changed

tests/FSharp.Compiler.ComponentTests/Language/ComputationExpressionTests.fs

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1521,4 +1521,122 @@ let fooTask () : Task<int64> = task {
15211521
is not compatible with type
15221522
'TaskCode<int64,int64>'
15231523
")
1524-
]
1524+
]
1525+
1526+
[<Fact>]
1527+
let ``Version 9.0: and! with type annotations requires parentheses`` () =
1528+
FSharp """
1529+
module Test
1530+
1531+
type ParallelBuilder() =
1532+
member _.Return(x) = async { return x }
1533+
member _.ReturnFrom(computation: Async<'T>) = computation
1534+
member _.Bind(computation: Async<'T>, binder: 'T -> Async<'U>) =
1535+
async {
1536+
let! x = computation
1537+
return! binder x
1538+
}
1539+
member _.Bind2(comp1: Async<'T1>, comp2: Async<'T2>, binder: 'T1 * 'T2 -> Async<'U>) =
1540+
async {
1541+
let! task1 = Async.StartChild comp1
1542+
let! task2 = Async.StartChild comp2
1543+
let! result1 = task1
1544+
let! result2 = task2
1545+
return! binder (result1, result2)
1546+
}
1547+
1548+
member _.Zero() = async.Zero()
1549+
member _.Combine(comp1, comp2) = async.Combine(comp1, comp2)
1550+
member _.Delay(f) = async.Delay(f)
1551+
1552+
let parallelCE = ParallelBuilder()
1553+
1554+
let testParallel() =
1555+
parallelCE {
1556+
let! x = async { return 1 }
1557+
and! y = async { return 2 }
1558+
return x + y
1559+
}
1560+
1561+
let testParallel2() =
1562+
parallelCE {
1563+
let! (x: int) = async { return 1 }
1564+
and! (y: int) = async { return 2 }
1565+
return x + y
1566+
}
1567+
1568+
let testParallel3() =
1569+
parallelCE {
1570+
let! x: int = async { return 1 }
1571+
and! y: int = async { return 2 }
1572+
return x + y
1573+
}
1574+
"""
1575+
|> withLangVersion90
1576+
|> typecheck
1577+
|> shouldFail
1578+
|> withDiagnostics [
1579+
(Error 3350, Line 44, Col 17, Line 44, Col 20, "Feature 'Allow let! and use! type annotations without requiring parentheses' is not available in F# 9.0. Please use language version 'PREVIEW' or greater.");
1580+
(Error 3350, Line 43, Col 14, Line 43, Col 20, "Feature 'Allow let! and use! type annotations without requiring parentheses' is not available in F# 9.0. Please use language version 'PREVIEW' or greater.")
1581+
]
1582+
1583+
[<Fact>]
1584+
let ``Preview: and! with type annotations works without parentheses`` () =
1585+
FSharp """
1586+
module Test
1587+
1588+
type ParallelBuilder() =
1589+
member _.Return(x) = async { return x }
1590+
member _.ReturnFrom(computation: Async<'T>) = computation
1591+
member _.Bind(computation: Async<'T>, binder: 'T -> Async<'U>) =
1592+
async {
1593+
let! x = computation
1594+
return! binder x
1595+
}
1596+
member _.Bind2(comp1: Async<'T1>, comp2: Async<'T2>, binder: 'T1 * 'T2 -> Async<'U>) =
1597+
async {
1598+
let! task1 = Async.StartChild comp1
1599+
let! task2 = Async.StartChild comp2
1600+
let! result1 = task1
1601+
let! result2 = task2
1602+
return! binder (result1, result2)
1603+
}
1604+
1605+
member _.Zero() = async.Zero()
1606+
member _.Combine(comp1, comp2) = async.Combine(comp1, comp2)
1607+
member _.Delay(f) = async.Delay(f)
1608+
1609+
let parallelCE = ParallelBuilder()
1610+
1611+
let testParallel() =
1612+
parallelCE {
1613+
let! x = async { return 1 }
1614+
and! y = async { return 2 }
1615+
return x + y
1616+
}
1617+
1618+
let testParallel2() =
1619+
parallelCE {
1620+
let! (x: int) = async { return 1 }
1621+
and! (y: int) = async { return 2 }
1622+
return x + y
1623+
}
1624+
1625+
let testParallel3() =
1626+
parallelCE {
1627+
let! x: int = async { return 1 }
1628+
and! y: int = async { return 2 }
1629+
return x + y
1630+
}
1631+
1632+
let result = testParallel() |> Async.RunSynchronously
1633+
let result2 = testParallel2() |> Async.RunSynchronously
1634+
let result3 = testParallel3() |> Async.RunSynchronously
1635+
if result <> 3 then failwithf $"Expected 3, but got {result}"
1636+
if result2 <> 3 then failwithf $"Expected 3, but got {result2}"
1637+
if result3 <> 3 then failwithf $"Expected 3, but got {result3}"
1638+
"""
1639+
|> withLangVersionPreview
1640+
|> asExe
1641+
|> compileAndRun
1642+
|> shouldSucceed

0 commit comments

Comments
 (0)