From 8d5d89a3da208737698003dfbb6190c94ffedbb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20Tsnobiladz=C3=A9?= Date: Mon, 17 Jun 2024 11:22:59 +0200 Subject: [PATCH] fix tag function location on compiler error --- CHANGELOG.md | 1 + .../unknown_tagged_template_function.res.expected | 7 +++++++ .../fixtures/unknown_tagged_template_function.res | 1 + jscomp/syntax/src/res_core.ml | 13 ++++--------- 4 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 jscomp/build_tests/super_errors/expected/unknown_tagged_template_function.res.expected create mode 100644 jscomp/build_tests/super_errors/fixtures/unknown_tagged_template_function.res diff --git a/CHANGELOG.md b/CHANGELOG.md index 495de97b89..33651b6311 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ #### :bug: Bug Fix +- Fix tag function location on compiler error. https://github.com/rescript-lang/rescript-compiler/pull/6816 - Fix encoding inside tagged template literals. https://github.com/rescript-lang/rescript-compiler/pull/6810 - Fix unhandled cases for exotic idents (allow to use exotic PascalCased identifiers for types). https://github.com/rescript-lang/rescript-compiler/pull/6777 - PPX v4: mark props type in externals as `@live` to avoid dead code warnings for prop fields in the editor tooling. https://github.com/rescript-lang/rescript-compiler/pull/6796 diff --git a/jscomp/build_tests/super_errors/expected/unknown_tagged_template_function.res.expected b/jscomp/build_tests/super_errors/expected/unknown_tagged_template_function.res.expected new file mode 100644 index 0000000000..5b5c2f816b --- /dev/null +++ b/jscomp/build_tests/super_errors/expected/unknown_tagged_template_function.res.expected @@ -0,0 +1,7 @@ + + We've found a bug for you! + /.../fixtures/unknown_tagged_template_function.res:1:11-14 + + 1 │ let res = tagg`| 5 × 10 = ${5} |` + + The value tagg can't be found \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/fixtures/unknown_tagged_template_function.res b/jscomp/build_tests/super_errors/fixtures/unknown_tagged_template_function.res new file mode 100644 index 0000000000..40a9532ace --- /dev/null +++ b/jscomp/build_tests/super_errors/fixtures/unknown_tagged_template_function.res @@ -0,0 +1 @@ +let res = tagg`| 5 × 10 = ${5} |` \ No newline at end of file diff --git a/jscomp/syntax/src/res_core.ml b/jscomp/syntax/src/res_core.ml index 9d712b28cd..c77084669b 100644 --- a/jscomp/syntax/src/res_core.ml +++ b/jscomp/syntax/src/res_core.ml @@ -2286,7 +2286,6 @@ and parse_template_expr ?prefix p = Some prefix | _ -> Some "js" in - let start_pos = p.Parser.start_pos in let parse_parts p = let rec aux acc = @@ -2319,13 +2318,9 @@ and parse_template_expr ?prefix p = let parts = parse_parts p in let strings = List.map fst parts in let values = Ext_list.filter_map parts snd in - let end_pos = p.Parser.end_pos in - let gen_tagged_template_call lident = - let ident = - Ast_helper.Exp.ident ~attrs:[] ~loc:Location.none - (Location.mknoloc lident) - in + let gen_tagged_template_call (lident_loc : Longident.t Location.loc) = + let ident = Ast_helper.Exp.ident ~attrs:[] ~loc:lident_loc.loc lident_loc in let strings_array = Ast_helper.Exp.array ~attrs:[] ~loc:Location.none strings in @@ -2334,7 +2329,7 @@ and parse_template_expr ?prefix p = in Ast_helper.Exp.apply ~attrs:[tagged_template_literal_attr] - ~loc:(mk_loc start_pos end_pos) ident + ~loc:lident_loc.loc ident [(Nolabel, strings_array); (Nolabel, values_array)] in @@ -2374,7 +2369,7 @@ and parse_template_expr ?prefix p = match prefix with | Some {txt = Longident.Lident ("js" | "j" | "json"); _} | None -> gen_interpolated_string () - | Some {txt = lident} -> gen_tagged_template_call lident + | Some lident_loc -> gen_tagged_template_call lident_loc (* Overparse: let f = a : int => a + 1, is it (a : int) => or (a): int => * Also overparse constraints: