Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tag function location on error #6816

Merged
merged 1 commit into from
Jun 17, 2024
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let res = tagg`| 5 × 10 = ${5} |`
13 changes: 4 additions & 9 deletions jscomp/syntax/src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this didn't make any difference

let strings_array =
Ast_helper.Exp.array ~attrs:[] ~loc:Location.none strings
in
Expand All @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the real fix is here

[(Nolabel, strings_array); (Nolabel, values_array)]
in

Expand Down Expand Up @@ -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:
Expand Down