From ecbc9fb59079ab86640d07b6db561126969d19d2 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sun, 8 Sep 2024 16:09:02 +0200 Subject: [PATCH 1/8] Set version to 11.1.4 --- CHANGELOG.md | 2 ++ jscomp/common/bs_version.ml | 2 +- package-lock.json | 4 ++-- package.json | 2 +- packages/std/package.json | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b79f0e2d78..3c5e54e0ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ > - :house: [Internal] > - :nail_care: [Polish] +# 11.1.4 + # 11.1.3 #### :bug: Bug Fix diff --git a/jscomp/common/bs_version.ml b/jscomp/common/bs_version.ml index f92abfba39..b60de7a330 100644 --- a/jscomp/common/bs_version.ml +++ b/jscomp/common/bs_version.ml @@ -21,6 +21,6 @@ * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -let version = "11.1.3" +let version = "11.1.4" let header = "// Generated by ReScript, PLEASE EDIT WITH CARE" let package_name = ref "rescript" diff --git a/package-lock.json b/package-lock.json index 741b0ea639..c07933ec3b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "rescript", - "version": "11.1.3", + "version": "11.1.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "rescript", - "version": "11.1.3", + "version": "11.1.4", "hasInstallScript": true, "license": "SEE LICENSE IN LICENSE", "bin": { diff --git a/package.json b/package.json index 8a9c3c818e..91025ff35c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rescript", - "version": "11.1.3", + "version": "11.1.4", "devDependencies": { "mocha": "10.1.0", "nyc": "15.0.0", diff --git a/packages/std/package.json b/packages/std/package.json index 83a1e10ddd..8e38b1b4fe 100644 --- a/packages/std/package.json +++ b/packages/std/package.json @@ -1,6 +1,6 @@ { "name": "@rescript/std", - "version": "11.1.3", + "version": "11.1.4", "keywords": [ "rescript", "stdlib", From f3cb04b6606d6b59285eae992ed569316b688e13 Mon Sep 17 00:00:00 2001 From: Shulhi Sapli Date: Thu, 15 Aug 2024 15:25:08 +0800 Subject: [PATCH 2/8] Skip trailing comma in explicit partial application (#6949) * Check for dotdotdot in args * Check on attribute rather than label * Add tests * Fix naming convention * Update CHANGELOG --- CHANGELOG.md | 2 + jscomp/syntax/src/res_parsetree_viewer.ml | 7 +++ jscomp/syntax/src/res_parsetree_viewer.mli | 2 + jscomp/syntax/src/res_printer.ml | 26 ++++++++-- jscomp/syntax/tests/printer/expr/apply.res | 34 +++++++++++++ .../tests/printer/expr/expected/apply.res.txt | 51 +++++++++++++++++++ 6 files changed, 117 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c5e54e0ee..3d184c5399 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ # 11.1.4 +- Fix issue where long layout break added a trailing comma in partial application `...`. https://github.com/rescript-lang/rescript-compiler/pull/6949 + # 11.1.3 #### :bug: Bug Fix diff --git a/jscomp/syntax/src/res_parsetree_viewer.ml b/jscomp/syntax/src/res_parsetree_viewer.ml index a376b5b633..9d8d5948a2 100644 --- a/jscomp/syntax/src/res_parsetree_viewer.ml +++ b/jscomp/syntax/src/res_parsetree_viewer.ml @@ -72,6 +72,13 @@ let processUncurriedAppAttribute attrs = in process false [] attrs +let hasPartialAttribute attrs = + List.exists + (function + | {Location.txt = "res.partial"}, _ -> true + | _ -> false) + attrs + let processPartialAppAttribute attrs = let rec process partialApp acc attrs = match attrs with diff --git a/jscomp/syntax/src/res_parsetree_viewer.mli b/jscomp/syntax/src/res_parsetree_viewer.mli index 954638c06a..d1bb8df451 100644 --- a/jscomp/syntax/src/res_parsetree_viewer.mli +++ b/jscomp/syntax/src/res_parsetree_viewer.mli @@ -29,6 +29,8 @@ type functionAttributesInfo = { attributes: Parsetree.attributes; } +val hasPartialAttribute : Parsetree.attributes -> bool + (* determines whether a function is async and/or uncurried based on the given attributes *) val processFunctionAttributes : Parsetree.attributes -> functionAttributesInfo diff --git a/jscomp/syntax/src/res_printer.ml b/jscomp/syntax/src/res_printer.ml index c7a715f8ce..72a3f1e9fb 100644 --- a/jscomp/syntax/src/res_printer.ml +++ b/jscomp/syntax/src/res_printer.ml @@ -4120,7 +4120,13 @@ and printPexpApply ~state expr cmtTbl = let partial, attrs = ParsetreeViewer.processPartialAppAttribute attrs in let args = if partial then - let dummy = Ast_helper.Exp.constant (Ast_helper.Const.int 0) in + let loc = + {Asttypes.txt = "res.partial"; Asttypes.loc = expr.pexp_loc} + in + let attr = (loc, Parsetree.PTyp (Ast_helper.Typ.any ())) in + let dummy = + Ast_helper.Exp.constant ~attrs:[attr] (Ast_helper.Const.int 0) + in args @ [(Asttypes.Labelled "...", dummy)] else args in @@ -4700,6 +4706,18 @@ and printArguments ~state ~dotted ?(partial = false) Doc.concat [(if dotted then Doc.text "(. " else Doc.lparen); argDoc; Doc.rparen] | args -> + (* Avoid printing trailing comma when there is ... in function application *) + let hasPartialAttr, printedArgs = + List.fold_right + (fun arg (flag, acc) -> + let _, expr = arg in + let hasPartialAttr = + ParsetreeViewer.hasPartialAttribute expr.Parsetree.pexp_attributes + in + let doc = printArgument ~state arg cmtTbl in + (flag || hasPartialAttr, doc :: acc)) + args (false, []) + in Doc.group (Doc.concat [ @@ -4708,11 +4726,9 @@ and printArguments ~state ~dotted ?(partial = false) (Doc.concat [ (if dotted then Doc.line else Doc.softLine); - Doc.join - ~sep:(Doc.concat [Doc.comma; Doc.line]) - (List.map (fun arg -> printArgument ~state arg cmtTbl) args); + Doc.join ~sep:(Doc.concat [Doc.comma; Doc.line]) printedArgs; ]); - (if partial then Doc.nil else Doc.trailingComma); + (if partial || hasPartialAttr then Doc.nil else Doc.trailingComma); Doc.softLine; Doc.rparen; ]) diff --git a/jscomp/syntax/tests/printer/expr/apply.res b/jscomp/syntax/tests/printer/expr/apply.res index 9d44d720d3..3c9d1aed48 100644 --- a/jscomp/syntax/tests/printer/expr/apply.res +++ b/jscomp/syntax/tests/printer/expr/apply.res @@ -73,3 +73,37 @@ f(. { resolve(.) resolve(. ()) + +let g = f( + a => LongModuleName.functionWithAlongNameThatWrapsTheEditorToTheNextLinexxxxxxxxxxxxxxxxxxxxxx(a), + b, + c +) + +let g = f( + a => LongModuleName.functionWithAlongNameThatWrapsTheEditorToTheNextLinexxxxxxxxxxxxxxxxxxxxxx(a), + b, + c, + ... +) + +let g = f( + a => LongModuleName.functionWithAlongNameThatWrapsTheEditorToTheNextLinexxxxxxxxxxxxxxxxxxxxxx(a), + b, + c => LongModuleName.functionWithAlongNameThatWrapsTheEditorToTheNextLinexxxxxxxxxxxxxxxxxxxxxx(d, ...), + ... +) + +let g = f( + a => LongModuleName.functionWithAlongNameThatWrapsTheEditorToTheNextLinexxxxxxxxxxxxxxxxxxxxxx(a, ...), + b, + c => LongModuleName.functionWithAlongNameThatWrapsTheEditorToTheNextLinexxxxxxxxxxxxxxxxxxxxxx(d), + ... +) + + +let g = f( + a => LongModuleName.functionWithAlongNameThatWrapsTheEditorToTheNextLinexxxxxxxxxxxxxxxxxxxxxx(a), + b, + c => LongModuleName.functionWithAlongNameThatWrapsTheEditorToTheNextLinexxxxxxxxxxxxxxxxxxxxxx(d, ...) +) diff --git a/jscomp/syntax/tests/printer/expr/expected/apply.res.txt b/jscomp/syntax/tests/printer/expr/expected/apply.res.txt index 1cccb8a20b..2472c24ace 100644 --- a/jscomp/syntax/tests/printer/expr/expected/apply.res.txt +++ b/jscomp/syntax/tests/printer/expr/expected/apply.res.txt @@ -93,3 +93,54 @@ f(. { resolve(.) resolve(. ()) + +let g = f( + a => LongModuleName.functionWithAlongNameThatWrapsTheEditorToTheNextLinexxxxxxxxxxxxxxxxxxxxxx(a), + b, + c, +) + +let g = + f( + a => + LongModuleName.functionWithAlongNameThatWrapsTheEditorToTheNextLinexxxxxxxxxxxxxxxxxxxxxx(a), + b, + c, + ... + ) + +let g = + f( + a => + LongModuleName.functionWithAlongNameThatWrapsTheEditorToTheNextLinexxxxxxxxxxxxxxxxxxxxxx(a), + b, + c => + LongModuleName.functionWithAlongNameThatWrapsTheEditorToTheNextLinexxxxxxxxxxxxxxxxxxxxxx( + d, + ... + ), + ... + ) + +let g = + f( + a => + LongModuleName.functionWithAlongNameThatWrapsTheEditorToTheNextLinexxxxxxxxxxxxxxxxxxxxxx( + a, + ... + ), + b, + c => + LongModuleName.functionWithAlongNameThatWrapsTheEditorToTheNextLinexxxxxxxxxxxxxxxxxxxxxx(d), + ... + ) + +let g = f( + a => LongModuleName.functionWithAlongNameThatWrapsTheEditorToTheNextLinexxxxxxxxxxxxxxxxxxxxxx(a), + b, + c => + LongModuleName.functionWithAlongNameThatWrapsTheEditorToTheNextLinexxxxxxxxxxxxxxxxxxxxxx( + d, + ... + ), +) From b6f137f45af259c088086a61074ae9bf6c9b007e Mon Sep 17 00:00:00 2001 From: Shulhi Sapli Date: Fri, 16 Aug 2024 13:38:03 +0800 Subject: [PATCH 3/8] Fix incorrect format of function under unary operator (#6953) * Fix parens in unary operator * Fix parens in binary expr * Handle underscore sugar application * Add tests * Update CHANGELOG --- CHANGELOG.md | 1 + jscomp/syntax/src/res_parens.ml | 10 ++++++++++ .../syntax/tests/printer/expr/expected/unary.res.txt | 2 ++ jscomp/syntax/tests/printer/expr/unary.res | 2 ++ 4 files changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d184c5399..b47da10a10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ # 11.1.4 - Fix issue where long layout break added a trailing comma in partial application `...`. https://github.com/rescript-lang/rescript-compiler/pull/6949 +- Fix incorrect format of function under unary operator. https://github.com/rescript-lang/rescript-compiler/pull/6953 # 11.1.3 diff --git a/jscomp/syntax/src/res_parens.ml b/jscomp/syntax/src/res_parens.ml index 4c699c9a31..f7a7623c12 100644 --- a/jscomp/syntax/src/res_parens.ml +++ b/jscomp/syntax/src/res_parens.ml @@ -111,6 +111,11 @@ let unaryExprOperand expr = Parenthesized | _ when ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes -> Parenthesized + | {pexp_desc = Pexp_construct ({txt = Lident "Function$"}, Some expr)} + when ParsetreeViewer.isUnderscoreApplySugar expr -> + Nothing + | {pexp_desc = Pexp_construct ({txt = Lident "Function$"}, Some _)} -> + Parenthesized | _ -> Nothing) let binaryExprOperand ~isLhs expr = @@ -276,6 +281,11 @@ let fieldExpr expr = Parenthesized | _ when ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes -> Parenthesized + | {pexp_desc = Pexp_construct ({txt = Lident "Function$"}, Some expr)} + when ParsetreeViewer.isUnderscoreApplySugar expr -> + Nothing + | {pexp_desc = Pexp_construct ({txt = Lident "Function$"}, Some _)} -> + Parenthesized | _ -> Nothing) let setFieldExprRhs expr = diff --git a/jscomp/syntax/tests/printer/expr/expected/unary.res.txt b/jscomp/syntax/tests/printer/expr/expected/unary.res.txt index cfe9b42193..714deac77d 100644 --- a/jscomp/syntax/tests/printer/expr/expected/unary.res.txt +++ b/jscomp/syntax/tests/printer/expr/expected/unary.res.txt @@ -85,3 +85,5 @@ let () = { let x = (!truths)[0] (!streets)[0] = "foo-street" + +!(arg => doStuffWith(arg)) diff --git a/jscomp/syntax/tests/printer/expr/unary.res b/jscomp/syntax/tests/printer/expr/unary.res index 0aba0aea7e..684ce64916 100644 --- a/jscomp/syntax/tests/printer/expr/unary.res +++ b/jscomp/syntax/tests/printer/expr/unary.res @@ -68,3 +68,5 @@ let () = { let x = (!truths)[0] (!streets)[0] = "foo-street" + +!(arg => doStuffWith(arg)) From b0a0e1bf2e0b1216e9d39157bdde3c67077cc58a Mon Sep 17 00:00:00 2001 From: Shulhi Sapli Date: Tue, 20 Aug 2024 13:43:06 +0800 Subject: [PATCH 4/8] Fix module printing (#6963) * Handle parens when mod type is a module signature * Refactor * Update CHANGELOG * Add tests * Handle more edge cases * Add more test cases from jscomp/test/coercion_module_alias_test.res --- CHANGELOG.md | 1 + jscomp/syntax/src/res_parens.ml | 17 +++++++ jscomp/syntax/src/res_parens.mli | 2 + jscomp/syntax/src/res_printer.ml | 7 ++- .../modExpr/expected/structure.res.txt | 46 +++++++++++++++++ .../tests/printer/modExpr/structure.res | 49 ++++++++++++++++++- 6 files changed, 120 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b47da10a10..342b1d60f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - Fix issue where long layout break added a trailing comma in partial application `...`. https://github.com/rescript-lang/rescript-compiler/pull/6949 - Fix incorrect format of function under unary operator. https://github.com/rescript-lang/rescript-compiler/pull/6953 +- Fix incorrect incorrect printing of module binding with signature. https://github.com/rescript-lang/rescript-compiler/pull/6963 # 11.1.3 diff --git a/jscomp/syntax/src/res_parens.ml b/jscomp/syntax/src/res_parens.ml index f7a7623c12..83ae636bde 100644 --- a/jscomp/syntax/src/res_parens.ml +++ b/jscomp/syntax/src/res_parens.ml @@ -450,6 +450,23 @@ let includeModExpr modExpr = | Parsetree.Pmod_constraint _ -> true | _ -> false +let modExprParens modExpr = + match modExpr with + | { + Parsetree.pmod_desc = + Pmod_constraint + ( {Parsetree.pmod_desc = Pmod_structure _}, + {Parsetree.pmty_desc = Pmty_signature [{psig_desc = Psig_module _}]} ); + } -> + false + | { + Parsetree.pmod_desc = + Pmod_constraint + (_, {Parsetree.pmty_desc = Pmty_signature [{psig_desc = Psig_module _}]}); + } -> + true + | _ -> false + let arrowReturnTypExpr typExpr = match typExpr.Parsetree.ptyp_desc with | Parsetree.Ptyp_arrow _ -> true diff --git a/jscomp/syntax/src/res_parens.mli b/jscomp/syntax/src/res_parens.mli index 9b60b815f1..5d1abf9e1c 100644 --- a/jscomp/syntax/src/res_parens.mli +++ b/jscomp/syntax/src/res_parens.mli @@ -32,6 +32,8 @@ val callExpr : Parsetree.expression -> kind val includeModExpr : Parsetree.module_expr -> bool +val modExprParens : Parsetree.module_expr -> bool + val arrowReturnTypExpr : Parsetree.core_type -> bool val patternRecordRowRhs : Parsetree.pattern -> bool diff --git a/jscomp/syntax/src/res_printer.ml b/jscomp/syntax/src/res_printer.ml index 72a3f1e9fb..376e9cacf8 100644 --- a/jscomp/syntax/src/res_printer.ml +++ b/jscomp/syntax/src/res_printer.ml @@ -719,6 +719,11 @@ and printModuleBinding ~state ~isRec moduleBinding cmtTbl i = Doc.concat [Doc.text ": "; printModType ~state modType cmtTbl] ) | modExpr -> (printModExpr ~state modExpr cmtTbl, Doc.nil) in + let modExprDocParens = + if Parens.modExprParens moduleBinding.pmb_expr then + Doc.concat [Doc.lparen; modExprDoc; Doc.rparen] + else modExprDoc + in let modName = let doc = Doc.text moduleBinding.pmb_name.Location.txt in printComments doc cmtTbl moduleBinding.pmb_name.loc @@ -732,7 +737,7 @@ and printModuleBinding ~state ~isRec moduleBinding cmtTbl i = modName; modConstraintDoc; Doc.text " = "; - modExprDoc; + modExprDocParens; ] in printComments doc cmtTbl moduleBinding.pmb_loc diff --git a/jscomp/syntax/tests/printer/modExpr/expected/structure.res.txt b/jscomp/syntax/tests/printer/modExpr/expected/structure.res.txt index b5016cf426..a958790e76 100644 --- a/jscomp/syntax/tests/printer/modExpr/expected/structure.res.txt +++ b/jscomp/syntax/tests/printer/modExpr/expected/structure.res.txt @@ -22,3 +22,49 @@ let g = { module M: T = {} 0 } + +module M7: { + module N': { + let x: int + } +} = (M6: { + module N: { + let x: int + } + module N' = N +}) + +module M8 = M7 + +module M5 = G0() + +module M7: { + let x: int +} = { + let x = 8 +} + +module M3: { + module N': { + let x: int + } +} = { + include M' +} + +module G0: (X: {}) => +{ + module N': { + let x: int + } +} = F0 + +module M6 = { + module D = { + let y = 3 + } + module N = { + let x = 1 + } + module N' = N +} diff --git a/jscomp/syntax/tests/printer/modExpr/structure.res b/jscomp/syntax/tests/printer/modExpr/structure.res index a0bd2ff7c4..86a882d62d 100644 --- a/jscomp/syntax/tests/printer/modExpr/structure.res +++ b/jscomp/syntax/tests/printer/modExpr/structure.res @@ -21,4 +21,51 @@ module type T = {} let g = { module M: T = {} 0 -} \ No newline at end of file +} + +module M7: { + module N': { + let x: int + } +} = (M6: { + module N: { + let x: int + } + module N' = N +}) + + +module M8 = M7 + +module M5 = G0() + +module M7: { + let x: int +} = { + let x = 8 +} + +module M3: { + module N': { + let x: int + } +} = { + include M' +} + +module G0: (X: {}) => +{ + module N': { + let x: int + } +} = F0 + +module M6 = { + module D = { + let y = 3 + } + module N = { + let x = 1 + } + module N' = N +} From 401de693317f05f41a77e9cd91c6715882a5ae99 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Tue, 27 Aug 2024 10:26:37 +0200 Subject: [PATCH 5/8] Disallow non-variant spreads in variants (#6980) * disallow non-variant spreads in variants * changelog * undo formatting in changelog * run make lib * changelog * fix * changelog # Conflicts: # CHANGELOG.md --- CHANGELOG.md | 3 ++- .../expected/variant_spread_abstract_type.res.expected | 9 +++++++++ .../variant_spread_extensible_variant.res.expected | 9 +++++++++ .../fixtures/variant_spread_abstract_type.res | 2 ++ .../fixtures/variant_spread_extensible_variant.res | 2 ++ jscomp/ml/typedecl.ml | 2 ++ jscomp/ml/variant_type_spread.ml | 4 +++- 7 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 jscomp/build_tests/super_errors/expected/variant_spread_abstract_type.res.expected create mode 100644 jscomp/build_tests/super_errors/expected/variant_spread_extensible_variant.res.expected create mode 100644 jscomp/build_tests/super_errors/fixtures/variant_spread_abstract_type.res create mode 100644 jscomp/build_tests/super_errors/fixtures/variant_spread_extensible_variant.res diff --git a/CHANGELOG.md b/CHANGELOG.md index 342b1d60f5..871c9232d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - Fix issue where long layout break added a trailing comma in partial application `...`. https://github.com/rescript-lang/rescript-compiler/pull/6949 - Fix incorrect format of function under unary operator. https://github.com/rescript-lang/rescript-compiler/pull/6953 - Fix incorrect incorrect printing of module binding with signature. https://github.com/rescript-lang/rescript-compiler/pull/6963 +- Disallow spreading anything but regular variants inside of other variants. https://github.com/rescript-lang/rescript-compiler/pull/6980 # 11.1.3 @@ -2507,4 +2508,4 @@ Features: # 1.0.0 -Initial release +Initial release \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/expected/variant_spread_abstract_type.res.expected b/jscomp/build_tests/super_errors/expected/variant_spread_abstract_type.res.expected new file mode 100644 index 0000000000..016fd1e23c --- /dev/null +++ b/jscomp/build_tests/super_errors/expected/variant_spread_abstract_type.res.expected @@ -0,0 +1,9 @@ + + We've found a bug for you! + /.../fixtures/variant_spread_abstract_type.res:2:15 + + 1 │ type a + 2 │ type b = | ...a | Other + 3 │ + + This type is not a valid type to spread. It's only possible to spread other variants. \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/expected/variant_spread_extensible_variant.res.expected b/jscomp/build_tests/super_errors/expected/variant_spread_extensible_variant.res.expected new file mode 100644 index 0000000000..100f881686 --- /dev/null +++ b/jscomp/build_tests/super_errors/expected/variant_spread_extensible_variant.res.expected @@ -0,0 +1,9 @@ + + We've found a bug for you! + /.../fixtures/variant_spread_extensible_variant.res:2:15 + + 1 │ type a = .. + 2 │ type b = | ...a | Other + 3 │ + + This type is not a valid type to spread. It's only possible to spread other variants. \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/fixtures/variant_spread_abstract_type.res b/jscomp/build_tests/super_errors/fixtures/variant_spread_abstract_type.res new file mode 100644 index 0000000000..ae52ca53af --- /dev/null +++ b/jscomp/build_tests/super_errors/fixtures/variant_spread_abstract_type.res @@ -0,0 +1,2 @@ +type a +type b = | ...a | Other diff --git a/jscomp/build_tests/super_errors/fixtures/variant_spread_extensible_variant.res b/jscomp/build_tests/super_errors/fixtures/variant_spread_extensible_variant.res new file mode 100644 index 0000000000..344b0f66d5 --- /dev/null +++ b/jscomp/build_tests/super_errors/fixtures/variant_spread_extensible_variant.res @@ -0,0 +1,2 @@ +type a = .. +type b = | ...a | Other diff --git a/jscomp/ml/typedecl.ml b/jscomp/ml/typedecl.ml index 43a8b3f05f..532c093b87 100644 --- a/jscomp/ml/typedecl.ml +++ b/jscomp/ml/typedecl.ml @@ -2184,6 +2184,8 @@ let report_error ppf = function ^ other_variant_text ^ ". Both variants must have the same @tag attribute configuration, or no \ @tag attribute at all") + | Variant_spread_fail Variant_type_spread.InvalidType -> + fprintf ppf "@[This type is not a valid type to spread. It's only possible to spread other variants.@]" | Variant_spread_fail Variant_type_spread.CouldNotFindType -> fprintf ppf "@[This type could not be found. It's only possible to spread variants that are known as the spread happens. This means for example that you can't spread variants in recursive definitions.@]" | Variant_spread_fail Variant_type_spread.HasTypeParams -> diff --git a/jscomp/ml/variant_type_spread.ml b/jscomp/ml/variant_type_spread.ml index 94caebe581..bb1c380906 100644 --- a/jscomp/ml/variant_type_spread.ml +++ b/jscomp/ml/variant_type_spread.ml @@ -4,6 +4,7 @@ let mk_constructor_comes_from_spread_attr () : Parsetree.attribute = type variant_type_spread_error = | CouldNotFindType | HasTypeParams + | InvalidType | DuplicateConstructor of { variant_with_overlapping_constructor: string; overlapping_constructor_name: string; @@ -31,6 +32,7 @@ let map_constructors ~(sdecl : Parsetree.type_declaration) ~all_constructors env in match type_decl with + | {type_kind = Type_variant [] } -> raise (VariantTypeSpreadError (loc.loc, InvalidType)) | {type_kind = Type_variant cstrs; type_attributes; type_params} -> if List.length type_params > 0 then raise (VariantTypeSpreadError (loc.loc, HasTypeParams)); @@ -83,7 +85,7 @@ let map_constructors ~(sdecl : Parsetree.type_declaration) ~all_constructors env pcd_args = Pcstr_tuple []; pcd_name = Location.mkloc cstr.cd_id.name cstr.cd_loc; })) - | _ -> [c]) + | _ -> raise (VariantTypeSpreadError (loc.loc, InvalidType))) | _ -> Hashtbl.add all_constructors c.pcd_name.txt (); [c] From 09dfbc775b63e75db4e7bcb56390ffc9bfe95654 Mon Sep 17 00:00:00 2001 From: Shulhi Sapli Date: Sun, 1 Sep 2024 14:40:17 +0800 Subject: [PATCH 6/8] Fix comment removed when function signature has type keyword (#6997) * Fix comment removed when function signature has type keyword * Update CHANGELOG --- CHANGELOG.md | 3 ++- jscomp/syntax/src/res_comments_table.ml | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 871c9232d1..57ab7022c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - Fix incorrect format of function under unary operator. https://github.com/rescript-lang/rescript-compiler/pull/6953 - Fix incorrect incorrect printing of module binding with signature. https://github.com/rescript-lang/rescript-compiler/pull/6963 - 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 # 11.1.3 @@ -2508,4 +2509,4 @@ Features: # 1.0.0 -Initial release \ No newline at end of file +Initial release diff --git a/jscomp/syntax/src/res_comments_table.ml b/jscomp/syntax/src/res_comments_table.ml index 3fd0d5e989..b23e65c5f7 100644 --- a/jscomp/syntax/src/res_comments_table.ml +++ b/jscomp/syntax/src/res_comments_table.ml @@ -1404,6 +1404,8 @@ and walkExpression expr t comments = attach t.leading expr.pexp_loc leading; walkExpression expr t inside; attach t.trailing expr.pexp_loc trailing + | Pexp_construct ({txt = Longident.Lident "Function$"}, Some returnExpr) -> + walkExpression returnExpr t comments | _ -> if isBlockExpr returnExpr then walkExpression returnExpr t comments else From 4ca3bd8bacb0ae6a74d38f514b675c5f4a8a0ecb Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Mon, 2 Sep 2024 10:51:50 +0200 Subject: [PATCH 7/8] Fix parse error on doc comment before "and" in type def (#7001) * Fix parse error on doc comment before "and" in type def * CHANGELOG # Conflicts: # jscomp/syntax/src/res_core.ml --- CHANGELOG.md | 1 + jscomp/syntax/src/res_core.ml | 2 +- jscomp/syntax/tests/parsing/other/docComments.res | 6 +++++- .../syntax/tests/parsing/other/expected/docComments.res.txt | 6 +++++- jscomp/syntax/tests/printer/comments/docComments.res | 6 +++++- .../tests/printer/comments/expected/docComments.res.txt | 3 +++ 6 files changed, 20 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57ab7022c0..fd67e60ee4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - Fix incorrect incorrect printing of module binding with signature. https://github.com/rescript-lang/rescript-compiler/pull/6963 - 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 # 11.1.3 diff --git a/jscomp/syntax/src/res_core.ml b/jscomp/syntax/src/res_core.ml index cd1d576267..37e01e56e3 100644 --- a/jscomp/syntax/src/res_core.ml +++ b/jscomp/syntax/src/res_core.ml @@ -2525,7 +2525,7 @@ and parseAttributesAndBinding (p : Parser.t) = let comments = p.comments in match p.Parser.token with - | At -> ( + | At | DocComment (_, _) -> ( let attrs = parseAttributes p in match p.Parser.token with | And -> attrs diff --git a/jscomp/syntax/tests/parsing/other/docComments.res b/jscomp/syntax/tests/parsing/other/docComments.res index 2aec79b66c..793f5980d8 100644 --- a/jscomp/syntax/tests/parsing/other/docComments.res +++ b/jscomp/syntax/tests/parsing/other/docComments.res @@ -14,4 +14,8 @@ let q = 11 * is a multi-line multiline doc comment */ -type h = int \ No newline at end of file +type h = int + +type pathItem = {} +/** Issue 6844: doc comment before "and" */ +and operation = {} diff --git a/jscomp/syntax/tests/parsing/other/expected/docComments.res.txt b/jscomp/syntax/tests/parsing/other/expected/docComments.res.txt index f8427fb3ff..004126c18d 100644 --- a/jscomp/syntax/tests/parsing/other/expected/docComments.res.txt +++ b/jscomp/syntax/tests/parsing/other/expected/docComments.res.txt @@ -4,4 +4,8 @@ let z = 34[@@res.doc " This is a doc \226\156\133 comment "] [@@@res.doc {js|And this is a res.doc module annotation|js}] let q = 11[@@res.doc {js|And this is a res.doc ✅ annotation|js}] type nonrec h = int[@@res.doc - " This\n * is a multi-line\n multiline doc comment\n "] \ No newline at end of file + " This\n * is a multi-line\n multiline doc comment\n "] +type nonrec pathItem = { + } +and operation = { + }[@@res.doc " Issue 6844: doc comment before \"and\" "] \ No newline at end of file diff --git a/jscomp/syntax/tests/printer/comments/docComments.res b/jscomp/syntax/tests/printer/comments/docComments.res index e3e667adb3..731ca5d5cd 100644 --- a/jscomp/syntax/tests/printer/comments/docComments.res +++ b/jscomp/syntax/tests/printer/comments/docComments.res @@ -26,4 +26,8 @@ type h = int @foo @bar @baz let x = 10 /** doc comment and 0 attributes */ -let x = 10 \ No newline at end of file +let x = 10 + +type pathItem = {} +/** Issue 6844: doc comment before "and" */ +and operation = {} diff --git a/jscomp/syntax/tests/printer/comments/expected/docComments.res.txt b/jscomp/syntax/tests/printer/comments/expected/docComments.res.txt index 6a6a951e97..bae9ae907e 100644 --- a/jscomp/syntax/tests/printer/comments/expected/docComments.res.txt +++ b/jscomp/syntax/tests/printer/comments/expected/docComments.res.txt @@ -31,3 +31,6 @@ let x = 10 /** doc comment and 0 attributes */ let x = 10 + +type pathItem = {} +/** Issue 6844: doc comment before "and" */ and operation = {} From b1801436043e2a49ba8aa3bad643da6d78d9b923 Mon Sep 17 00:00:00 2001 From: Shulhi Sapli Date: Sun, 8 Sep 2024 15:18:54 +0800 Subject: [PATCH 8/8] 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