Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Fix eaten async for function with labelled args #676

Closed
wants to merge 2 commits into from
Closed
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
18 changes: 18 additions & 0 deletions src/res_parsetree_viewer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ let processFunctionAttributes attrs =
in
process false false [] attrs

let hasAsyncAttribute attrs =
List.exists
(function
| {Location.txt = "res.async"}, _ -> true
| _ -> false)
attrs

let hasAwaitAttribute attrs =
List.exists
(function
Expand Down Expand Up @@ -177,6 +184,17 @@ let funExpr expr =
pexp_attributes = attrs;
} as expr ->
collect attrs [] {expr with pexp_attributes = []}
| {
pexp_desc = Pexp_fun (_, _defaultExpr, _pattern, _returnExpr);
pexp_attributes = attrs;
} as expr
when hasAsyncAttribute attrs ->
let asyncAttr =
List.filter
(fun (({txt}, _) : Parsetree.attribute) -> txt = "res.async")
attrs
in
collect asyncAttr [] {expr with pexp_attributes = []}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This throws away all the other attributes, if there are some.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct.

| expr -> collect [] [] expr

let processBracesAttr expr =
Expand Down
6 changes: 5 additions & 1 deletion tests/printer/expr/asyncAwait.res
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,8 @@ let _ = await {x}
let _ = await {
let x = 1
Js.Promise.resolve(x)
}
}

let _ = async x => x
let _ = async (~x) => x
let _ = async (~x, ~y) => x + y
4 changes: 4 additions & 0 deletions tests/printer/expr/expected/asyncAwait.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,7 @@ let _ = await {
let x = 1
Js.Promise.resolve(x)
}

let _ = async (x) => x
let _ = async (~x) => x
let _ = async (~x, ~y) => x + y