From ded2d065609e4c35d33ef05dd8885c40294d3158 Mon Sep 17 00:00:00 2001 From: Shulhi Sapli Date: Sun, 8 Sep 2024 15:18:54 +0800 Subject: [PATCH] Fix tuple coercion (#7024) * Fix tuple coercion It was only handled for the first arg in the tuple * Update CHANGELOG --- CHANGELOG.md | 3 +++ jscomp/syntax/src/res_core.ml | 1 + .../tests/parsing/grammar/expressions/coerce.res | 10 +++++++++- .../grammar/expressions/expected/coerce.res.txt | 6 +++++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 415ff1ad5b..f03c0cdc93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ # 12.0.0-alpha.4 (Unreleased) +#### :bug: Bug fix +- Fix tuple coercion. https://github.com/rescript-lang/rescript-compiler/pull/7024 + # 12.0.0-alpha.3 #### :bug: Bug fix diff --git a/jscomp/syntax/src/res_core.ml b/jscomp/syntax/src/res_core.ml index ba182675f7..2e0ee3e902 100644 --- a/jscomp/syntax/src/res_core.ml +++ b/jscomp/syntax/src/res_core.ml @@ -1823,6 +1823,7 @@ and parse_constrained_expr_region p = | token when Grammar.is_expr_start token -> ( let expr = parse_expr p in match p.Parser.token with + | ColonGreaterThan -> Some (parse_coerced_expr ~expr p) | Colon -> Parser.next p; let typ = parse_typ_expr p in diff --git a/jscomp/syntax/tests/parsing/grammar/expressions/coerce.res b/jscomp/syntax/tests/parsing/grammar/expressions/coerce.res index e9f73bbf27..f2bd210eff 100644 --- a/jscomp/syntax/tests/parsing/grammar/expressions/coerce.res +++ b/jscomp/syntax/tests/parsing/grammar/expressions/coerce.res @@ -1,3 +1,11 @@ let foo = (x:int) => (x :> int) -let foo = x => (x : t :> int) \ No newline at end of file +let foo = x => (x : t :> int) + +let _ = (x : int) + +let foo = (x : int, y :> float) + +let foo = (x : int, y :> float, z :> int) + +let foo = (x : int, y, z :> int) diff --git a/jscomp/syntax/tests/parsing/grammar/expressions/expected/coerce.res.txt b/jscomp/syntax/tests/parsing/grammar/expressions/expected/coerce.res.txt index 8ad27dde31..1fdea49ce8 100644 --- a/jscomp/syntax/tests/parsing/grammar/expressions/expected/coerce.res.txt +++ b/jscomp/syntax/tests/parsing/grammar/expressions/expected/coerce.res.txt @@ -1,2 +1,6 @@ let foo = ((Function$ (fun (x : int) -> (x :> int)))[@res.arity 1]) -let foo = ((Function$ (fun x -> ((x : t) :> int)))[@res.arity 1]) \ No newline at end of file +let foo = ((Function$ (fun x -> ((x : t) :> int)))[@res.arity 1]) +let _ = (x : int) +let foo = ((x : int), (y :> float)) +let foo = ((x : int), (y :> float), (z :> int)) +let foo = ((x : int), y, (z :> int))