Skip to content

Commit b21f734

Browse files
committed
Fix location issue for the treatment of async functions
Fixes https://github.com/rescript-lang/rescript-vscode/issues/698
1 parent 44286be commit b21f734

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ These are only breaking changes for unformatted code.
6565
- Fix issue in `Js.Promise2` where `then` and `catch` were returning `undefined` https://github.com/rescript-lang/rescript-compiler/pull/5997
6666
- Fix formatting of props spread for multiline JSX expression https://github.com/rescript-lang/rescript-compiler/pull/6006
6767
- Fix issue in the compiler back-end where async functions passed to an `@uncurry` external would be inlined and transformed in a way that loses async https://github.com/rescript-lang/rescript-compiler/pull/6010
68+
- Fix location issue for the treatment of `async` functions where hovering on the body with a type error would show `'a => promise<'a>` everywhere https://github.com/rescript-lang/rescript-compiler/pull/6012
6869

6970
#### :nail_care: Polish
7071

jscomp/frontend/ast_async.ml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
let add_promise_type ~async (result : Parsetree.expression) =
1+
let add_promise_type ?(loc=Location.none) ~async (result : Parsetree.expression) =
22
if async then
3-
let loc = result.pexp_loc in
43
let unsafe_async =
54
Ast_helper.Exp.ident ~loc
65
{ txt = Ldot (Ldot (Lident "Js", "Promise"), "unsafe_async"); loc }
@@ -18,16 +17,16 @@ let add_async_attribute ~async (body : Parsetree.expression) =
1817
}
1918
else body
2019

21-
let rec add_promise_to_result (e : Parsetree.expression) =
20+
let rec add_promise_to_result ~loc (e : Parsetree.expression) =
2221
match e.pexp_desc with
2322
| Pexp_fun (label, eo, pat, body) ->
24-
let body = add_promise_to_result body in
23+
let body = add_promise_to_result ~loc body in
2524
{ e with pexp_desc = Pexp_fun (label, eo, pat, body) }
26-
| _ -> add_promise_type ~async:true e
25+
| _ -> add_promise_type ~loc ~async:true e
2726

2827
let make_function_async ~async (e : Parsetree.expression) =
2928
if async then
3029
match e.pexp_desc with
31-
| Pexp_fun _ -> add_promise_to_result e
30+
| Pexp_fun (_, _, {ppat_loc}, _) -> add_promise_to_result ~loc:ppat_loc e
3231
| _ -> assert false
3332
else e

0 commit comments

Comments
 (0)