Skip to content

Commit 7a90de0

Browse files
committedMay 2, 2022
Give accurate location for pipe expressions where possible.
Currently a pipe expression `a -> foo(x,y)` has the location of function `foo`. This can lead to confusing error messages where the type of `foo` is blamed when the error is actually about the whole expression. Example: ``` let z = "ac" let _ = z -> String.compare("x") ++ "" ``` The correct error should blame the entire pipe expression, not just `String.compare`. This PR does not change the location in the case of pipe with tuple, where giving accurate location is simply not possible. For example: ``` let f = (a: int, b: int => int, c: int => string): (int, int) => a->(b, c) ``` there's no way to blame the application `c(a)` separately from `b`.
1 parent cf8ff3b commit 7a90de0

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed
 

‎jscomp/frontend/ast_exp_apply.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,16 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
110110
let fn = self.expr self fn in
111111
match fn.pexp_desc with
112112
| Pexp_variant (label, None) ->
113-
{ fn with pexp_desc = Pexp_variant (label, Some new_obj_arg) }
113+
{ fn with pexp_desc = Pexp_variant (label, Some new_obj_arg); pexp_loc = e.pexp_loc }
114114
| Pexp_construct (ctor, None) ->
115-
{ fn with pexp_desc = Pexp_construct (ctor, Some new_obj_arg) }
115+
{ fn with pexp_desc = Pexp_construct (ctor, Some new_obj_arg); pexp_loc = e.pexp_loc }
116116
| Pexp_apply (fn, args) ->
117117
Bs_ast_invariant.warn_discarded_unused_attributes
118118
fn.pexp_attributes;
119119
{
120120
pexp_desc = Pexp_apply (fn, (Nolabel, new_obj_arg) :: args);
121121
pexp_attributes = [];
122-
pexp_loc = fn.pexp_loc;
122+
pexp_loc = e.pexp_loc;
123123
}
124124
| _ -> (
125125
match Ast_open_cxt.destruct fn [] with

0 commit comments

Comments
 (0)