From 3d8ca494957b51cac5568b3cc0d6fc56053fb90a 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 | 1 + jscomp/syntax/src/res_core.ml | 1 + .../tests/parsing/grammar/expressions/coerce.res | 10 +++++++++- .../grammar/expressions/expected/coerce.res.txt | 6 +++++- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd67e60ee4..bf653d33ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - Disallow spreading anything but regular variants inside of other variants. https://github.com/rescript-lang/rescript-compiler/pull/6980 - Fix comment removed when function signature has `type` keyword. https://github.com/rescript-lang/rescript-compiler/pull/6997 - Fix parse error on doc comment before "and" in type def. https://github.com/rescript-lang/rescript-compiler/pull/7001 +- Fix tuple coercion. https://github.com/rescript-lang/rescript-compiler/pull/7024 # 11.1.3 diff --git a/jscomp/syntax/src/res_core.ml b/jscomp/syntax/src/res_core.ml index 37e01e56e3..2a0807416c 100644 --- a/jscomp/syntax/src/res_core.ml +++ b/jscomp/syntax/src/res_core.ml @@ -1865,6 +1865,7 @@ and parseConstrainedExprRegion p = | token when Grammar.isExprStart token -> ( let expr = parseExpr p in match p.Parser.token with + | ColonGreaterThan -> Some (parseCoercedExpr ~expr p) | Colon -> Parser.next p; let typ = parseTypExpr 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 fd68e3581a..f87fc15a75 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 (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)) \ No newline at end of file