From 4ba08b0266f2721a0c43e46d2170170ecd0bbf5b Mon Sep 17 00:00:00 2001 From: Shulhi Sapli Date: Thu, 2 Jan 2025 19:45:24 +0800 Subject: [PATCH 1/2] Fix formatter handling of wildcard pattern matching in record with no fields specified --- compiler/syntax/src/res_printer.ml | 2 ++ .../data/printer/pattern/expected/record.res.txt | 11 +++++++++++ tests/syntax_tests/data/printer/pattern/record.res | 11 +++++++++++ 3 files changed, 24 insertions(+) diff --git a/compiler/syntax/src/res_printer.ml b/compiler/syntax/src/res_printer.ml index 3897ff4a21..1144c178ba 100644 --- a/compiler/syntax/src/res_printer.ml +++ b/compiler/syntax/src/res_printer.ml @@ -2420,6 +2420,8 @@ and print_pattern ~state (p : Parsetree.pattern) cmt_tbl = Doc.soft_line; Doc.rbrace; ] + | Ppat_record ([], Open) -> + Doc.concat [Doc.lbrace; Doc.text "_"; Doc.rbrace] | Ppat_record (rows, open_flag) -> Doc.group (Doc.concat diff --git a/tests/syntax_tests/data/printer/pattern/expected/record.res.txt b/tests/syntax_tests/data/printer/pattern/expected/record.res.txt index a2c73f23d6..f2c669ccf1 100644 --- a/tests/syntax_tests/data/printer/pattern/expected/record.res.txt +++ b/tests/syntax_tests/data/printer/pattern/expected/record.res.txt @@ -114,3 +114,14 @@ let get_age3 = ({age: module(P: S), name: _}) => age2 let get_age3 = ({age: exception Exit, name: _}) => age2 let get_age3 = ({age: %raw("__GC"), name: _}) => age2 + +let get_age3 = ({age, _}) => age +let get_age3 = ({_}) => "" +let get_age3 = () => + switch x { + | {age, _} => age + } +let get_age3 = () => + switch x { + | {_} => "" + } diff --git a/tests/syntax_tests/data/printer/pattern/record.res b/tests/syntax_tests/data/printer/pattern/record.res index e880cb0182..b9021af252 100644 --- a/tests/syntax_tests/data/printer/pattern/record.res +++ b/tests/syntax_tests/data/printer/pattern/record.res @@ -58,3 +58,14 @@ let get_age3 = ({age: module(P: S), name: _}) => age2 let get_age3 = ({age: exception Exit, name: _}) => age2 let get_age3 = ({age: %raw("__GC"), name: _}) => age2 + +let get_age3 = ({age, _}) => age +let get_age3 = ({_}) => "" +let get_age3 = () => + switch x { + | {age, _} => age + } +let get_age3 = () => + switch x { + | {_} => "" + } From c77056a24a3384ed233953cf7fab1265e510b810 Mon Sep 17 00:00:00 2001 From: Shulhi Sapli Date: Thu, 2 Jan 2025 19:49:04 +0800 Subject: [PATCH 2/2] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7df6fae7f..5fc3916bcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ - Fix bug where a ref assignment is moved ouside a conditional. https://github.com/rescript-lang/rescript/pull/7176 - Fix nullable to opt conversion. https://github.com/rescript-lang/rescript/pull/7193 - Raise error when defining external React components with `@react.componentWithProps`. https://github.com/rescript-lang/rescript/pull/7217 +- Fix formatter handling of wildcard in pattern matching records with no fields specified. https://github.com/rescript-lang/rescript/pull/7224 #### :house: Internal