Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Fable.Cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

* [Python] Fix missing `await` on else branch of ternary expressions in async closures (by @dbrattli)
* [Beam] Fix `|> ignore` on cross-module Emit calls generating variable bindings that shadow Emit case-clause variables (by @dbrattli)
* [Beam] Fix `containsIdentRef` not checking `Call` ThisArg (by @dbrattli)
* [All] Fix CLI color not resetting after error messages (fixes #3755) (by @MangelMaxime)
Expand Down
1 change: 1 addition & 0 deletions src/Fable.Compiler/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

* [Python] Fix missing `await` on else branch of ternary expressions in async closures (by @dbrattli)
* [Beam] Fix `|> ignore` on cross-module Emit calls generating variable bindings that shadow Emit case-clause variables (by @dbrattli)
* [Beam] Fix `containsIdentRef` not checking `Call` ThisArg (by @dbrattli)
* [JS/TS] `StringEnum` now respect `CompiledValue` and `CompiledName` (by @shayanhabibi)
Expand Down
2 changes: 1 addition & 1 deletion src/Fable.Transforms/Python/PythonPrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ module PrinterExtensions =
| Name ex -> printer.Print(ex)
| Await ex ->
printer.Print("await ")
printer.Print(ex)
printer.ComplexExpressionWithParens(ex)
| Yield expr ->
printer.Print("yield")

Expand Down
20 changes: 20 additions & 0 deletions tests/Python/TestTask.fs
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,23 @@ let ``test async returns in try-with are awaited`` () =

let result2 = wrapper true |> fun tsk -> tsk.GetAwaiter().GetResult()
equal -1 result2

// Regression: closure with let binding before if/else returning Task emits ternary;
// both branches of the ternary must be awaited.
let asyncNone () : Task<int option> = Task.FromResult None

let makeClosure (flag: bool) =
let captured = flag
fun (value: int) ->
let x = value + 1
if captured then Task.FromResult(Some x) else asyncNone ()

[<Fact>]
let ``test async ternary in closure awaits both branches`` () =
let fn = makeClosure true
let result = fn 41 |> fun tsk -> tsk.GetAwaiter().GetResult()
equal (Some 42) result

let fn2 = makeClosure false
let result2 = fn2 41 |> fun tsk -> tsk.GetAwaiter().GetResult()
equal None result2
Loading