From 3286c4d866f5ddc201172ac78770ee1aa522b402 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Tue, 14 Jan 2025 13:36:43 +0100 Subject: [PATCH 1/6] AST: represent concatenation internally as "++" instead of "^". --- compiler/ml/ast_mapper_from0.ml | 3 + compiler/ml/ast_mapper_to0.ml | 3 + compiler/syntax/src/res_core.ml | 5 +- compiler/syntax/src/res_parens.ml | 4 +- compiler/syntax/src/res_parsetree_viewer.ml | 10 +-- compiler/syntax/src/res_printer.ml | 5 +- runtime/Pervasives.res | 2 +- runtime/Pervasives_mini.res | 2 +- .../expected/primitives2.res.expected | 2 +- .../expected/unicode_location.res.expected | 2 +- .../errors/structure/expected/gh16B.res.txt | 14 ++-- .../expressions/expected/async.res.txt | 2 +- .../expressions/expected/es6template.res.txt | 80 +++++++++---------- .../expressions/expected/infix.res.txt | 2 +- .../grammar/expressions/expected/jsx.res.txt | 5 +- .../expected/parenthesized.res.txt | 2 +- .../other/expected/stringLiterals.res.txt | 6 +- .../string/expected/es6template.res.txt | 2 +- tests/tests/src/bs_mutable_set_test.res | 8 +- tests/tests/src/bs_poly_mutable_set_test.res | 2 +- tests/tests/src/bs_queue_test.res | 18 ++--- tests/tools_tests/ppx/TestPpx.res | 2 + .../src/expected/TestPpx.res.jsout | 3 + 23 files changed, 97 insertions(+), 87 deletions(-) diff --git a/compiler/ml/ast_mapper_from0.ml b/compiler/ml/ast_mapper_from0.ml index 0a655877ff..d968606dc7 100644 --- a/compiler/ml/ast_mapper_from0.ml +++ b/compiler/ml/ast_mapper_from0.ml @@ -316,6 +316,9 @@ module E = struct | ( Pexp_ident ({txt = Longident.Lident "|."} as lid), [(Nolabel, _); (Nolabel, _)] ) -> {e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "->"}} + | ( Pexp_ident ({txt = Longident.Lident "^"} as lid), + [(Nolabel, _); (Nolabel, _)] ) -> + {e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "++"}} | _ -> e in let process_partial_app_attribute attrs = diff --git a/compiler/ml/ast_mapper_to0.ml b/compiler/ml/ast_mapper_to0.ml index 1345a40fa9..3ff711407c 100644 --- a/compiler/ml/ast_mapper_to0.ml +++ b/compiler/ml/ast_mapper_to0.ml @@ -327,6 +327,9 @@ module E = struct | ( Pexp_ident ({txt = Longident.Lident "->"} as lid), [(Nolabel, _); (Nolabel, _)] ) -> {e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "|."}} + | ( Pexp_ident ({txt = Longident.Lident "++"} as lid), + [(Nolabel, _); (Nolabel, _)] ) -> + {e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "^"}} | _ -> e in let attrs = diff --git a/compiler/syntax/src/res_core.ml b/compiler/syntax/src/res_core.ml index fd3f928138..e937d532fb 100644 --- a/compiler/syntax/src/res_core.ml +++ b/compiler/syntax/src/res_core.ml @@ -391,8 +391,7 @@ let build_longident words = let make_infix_operator (p : Parser.t) token start_pos end_pos = let stringified_token = - if token = Token.PlusPlus then "^" - else if token = Token.BangEqual then "<>" + if token = Token.BangEqual then "<>" else if token = Token.BangEqualEqual then "!=" else if token = Token.Equal then ( (* TODO: could have a totally different meaning like x->fooSet(y)*) @@ -2327,7 +2326,7 @@ and parse_template_expr ?prefix p = in let hidden_operator = - let op = Location.mknoloc (Longident.Lident "^") in + let op = Location.mknoloc (Longident.Lident "++") in Ast_helper.Exp.ident op in let concat (e1 : Parsetree.expression) (e2 : Parsetree.expression) = diff --git a/compiler/syntax/src/res_parens.ml b/compiler/syntax/src/res_parens.ml index 6b59c67c25..d9f76fca29 100644 --- a/compiler/syntax/src/res_parens.ml +++ b/compiler/syntax/src/res_parens.ml @@ -162,7 +162,7 @@ let rhs_binary_expr_operand parent_operator rhs = args = [(_, _left); (_, _right)]; } when ParsetreeViewer.is_binary_operator operator - && not (operator_loc.loc_ghost && operator = "^") -> + && not (operator_loc.loc_ghost && operator = "++") -> let prec_parent = ParsetreeViewer.operator_precedence parent_operator in let prec_child = ParsetreeViewer.operator_precedence operator in prec_parent == prec_child @@ -180,7 +180,7 @@ let flatten_operand_rhs parent_operator rhs = args = [(_, _left); (_, _right)]; } when ParsetreeViewer.is_binary_operator operator - && not (operator_loc.loc_ghost && operator = "^") -> + && not (operator_loc.loc_ghost && operator = "++") -> let prec_parent = ParsetreeViewer.operator_precedence parent_operator in let prec_child = ParsetreeViewer.operator_precedence operator in prec_parent >= prec_child || rhs.pexp_attributes <> [] diff --git a/compiler/syntax/src/res_parsetree_viewer.ml b/compiler/syntax/src/res_parsetree_viewer.ml index b030426e55..bb49c34f76 100644 --- a/compiler/syntax/src/res_parsetree_viewer.ml +++ b/compiler/syntax/src/res_parsetree_viewer.ml @@ -271,7 +271,7 @@ let operator_precedence operator = | "||" -> 2 | "&&" -> 3 | "=" | "==" | "<" | ">" | "!=" | "<>" | "!==" | "<=" | ">=" | "|>" -> 4 - | "+" | "+." | "-" | "-." | "^" -> 5 + | "+" | "+." | "-" | "-." | "++" -> 5 | "*" | "*." | "/" | "/." | "%" -> 6 | "**" -> 7 | "#" | "##" | "->" -> 8 @@ -297,8 +297,8 @@ let is_unary_expression expr = let is_binary_operator operator = match operator with | ":=" | "||" | "&&" | "=" | "==" | "<" | ">" | "!=" | "!==" | "<=" | ">=" - | "|>" | "+" | "+." | "-" | "-." | "^" | "*" | "*." | "/" | "/." | "**" | "->" - | "<>" | "%" -> + | "|>" | "+" | "+." | "-" | "-." | "++" | "*" | "*." | "/" | "/." | "**" + | "->" | "<>" | "%" -> true | _ -> false @@ -314,7 +314,7 @@ let is_binary_expression expr = args = [(Nolabel, _operand1); (Nolabel, _operand2)]; } when is_binary_operator operator - && not (operator_loc.loc_ghost && operator = "^") + && not (operator_loc.loc_ghost && operator = "++") (* template literal *) -> true | _ -> false @@ -643,7 +643,7 @@ let is_template_literal expr = match expr.pexp_desc with | Pexp_apply { - funct = {pexp_desc = Pexp_ident {txt = Longident.Lident "^"}}; + funct = {pexp_desc = Pexp_ident {txt = Longident.Lident "++"}}; args = [(Nolabel, _); (Nolabel, _)]; } when has_template_literal_attr expr.pexp_attributes -> diff --git a/compiler/syntax/src/res_printer.ml b/compiler/syntax/src/res_printer.ml index 3fae201ba1..6bdfa377ce 100644 --- a/compiler/syntax/src/res_printer.ml +++ b/compiler/syntax/src/res_printer.ml @@ -3557,7 +3557,7 @@ and print_template_literal ~state expr cmt_tbl = match expr.pexp_desc with | Pexp_apply { - funct = {pexp_desc = Pexp_ident {txt = Longident.Lident "^"}}; + funct = {pexp_desc = Pexp_ident {txt = Longident.Lident "++"}}; args = [(Nolabel, arg1); (Nolabel, arg2)]; } -> let lhs = walk_expr arg1 in @@ -3664,7 +3664,6 @@ and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl = let print_binary_operator ~inline_rhs operator = let operator_txt = match operator with - | "^" -> "++" | "=" -> "==" | "==" -> "===" | "<>" -> "!=" @@ -3800,7 +3799,7 @@ and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl = match expr.pexp_desc with | Pexp_apply { - funct = {pexp_desc = Pexp_ident {txt = Longident.Lident "^"; loc}}; + funct = {pexp_desc = Pexp_ident {txt = Longident.Lident "++"; loc}}; args = [(Nolabel, _); (Nolabel, _)]; } when loc.loc_ghost -> diff --git a/runtime/Pervasives.res b/runtime/Pervasives.res index f30c2bdfc8..95c2c7a6bb 100644 --- a/runtime/Pervasives.res +++ b/runtime/Pervasives.res @@ -230,7 +230,7 @@ let classify_float = (x: float): fpclass => /* String and byte sequence operations -- more in modules String and Bytes */ -external \"^": (string, string) => string = "%string_concat" +external \"++": (string, string) => string = "%string_concat" /* Character operations -- more in module Char */ diff --git a/runtime/Pervasives_mini.res b/runtime/Pervasives_mini.res index 9cf3cd90e4..b0c9380c29 100644 --- a/runtime/Pervasives_mini.res +++ b/runtime/Pervasives_mini.res @@ -78,7 +78,7 @@ external \"/.": (float, float) => float = "%divfloat" /* String operations */ -external \"^": (string, string) => string = "%string_concat" +external \"++": (string, string) => string = "%string_concat" /* Unit operations */ diff --git a/tests/build_tests/super_errors/expected/primitives2.res.expected b/tests/build_tests/super_errors/expected/primitives2.res.expected index 8677b188ff..d2f30716a2 100644 --- a/tests/build_tests/super_errors/expected/primitives2.res.expected +++ b/tests/build_tests/super_errors/expected/primitives2.res.expected @@ -7,6 +7,6 @@ 3 │ This has type: int - But this function argument is expecting: string + But it's expected to have type: string You can convert int to string with Belt.Int.toString. \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/unicode_location.res.expected b/tests/build_tests/super_errors/expected/unicode_location.res.expected index b228a653ed..55655bd54a 100644 --- a/tests/build_tests/super_errors/expected/unicode_location.res.expected +++ b/tests/build_tests/super_errors/expected/unicode_location.res.expected @@ -8,6 +8,6 @@ 3 │ This has type: int - But this function argument is expecting: string + But it's expected to have type: string You can convert int to string with Belt.Int.toString. \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/errors/structure/expected/gh16B.res.txt b/tests/syntax_tests/data/parsing/errors/structure/expected/gh16B.res.txt index 8f805a3c59..bd44146f4f 100644 --- a/tests/syntax_tests/data/parsing/errors/structure/expected/gh16B.res.txt +++ b/tests/syntax_tests/data/parsing/errors/structure/expected/gh16B.res.txt @@ -16,15 +16,15 @@ let wss = Server.make { port = 82 } let address = wss -> Server.address let log [arity:1]msg = Js.log - (((((({js|> Server: |js})[@res.template ]) ^ msg)[@res.template ]) ^ + (((((({js|> Server: |js})[@res.template ]) ++ msg)[@res.template ]) ++ (({js||js})[@res.template ]))[@res.template ]) ;;log - (((((((((((((({js|Running on: |js})[@res.template ]) ^ address.address) - [@res.template ]) ^ (({js|:|js})[@res.template ])) - [@res.template ]) ^ (address.port -> string_of_int)) - [@res.template ]) ^ (({js| (|js})[@res.template ])) - [@res.template ]) ^ address.family) - [@res.template ]) ^ (({js|)|js})[@res.template ]))[@res.template ]) + (((((((((((((({js|Running on: |js})[@res.template ]) ++ address.address) + [@res.template ]) ++ (({js|:|js})[@res.template ])) + [@res.template ]) ++ (address.port -> string_of_int)) + [@res.template ]) ++ (({js| (|js})[@res.template ])) + [@res.template ]) ++ address.family) + [@res.template ]) ++ (({js|)|js})[@res.template ]))[@res.template ]) module ClientSet = struct module T = diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/async.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/async.res.txt index 0c811af33f..cdffed3d8f 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/async.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/async.res.txt @@ -1,6 +1,6 @@ let greetUser async [arity:1]userId = ((let name = ((getUserName userId)[@res.await ]) in - ({js|Hello |js} ^ name) ^ {js|!|js}) + ({js|Hello |js} ++ name) ++ {js|!|js}) [@res.braces ]) ;;async fun [arity:1]() -> 123 let fetch = ((async fun [arity:1]url -> browserFetch url)[@res.braces ]) diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/es6template.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/es6template.res.txt index b84d1fc751..f88334a2e2 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/es6template.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/es6template.res.txt @@ -5,74 +5,74 @@ let s = (({js|multi string |js})[@res.template ]) let s = - (((((({js||js})[@res.template ]) ^ foo)[@res.template ]) ^ (({js||js}) + (((((({js||js})[@res.template ]) ++ foo)[@res.template ]) ++ (({js||js}) [@res.template ])) [@res.template ]) let s = - (((((({js|before|js})[@res.template ]) ^ foo)[@res.template ]) ^ + (((((({js|before|js})[@res.template ]) ++ foo)[@res.template ]) ++ (({js||js})[@res.template ])) [@res.template ]) let s = - (((((({js|before |js})[@res.template ]) ^ foo)[@res.template ]) ^ + (((((({js|before |js})[@res.template ]) ++ foo)[@res.template ]) ++ (({js||js})[@res.template ])) [@res.template ]) let s = - (((((({js|before |js})[@res.template ]) ^ foo)[@res.template ]) ^ + (((((({js|before |js})[@res.template ]) ++ foo)[@res.template ]) ++ (({js||js})[@res.template ])) [@res.template ]) let s = - (((((({js||js})[@res.template ]) ^ foo)[@res.template ]) ^ (({js|after|js}) - [@res.template ])) + (((((({js||js})[@res.template ]) ++ foo)[@res.template ]) ++ + (({js|after|js})[@res.template ])) [@res.template ]) let s = - (((((({js||js})[@res.template ]) ^ foo)[@res.template ]) ^ + (((((({js||js})[@res.template ]) ++ foo)[@res.template ]) ++ (({js| after|js})[@res.template ])) [@res.template ]) let s = - (((((({js||js})[@res.template ]) ^ foo)[@res.template ]) ^ + (((((({js||js})[@res.template ]) ++ foo)[@res.template ]) ++ (({js| after|js})[@res.template ])) [@res.template ]) let s = - (((((((((({js||js})[@res.template ]) ^ foo)[@res.template ]) ^ (({js||js}) - [@res.template ])) - [@res.template ]) ^ bar) - [@res.template ]) ^ (({js||js})[@res.template ])) + (((((((((({js||js})[@res.template ]) ++ foo)[@res.template ]) ++ + (({js||js})[@res.template ])) + [@res.template ]) ++ bar) + [@res.template ]) ++ (({js||js})[@res.template ])) [@res.template ]) let s = - (((((((((((((({js||js})[@res.template ]) ^ foo)[@res.template ]) ^ + (((((((((((((({js||js})[@res.template ]) ++ foo)[@res.template ]) ++ (({js||js})[@res.template ])) - [@res.template ]) ^ bar) - [@res.template ]) ^ (({js||js})[@res.template ])) - [@res.template ]) ^ baz) - [@res.template ]) ^ (({js||js})[@res.template ])) + [@res.template ]) ++ bar) + [@res.template ]) ++ (({js||js})[@res.template ])) + [@res.template ]) ++ baz) + [@res.template ]) ++ (({js||js})[@res.template ])) [@res.template ]) let s = - (((((((((({js||js})[@res.template ]) ^ foo)[@res.template ]) ^ (({js| |js}) - [@res.template ])) - [@res.template ]) ^ bar) - [@res.template ]) ^ (({js||js})[@res.template ])) + (((((((((({js||js})[@res.template ]) ++ foo)[@res.template ]) ++ + (({js| |js})[@res.template ])) + [@res.template ]) ++ bar) + [@res.template ]) ++ (({js||js})[@res.template ])) [@res.template ]) let s = - (((((((((((((({js||js})[@res.template ]) ^ foo)[@res.template ]) ^ + (((((((((((((({js||js})[@res.template ]) ++ foo)[@res.template ]) ++ (({js| |js})[@res.template ])) - [@res.template ]) ^ bar) - [@res.template ]) ^ (({js| |js})[@res.template ])) - [@res.template ]) ^ baz) - [@res.template ]) ^ (({js||js})[@res.template ])) + [@res.template ]) ++ bar) + [@res.template ]) ++ (({js| |js})[@res.template ])) + [@res.template ]) ++ baz) + [@res.template ]) ++ (({js||js})[@res.template ])) [@res.template ]) let s = - (((((((((({js| before |js})[@res.template ]) ^ foo)[@res.template ]) ^ + (((((((((({js| before |js})[@res.template ]) ++ foo)[@res.template ]) ++ (({js| |js})[@res.template ])) - [@res.template ]) ^ bar) - [@res.template ]) ^ (({js| after |js})[@res.template ])) + [@res.template ]) ++ bar) + [@res.template ]) ++ (({js| after |js})[@res.template ])) [@res.template ]) let s = - (((((((((((((({js|before |js})[@res.template ]) ^ foo)[@res.template ]) ^ + (((((((((((((({js|before |js})[@res.template ]) ++ foo)[@res.template ]) ++ (({js| middle |js})[@res.template ])) - [@res.template ]) ^ bar) - [@res.template ]) ^ (({js| |js})[@res.template ])) - [@res.template ]) ^ baz) - [@res.template ]) ^ (({js| wow |js})[@res.template ])) + [@res.template ]) ++ bar) + [@res.template ]) ++ (({js| |js})[@res.template ])) + [@res.template ]) ++ baz) + [@res.template ]) ++ (({js| wow |js})[@res.template ])) [@res.template ]) let s = (({js| @@ -93,15 +93,15 @@ let s = (({js|$dollar without $braces $interpolation|js})[@res.template ]) let s = (({json|null|json})[@res.template ]) let x = (({js|foo\`bar\$\\foo|js})[@res.template ]) let x = - (((((((((({js|foo\`bar\$\\foo|js})[@res.template ]) ^ a)[@res.template ]) ^ - (({js| \` |js})[@res.template ])) - [@res.template ]) ^ b) - [@res.template ]) ^ (({js| \` xx|js})[@res.template ])) + (((((((((({js|foo\`bar\$\\foo|js})[@res.template ]) ++ a)[@res.template ]) + ++ (({js| \` |js})[@res.template ])) + [@res.template ]) ++ b) + [@res.template ]) ++ (({js| \` xx|js})[@res.template ])) [@res.template ]) let thisIsFine = (({js|$something|js})[@res.template ]) let thisIsAlsoFine = (({js|fine\$|js})[@res.template ]) let isThisFine = (({js|shouldBeFine$|js})[@res.template ]) -;;(((((({js|$|js})[@res.template ]) ^ dollarAmountInt)[@res.template ]) ^ +;;(((((({js|$|js})[@res.template ]) ++ dollarAmountInt)[@res.template ]) ++ (({js||js})[@res.template ]))[@res.template ]) -;;(((((({js|\$|js})[@res.template ]) ^ dollarAmountInt)[@res.template ]) ^ +;;(((((({js|\$|js})[@res.template ]) ++ dollarAmountInt)[@res.template ]) ++ (({js||js})[@res.template ]))[@res.template ]) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/infix.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/infix.res.txt index 0ceef89259..ace4a7a9c8 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/infix.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/infix.res.txt @@ -1,5 +1,5 @@ ;;a -> (f b) -;;{js|string1|js} ^ {js|string2|js} +;;{js|string1|js} ++ {js|string2|js} ;;a <> b ;;a != b ;;a = b diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/jsx.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/jsx.res.txt index d1a826b477..7e68d9c539 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/jsx.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/jsx.res.txt @@ -534,8 +534,9 @@ let _ = let _ = ((div ~children:[(((let left = limit -> Int.toString in - (((((({js||js})[@res.template ]) ^ left)[@res.template ]) - ^ (({js| characters left|js})[@res.template ])) + (((((({js||js})[@res.template ]) ++ left) + [@res.template ]) ++ (({js| characters left|js}) + [@res.template ])) [@res.template ]) -> React.string)) [@res.braces ])] ()) [@JSX ]) diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/parenthesized.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/parenthesized.res.txt index 9507c0cfe4..871890abac 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/parenthesized.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/parenthesized.res.txt @@ -6,7 +6,7 @@ let constructor = None let longidentConstructor = Option.None let txt = {js|a string|js} let otherTxt = - (((((({js|foo bar |js})[@res.template ]) ^ txt)[@res.template ]) ^ + (((((({js|foo bar |js})[@res.template ]) ++ txt)[@res.template ]) ++ (({js||js})[@res.template ])) [@res.template ]) let ident = myIdent diff --git a/tests/syntax_tests/data/parsing/other/expected/stringLiterals.res.txt b/tests/syntax_tests/data/parsing/other/expected/stringLiterals.res.txt index 19fcd7de50..1e290bd44f 100644 --- a/tests/syntax_tests/data/parsing/other/expected/stringLiterals.res.txt +++ b/tests/syntax_tests/data/parsing/other/expected/stringLiterals.res.txt @@ -1,12 +1,12 @@ let s = {js|some unicode é £ |js} let s = (({js|foo|js})[@res.template ]) let s = - (((((({js|foo |js})[@res.template ]) ^ bar)[@res.template ]) ^ + (((((({js|foo |js})[@res.template ]) ++ bar)[@res.template ]) ++ (({js| baz|js})[@res.template ])) [@res.template ]) let s = - (((((({js|some unicode é |js})[@res.template ]) ^ bar)[@res.template ]) ^ - (({js| £ |js})[@res.template ])) + (((((({js|some unicode é |js})[@res.template ]) ++ bar)[@res.template ]) + ++ (({js| £ |js})[@res.template ])) [@res.template ]) let s = ((x [|(({js|foo|js})[@res.template ])|] [||])[@res.taggedTemplate ]) let s = diff --git a/tests/syntax_tests/data/parsing/recovery/string/expected/es6template.res.txt b/tests/syntax_tests/data/parsing/recovery/string/expected/es6template.res.txt index 95bf1856a5..7885495f7f 100644 --- a/tests/syntax_tests/data/parsing/recovery/string/expected/es6template.res.txt +++ b/tests/syntax_tests/data/parsing/recovery/string/expected/es6template.res.txt @@ -8,6 +8,6 @@ Did you forget to close this template expression with a backtick? let x = - (((((({js|this contains |js})[@res.template ]) ^ foo)[@res.template ]) ^ + (((((({js|this contains |js})[@res.template ]) ++ foo)[@res.template ]) ++ (({js|, missing closing|js})[@res.template ])) [@res.template ]) \ No newline at end of file diff --git a/tests/tests/src/bs_mutable_set_test.res b/tests/tests/src/bs_mutable_set_test.res index dc31d66fc4..fd2dbf5de0 100644 --- a/tests/tests/src/bs_mutable_set_test.res +++ b/tests/tests/src/bs_mutable_set_test.res @@ -117,7 +117,7 @@ include ( let () = { let aa = f(I.randomRange(0, 100)) let bb = f(I.randomRange(40, 120)) - let cc = \"++"(aa, bb) + let cc = aa ++ bb b(__LOC__, \"=~"(cc, f(I.randomRange(0, 120)))) b( @@ -170,7 +170,7 @@ let () = { } let () = { - let u = \"++"(I.randomRange(30, 100), I.randomRange(40, 120)) + let u = I.randomRange(30, 100) ++ I.randomRange(40, 120) let v = N.make() N.mergeMany(v, u) eq(__LOC__, N.size(v), 91) @@ -178,7 +178,7 @@ let () = { } let () = { - let u = \"++"(I.randomRange(0, 100_000), I.randomRange(0, 100)) + let u = I.randomRange(0, 100_000) ++ I.randomRange(0, 100) let v = N.fromArray(u) eq(__LOC__, N.size(v), 100_001) let u = I.randomRange(50_000, 80_000) @@ -265,7 +265,7 @@ let \"=~" = N.eq let () = { let aa = f(I.randomRange(0, 100)) let bb = f(I.randomRange(40, 120)) - let cc = \"++"(aa, bb) + let cc = aa ++ bb b(__LOC__, \"=~"(cc, f(I.randomRange(0, 120)))) b( diff --git a/tests/tests/src/bs_poly_mutable_set_test.res b/tests/tests/src/bs_poly_mutable_set_test.res index fd3f60d1ac..d8e7e13a11 100644 --- a/tests/tests/src/bs_poly_mutable_set_test.res +++ b/tests/tests/src/bs_poly_mutable_set_test.res @@ -111,7 +111,7 @@ let \"=~" = N.eq let () = { let aa = f(I.randomRange(0, 100)) let bb = f(I.randomRange(40, 120)) - let cc = \"++"(aa, bb) + let cc = aa ++ bb b(__LOC__, \"=~"(cc, f(I.randomRange(0, 120)))) b( diff --git a/tests/tests/src/bs_queue_test.res b/tests/tests/src/bs_queue_test.res index df132d49b0..ca9f08e375 100644 --- a/tests/tests/src/bs_queue_test.res +++ b/tests/tests/src/bs_queue_test.res @@ -23,10 +23,10 @@ let \"++" = (q, x) => { let () = { let q = Q.make() assert(Q.toArray(q) == [] && Q.size(q) == 0) - assert(Q.toArray(\"++"(q, 1)) == [1] && Q.size(q) == 1) - assert(Q.toArray(\"++"(q, 2)) == [1, 2] && Q.size(q) == 2) - assert(Q.toArray(\"++"(q, 3)) == [1, 2, 3] && Q.size(q) == 3) - assert(Q.toArray(\"++"(q, 4)) == [1, 2, 3, 4] && Q.size(q) == 4) + assert(Q.toArray(q ++ 1) == [1] && Q.size(q) == 1) + assert(Q.toArray(q ++ 2) == [1, 2] && Q.size(q) == 2) + assert(Q.toArray(q ++ 3) == [1, 2, 3] && Q.size(q) == 3) + assert(Q.toArray(q ++ 4) == [1, 2, 3, 4] && Q.size(q) == 4) assert(Q.popExn(q) == 1) assert(Q.toArray(q) == [2, 3, 4] && Q.size(q) == 3) assert(Q.popExn(q) == 2) @@ -40,18 +40,18 @@ let () = { let () = { let q = Q.make() - assert(Q.popExn(\"++"(q, 1)) == 1) + assert(Q.popExn(q ++ 1) == 1) assert(does_raise(Q.popExn, q)) - assert(Q.popExn(\"++"(q, 2)) == 2) + assert(Q.popExn(q ++ 2) == 2) assert(does_raise(Q.popExn, q)) assert(Q.size(q) == 0) } let () = { let q = Q.make() - assert(Q.peekExn(\"++"(q, 1)) == 1) - assert(Q.peekExn(\"++"(q, 2)) == 1) - assert(Q.peekExn(\"++"(q, 3)) == 1) + assert(Q.peekExn(q ++ 1) == 1) + assert(Q.peekExn(q ++ 2) == 1) + assert(Q.peekExn(q ++ 3) == 1) assert(Q.peekExn(q) == 1) assert(Q.popExn(q) == 1) assert(Q.peekExn(q) == 2) diff --git a/tests/tools_tests/ppx/TestPpx.res b/tests/tools_tests/ppx/TestPpx.res index 33d32f38d1..9c8fac0f43 100644 --- a/tests/tools_tests/ppx/TestPpx.res +++ b/tests/tools_tests/ppx/TestPpx.res @@ -50,3 +50,5 @@ module Pipe = { let plus = (x, y) => x + y let z = 1->plus(2) } + +let concat = "a" ++ "b" diff --git a/tests/tools_tests/src/expected/TestPpx.res.jsout b/tests/tools_tests/src/expected/TestPpx.res.jsout index bd20990442..e1c2504c33 100644 --- a/tests/tools_tests/src/expected/TestPpx.res.jsout +++ b/tests/tools_tests/src/expected/TestPpx.res.jsout @@ -70,6 +70,8 @@ let Pipe = { z: z }; +let concat = "ab"; + let a = "A"; let b = "B"; @@ -89,4 +91,5 @@ exports.async_foo = async_foo; exports.add = add; exports.partial_add = partial_add; exports.Pipe = Pipe; +exports.concat = concat; /* Not a pure module */ From cda76d2b3fe62bce59b89995baf149a306746940 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Tue, 14 Jan 2025 13:58:21 +0100 Subject: [PATCH 2/6] Represent disequality as `!=` and `!==`. --- compiler/ml/ast_mapper_from0.ml | 6 +++++ compiler/ml/ast_mapper_to0.ml | 6 +++++ compiler/syntax/src/res_core.ml | 4 +--- compiler/syntax/src/res_parsetree_viewer.ml | 2 +- compiler/syntax/src/res_printer.ml | 2 -- runtime/Pervasives.res | 4 ++-- runtime/Pervasives_mini.res | 4 ++-- .../expected/binaryNoEs6Arrow.res.txt | 4 ++-- .../expressions/expected/infix.res.txt | 2 +- .../expected/equalAfterBinaryExpr.res.txt | 14 +++++------ .../expected/nonRecTypes.res.txt | 23 ++++++++++--------- tests/tests/src/bigint_test.res | 2 +- tests/tests/src/float_test.res | 2 +- tests/tools_tests/ppx/TestPpx.res | 3 +++ .../src/expected/TestPpx.res.jsout | 6 +++++ 15 files changed, 51 insertions(+), 33 deletions(-) diff --git a/compiler/ml/ast_mapper_from0.ml b/compiler/ml/ast_mapper_from0.ml index d968606dc7..8207f3236f 100644 --- a/compiler/ml/ast_mapper_from0.ml +++ b/compiler/ml/ast_mapper_from0.ml @@ -319,6 +319,12 @@ module E = struct | ( Pexp_ident ({txt = Longident.Lident "^"} as lid), [(Nolabel, _); (Nolabel, _)] ) -> {e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "++"}} + | ( Pexp_ident ({txt = Longident.Lident "<>"} as lid), + [(Nolabel, _); (Nolabel, _)] ) -> + {e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "!="}} + | ( Pexp_ident ({txt = Longident.Lident "!="} as lid), + [(Nolabel, _); (Nolabel, _)] ) -> + {e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "!=="}} | _ -> e in let process_partial_app_attribute attrs = diff --git a/compiler/ml/ast_mapper_to0.ml b/compiler/ml/ast_mapper_to0.ml index 3ff711407c..d84c58f710 100644 --- a/compiler/ml/ast_mapper_to0.ml +++ b/compiler/ml/ast_mapper_to0.ml @@ -330,6 +330,12 @@ module E = struct | ( Pexp_ident ({txt = Longident.Lident "++"} as lid), [(Nolabel, _); (Nolabel, _)] ) -> {e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "^"}} + | ( Pexp_ident ({txt = Longident.Lident "!="} as lid), + [(Nolabel, _); (Nolabel, _)] ) -> + {e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "<>"}} + | ( Pexp_ident ({txt = Longident.Lident "!=="} as lid), + [(Nolabel, _); (Nolabel, _)] ) -> + {e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "!="}} | _ -> e in let attrs = diff --git a/compiler/syntax/src/res_core.ml b/compiler/syntax/src/res_core.ml index e937d532fb..873b408951 100644 --- a/compiler/syntax/src/res_core.ml +++ b/compiler/syntax/src/res_core.ml @@ -391,9 +391,7 @@ let build_longident words = let make_infix_operator (p : Parser.t) token start_pos end_pos = let stringified_token = - if token = Token.BangEqual then "<>" - else if token = Token.BangEqualEqual then "!=" - else if token = Token.Equal then ( + if token = Token.Equal then ( (* TODO: could have a totally different meaning like x->fooSet(y)*) Parser.err ~start_pos ~end_pos p (Diagnostics.message "Did you mean `==` here?"); diff --git a/compiler/syntax/src/res_parsetree_viewer.ml b/compiler/syntax/src/res_parsetree_viewer.ml index bb49c34f76..723de19add 100644 --- a/compiler/syntax/src/res_parsetree_viewer.ml +++ b/compiler/syntax/src/res_parsetree_viewer.ml @@ -321,7 +321,7 @@ let is_binary_expression expr = let is_equality_operator operator = match operator with - | "=" | "==" | "<>" | "!=" -> true + | "=" | "==" | "!=" | "!==" -> true | _ -> false let is_rhs_binary_operator operator = diff --git a/compiler/syntax/src/res_printer.ml b/compiler/syntax/src/res_printer.ml index 6bdfa377ce..6874f3eb24 100644 --- a/compiler/syntax/src/res_printer.ml +++ b/compiler/syntax/src/res_printer.ml @@ -3666,8 +3666,6 @@ and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl = match operator with | "=" -> "==" | "==" -> "===" - | "<>" -> "!=" - | "!=" -> "!==" | txt -> txt in let spacing_before_operator = diff --git a/runtime/Pervasives.res b/runtime/Pervasives.res index 95c2c7a6bb..6b8c637ebc 100644 --- a/runtime/Pervasives.res +++ b/runtime/Pervasives.res @@ -56,7 +56,7 @@ external mod: ('a, 'a) => 'a = "%mod" /* Note: Later comparisons will be converted to unified operations too */ external \"=": ('a, 'a) => bool = "%equal" -external \"<>": ('a, 'a) => bool = "%notequal" +external \"!=": ('a, 'a) => bool = "%notequal" external \"<": ('a, 'a) => bool = "%lessthan" external \">": ('a, 'a) => bool = "%greaterthan" external \"<=": ('a, 'a) => bool = "%lessequal" @@ -65,7 +65,7 @@ external compare: ('a, 'a) => int = "%compare" external min: ('a, 'a) => 'a = "%min" external max: ('a, 'a) => 'a = "%max" external \"==": ('a, 'a) => bool = "%eq" -external \"!=": ('a, 'a) => bool = "%noteq" +external \"!==": ('a, 'a) => bool = "%noteq" /* Boolean operations */ diff --git a/runtime/Pervasives_mini.res b/runtime/Pervasives_mini.res index b0c9380c29..47256f6f3a 100644 --- a/runtime/Pervasives_mini.res +++ b/runtime/Pervasives_mini.res @@ -35,7 +35,7 @@ external mod: (int, int) => int = "%modint" /* Note: Later comparisons will be converted to unified operations too */ external \"=": ('a, 'a) => bool = "%equal" -external \"<>": ('a, 'a) => bool = "%notequal" +external \"!=": ('a, 'a) => bool = "%notequal" external \"<": ('a, 'a) => bool = "%lessthan" external \">": ('a, 'a) => bool = "%greaterthan" external \"<=": ('a, 'a) => bool = "%lessequal" @@ -44,7 +44,7 @@ external compare: ('a, 'a) => int = "%compare" external min: ('a, 'a) => 'a = "%min" external max: ('a, 'a) => 'a = "%max" external \"==": ('a, 'a) => bool = "%eq" -external \"!=": ('a, 'a) => bool = "%noteq" +external \"!==": ('a, 'a) => bool = "%noteq" /* Boolean operations */ diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/binaryNoEs6Arrow.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/binaryNoEs6Arrow.res.txt index 14693a33fb..d7bf10c836 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/binaryNoEs6Arrow.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/binaryNoEs6Arrow.res.txt @@ -1,11 +1,11 @@ ;;if (color == Black) && ((sibling == None) || (parent == None)) then () ;;if - ((color == Black) && (color != Red)) && + ((color == Black) && ((!==) color Red)) && ((sibling == None) || (parent == None)) then () ;;match (color == Black) && ((sibling == None) || (parent == None)) with | _ -> () -;;match ((color == Black) && (color != Red)) && +;;match ((color == Black) && ((!==) color Red)) && ((sibling == None) || (parent == None)) with | _ -> () diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/infix.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/infix.res.txt index ace4a7a9c8..923e7c0f8b 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/infix.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/infix.res.txt @@ -1,6 +1,6 @@ ;;a -> (f b) ;;{js|string1|js} ++ {js|string2|js} -;;a <> b ;;a != b +;;(!==) a b ;;a = b ;;a == b \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/infiniteLoops/expected/equalAfterBinaryExpr.res.txt b/tests/syntax_tests/data/parsing/infiniteLoops/expected/equalAfterBinaryExpr.res.txt index bc85040917..d8996c816f 100644 --- a/tests/syntax_tests/data/parsing/infiniteLoops/expected/equalAfterBinaryExpr.res.txt +++ b/tests/syntax_tests/data/parsing/infiniteLoops/expected/equalAfterBinaryExpr.res.txt @@ -19,7 +19,7 @@ let rec _addLoop [arity:2]rbt currentNode = else if (((let uncle = uncleOf currentNode in - (uncle != None) && ((uncle -> castNotOption).color == Red))) + ((!==) uncle None) && ((uncle -> castNotOption).color == Red))) [@res.braces ]) then ((currentNode.parent -> castNotOption).color <- Black; @@ -67,7 +67,7 @@ let removeNode [arity:2]rbt node = | Some successorParent -> let sibling = siblingOf successor in (if - (sibling != None) && + ((!==) sibling None) && ((sibling -> castNotOption).color == Red) then (successorParent.color <- Red; @@ -89,7 +89,7 @@ let removeNode [arity:2]rbt node = ((siblingNN.right -> castNotOption).color == Black)))) then - (if sibling != None then siblingNN.color <- Red; + (if (!==) sibling None then siblingNN.color <- Red; successorRef.contents <- successorParent) else if @@ -104,12 +104,12 @@ let removeNode [arity:2]rbt node = ((siblingNN.right -> castNotOption).color == Black)))) then - (if sibling != None then siblingNN.color <- Red; + (if (!==) sibling None then siblingNN.color <- Red; successorParent.color <- Black; break.contents <- true) else if - (sibling != None) && + ((!==) sibling None) && ((sibling -> castNotOption).color == Black) then (let sibling = sibling -> castNotOption in @@ -118,7 +118,7 @@ let removeNode [arity:2]rbt node = ((sibling.right == None) || ((sibling.right -> castNotOption).color == Black))) - && (sibling.left != None)) + && ((!==) sibling.left None)) && ((sibling.left -> castNotOption).color == Red) then @@ -131,7 +131,7 @@ let removeNode [arity:2]rbt node = ((sibling.left == None) || ((sibling.left -> castNotOption).color == Black))) - && (sibling.right != None)) + && ((!==) sibling.right None)) && ((sibling.right -> castNotOption).color == Red) then diff --git a/tests/syntax_tests/data/parsing/infiniteLoops/expected/nonRecTypes.res.txt b/tests/syntax_tests/data/parsing/infiniteLoops/expected/nonRecTypes.res.txt index c15c53f0c6..9153cdd692 100644 --- a/tests/syntax_tests/data/parsing/infiniteLoops/expected/nonRecTypes.res.txt +++ b/tests/syntax_tests/data/parsing/infiniteLoops/expected/nonRecTypes.res.txt @@ -120,7 +120,8 @@ include ;;{js||js} ;;{js|BS:6.0.1\x84\x95\xa6\xbe\0\0\0\x13\0\0\0\x07\0\0\0\x14\0\0\0\x13\xb0\xa0\xa0A\x91@@A\x98\xa0'compare@|js} end - let has [arity:2]rbt value = (_findNode rbt (rootGet rbt) value) != None + let has [arity:2]rbt value = + (!==) (_findNode rbt (rootGet rbt) value) None let rec minNode [arity:1]node = [%rescript.exprhole ] let findMin [arity:1]rbt = [%rescript.exprhole ] let removeNode [arity:2]rbt node = @@ -173,7 +174,7 @@ include | Some successorParent -> let sibling = siblingOf successor in (if - (sibling != None) && + ((!==) sibling None) && ((colorGet (castNotOption sibling)) == Red) then (colorSet successorParent Red; @@ -197,7 +198,7 @@ include (castNotOption (rightGet siblingNN))) == Black)))) then - (if sibling != None then colorSet siblingNN Red; + (if (!==) sibling None then colorSet siblingNN Red; successorRef.contents <- successorParent) else if @@ -214,12 +215,12 @@ include (castNotOption (rightGet siblingNN))) == Black)))) then - (if sibling != None then colorSet siblingNN Red; + (if (!==) sibling None then colorSet siblingNN Red; colorSet successorParent Black; break.contents <- true) else if - (sibling != None) && + ((!==) sibling None) && ((colorGet (castNotOption sibling)) == Black) then (let sibling = castNotOption sibling in @@ -229,7 +230,7 @@ include ((colorGet (castNotOption (rightGet sibling))) == Black))) - && ((leftGet sibling) != None)) + && ((!==) (leftGet sibling) None)) && ((colorGet (castNotOption (leftGet sibling))) == Red) @@ -245,7 +246,7 @@ include ((colorGet (castNotOption (leftGet sibling))) == Black))) - && ((rightGet sibling) != None)) + && ((!==) (rightGet sibling) None)) && ((colorGet (castNotOption (rightGet sibling))) @@ -313,14 +314,14 @@ include then sumGet n else if - (lhs != None) && + ((!==) lhs None) && ((Js.Internal.fn_run2 (compareGet rbt) (valueGet n) (castNotOption lhs)) < 0) then heightOfInterval rbt (rightGet n) lhs rhs else if - (rhs != None) && + ((!==) rhs None) && ((Js.Internal.fn_run2 (compareGet rbt) (valueGet n) (castNotOption rhs)) > 0) @@ -407,7 +408,7 @@ include | None -> () | Some node -> (if inclusive then Js.Internal.fn_run1 callback node; - if firstNode != lastNode + if (!==) firstNode lastNode then (if not inclusive then Js.Internal.fn_run1 callback node; iterate ~inclusive:((inclusive)[@res.namedArgLoc ]) @@ -421,7 +422,7 @@ include | Some node -> let y = match y with | None -> getY node | Some y -> y in (if inclusive then Js.Internal.fn_run2 callback node y; - if firstNode != lastNode + if (!==) firstNode lastNode then (if not inclusive then Js.Internal.fn_run2 callback node y; iterateWithY ~y:((y +. (heightGet node))[@res.namedArgLoc ]) diff --git a/tests/tests/src/bigint_test.res b/tests/tests/src/bigint_test.res index 70b3f16d91..ce79969d5d 100644 --- a/tests/tests/src/bigint_test.res +++ b/tests/tests/src/bigint_test.res @@ -7,7 +7,7 @@ let generic_compare = Pervasives.compare let bigint_equal = (x: bigint, y) => x == y let generic_equal = \"=" let bigint_notequal = (x: bigint, y) => x != y -let generic_notequal = \"<>" +let generic_notequal = \"!=" let bigint_lessthan = (x: bigint, y) => x < y let generic_lessthan = \"<" let bigint_greaterthan = (x: bigint, y) => x > y diff --git a/tests/tests/src/float_test.res b/tests/tests/src/float_test.res index c16fcdc0a2..8078fb2731 100644 --- a/tests/tests/src/float_test.res +++ b/tests/tests/src/float_test.res @@ -14,7 +14,7 @@ let generic_compare = Pervasives.compare let float_equal = (x: float, y) => x == y let generic_equal = \"=" let float_notequal = (x: float, y) => x != y -let generic_notequal = \"<>" +let generic_notequal = \"!=" let float_lessthan = (x: float, y) => x < y let generic_lessthan = \"<" let float_greaterthan = (x: float, y) => x > y diff --git a/tests/tools_tests/ppx/TestPpx.res b/tests/tools_tests/ppx/TestPpx.res index 9c8fac0f43..83c6522430 100644 --- a/tests/tools_tests/ppx/TestPpx.res +++ b/tests/tools_tests/ppx/TestPpx.res @@ -52,3 +52,6 @@ module Pipe = { } let concat = "a" ++ "b" + +let neq = 3 != 3 +let neq2 = 3 !== 3 \ No newline at end of file diff --git a/tests/tools_tests/src/expected/TestPpx.res.jsout b/tests/tools_tests/src/expected/TestPpx.res.jsout index e1c2504c33..854a6e4ffe 100644 --- a/tests/tools_tests/src/expected/TestPpx.res.jsout +++ b/tests/tools_tests/src/expected/TestPpx.res.jsout @@ -78,6 +78,10 @@ let b = "B"; let vv = 10; +let neq = false; + +let neq2 = false; + exports.a = a; exports.b = b; exports.M = M; @@ -92,4 +96,6 @@ exports.add = add; exports.partial_add = partial_add; exports.Pipe = Pipe; exports.concat = concat; +exports.neq = neq; +exports.neq2 = neq2; /* Not a pure module */ From 96ef15cafdbfd2bb04e024bf813b089ca4df82ce Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Tue, 14 Jan 2025 14:18:51 +0100 Subject: [PATCH 3/6] Represent equality as `==` and `===`. --- .../larger-project/src/res_comments_table.res | 2 +- analysis/src/Xform.ml | 4 +- compiler/ml/ast_mapper_from0.ml | 14 +++- compiler/ml/ast_mapper_to0.ml | 6 ++ compiler/ml/error_message_utils.ml | 2 +- compiler/syntax/src/res_comments_table.ml | 2 +- compiler/syntax/src/res_core.ml | 2 - compiler/syntax/src/res_parsetree_viewer.ml | 6 +- compiler/syntax/src/res_printer.ml | 8 +-- runtime/Pervasives.res | 4 +- runtime/Pervasives_mini.res | 4 +- .../errors/expressions/expected/block.res.txt | 2 +- .../structure/expected/letBinding.res.txt | 2 +- .../expressions/expected/arrow.res.txt | 4 +- .../expressions/expected/binary.res.txt | 6 +- .../expected/binaryNoEs6Arrow.res.txt | 24 +++---- .../expressions/expected/block.res.txt | 6 +- .../grammar/expressions/expected/if.res.txt | 6 +- .../expressions/expected/infix.res.txt | 4 +- .../grammar/expressions/expected/jsx.res.txt | 4 +- .../expected/underscoreApply.res.txt | 2 +- .../expected/equalAfterBinaryExpr.res.txt | 65 ++++++++++--------- .../expected/nonRecTypes.res.txt | 60 ++++++++--------- .../parsing/other/expected/attributes.res.txt | 2 +- .../recovery/expression/expected/if.res.txt | 2 +- tests/tests/src/belt_list_test.res | 32 ++++----- tests/tests/src/bigint_test.res | 2 +- tests/tests/src/bs_array_test.res | 2 +- tests/tests/src/bs_mutable_set_test.res | 8 +-- tests/tests/src/bs_poly_map_test.res | 8 +-- tests/tests/src/bs_poly_mutable_set_test.res | 8 +-- tests/tests/src/core/Core_ErrorTests.mjs | 3 +- tests/tests/src/float_test.res | 2 +- tests/tests/src/gpr_2487.res | 2 +- tests/tests/src/variant.res | 2 +- tests/tools_tests/ppx/TestPpx.res | 5 +- .../src/expected/TestPpx.res.jsout | 6 ++ 37 files changed, 172 insertions(+), 151 deletions(-) diff --git a/analysis/examples/larger-project/src/res_comments_table.res b/analysis/examples/larger-project/src/res_comments_table.res index 9683e9f28c..40536a9c6d 100644 --- a/analysis/examples/larger-project/src/res_comments_table.res +++ b/analysis/examples/larger-project/src/res_comments_table.res @@ -1236,8 +1236,8 @@ and walkExpr = (expr, t, comments) => { ":=" | "||" | "&&" - | "=" | "==" + | "===" | "<" | ">" | "!=" diff --git a/analysis/src/Xform.ml b/analysis/src/Xform.ml index 2077affb86..837f7df744 100644 --- a/analysis/src/Xform.ml +++ b/analysis/src/Xform.ml @@ -93,7 +93,7 @@ module IfThenElse = struct { pexp_desc = Pexp_ident - {txt = Longident.Lident (("=" | "<>") as op)}; + {txt = Longident.Lident (("==" | "!=") as op)}; }; args = [(Nolabel, arg1); (Nolabel, arg2)]; }; @@ -101,7 +101,7 @@ module IfThenElse = struct e1, Some e2 ) when Loc.hasPos ~pos e.pexp_loc -> ( - let e1, e2 = if op = "=" then (e1, e2) else (e2, e1) in + let e1, e2 = if op = "==" then (e1, e2) else (e2, e1) in let mkMatch ~arg ~pat = let cases = [ diff --git a/compiler/ml/ast_mapper_from0.ml b/compiler/ml/ast_mapper_from0.ml index 8207f3236f..ddba26ae88 100644 --- a/compiler/ml/ast_mapper_from0.ml +++ b/compiler/ml/ast_mapper_from0.ml @@ -324,7 +324,19 @@ module E = struct {e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "!="}} | ( Pexp_ident ({txt = Longident.Lident "!="} as lid), [(Nolabel, _); (Nolabel, _)] ) -> - {e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "!=="}} + { + e with + pexp_desc = Pexp_ident {lid with txt = Longident.Lident "!=="}; + } + | ( Pexp_ident ({txt = Longident.Lident "="} as lid), + [(Nolabel, _); (Nolabel, _)] ) -> + {e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "=="}} + | ( Pexp_ident ({txt = Longident.Lident "=="} as lid), + [(Nolabel, _); (Nolabel, _)] ) -> + { + e with + pexp_desc = Pexp_ident {lid with txt = Longident.Lident "==="}; + } | _ -> e in let process_partial_app_attribute attrs = diff --git a/compiler/ml/ast_mapper_to0.ml b/compiler/ml/ast_mapper_to0.ml index d84c58f710..b3a4857c81 100644 --- a/compiler/ml/ast_mapper_to0.ml +++ b/compiler/ml/ast_mapper_to0.ml @@ -336,6 +336,12 @@ module E = struct | ( Pexp_ident ({txt = Longident.Lident "!=="} as lid), [(Nolabel, _); (Nolabel, _)] ) -> {e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "!="}} + | ( Pexp_ident ({txt = Longident.Lident "==="} as lid), + [(Nolabel, _); (Nolabel, _)] ) -> + {e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "=="}} + | ( Pexp_ident ({txt = Longident.Lident "=="} as lid), + [(Nolabel, _); (Nolabel, _)] ) -> + {e with pexp_desc = Pexp_ident {lid with txt = Longident.Lident "="}} | _ -> e in let attrs = diff --git a/compiler/ml/error_message_utils.ml b/compiler/ml/error_message_utils.ml index 4df379693f..d565e7430a 100644 --- a/compiler/ml/error_message_utils.ml +++ b/compiler/ml/error_message_utils.ml @@ -204,7 +204,7 @@ let type_clash_context_from_function sexp sfunct = in match sfunct.Parsetree.pexp_desc with | Pexp_ident - {txt = Lident ("=" | "==" | "<>" | "!=" | ">" | ">=" | "<" | "<=")} -> + {txt = Lident ("==" | "===" | "!=" | "!==" | ">" | ">=" | "<" | "<=")} -> Some ComparisonOperator | Pexp_ident {txt = Lident "++"} -> Some StringConcat | Pexp_ident {txt = Lident (("/." | "*." | "+." | "-.") as operator)} -> diff --git a/compiler/syntax/src/res_comments_table.ml b/compiler/syntax/src/res_comments_table.ml index e21cedd9e4..8db0852cb3 100644 --- a/compiler/syntax/src/res_comments_table.ml +++ b/compiler/syntax/src/res_comments_table.ml @@ -1338,7 +1338,7 @@ and walk_expression expr t comments = { txt = Longident.Lident - ( ":=" | "||" | "&&" | "=" | "==" | "<" | ">" | "!=" + ( ":=" | "||" | "&&" | "==" | "===" | "<" | ">" | "!=" | "!==" | "<=" | ">=" | "|>" | "+" | "+." | "-" | "-." | "++" | "^" | "*" | "*." | "/" | "/." | "**" | "->" | "<>" ); diff --git a/compiler/syntax/src/res_core.ml b/compiler/syntax/src/res_core.ml index 873b408951..74c03c890a 100644 --- a/compiler/syntax/src/res_core.ml +++ b/compiler/syntax/src/res_core.ml @@ -396,8 +396,6 @@ let make_infix_operator (p : Parser.t) token start_pos end_pos = Parser.err ~start_pos ~end_pos p (Diagnostics.message "Did you mean `==` here?"); "=") - else if token = Token.EqualEqual then "=" - else if token = Token.EqualEqualEqual then "==" else Token.to_string token in let loc = mk_loc start_pos end_pos in diff --git a/compiler/syntax/src/res_parsetree_viewer.ml b/compiler/syntax/src/res_parsetree_viewer.ml index 723de19add..043a2a1863 100644 --- a/compiler/syntax/src/res_parsetree_viewer.ml +++ b/compiler/syntax/src/res_parsetree_viewer.ml @@ -270,7 +270,7 @@ let operator_precedence operator = | ":=" -> 1 | "||" -> 2 | "&&" -> 3 - | "=" | "==" | "<" | ">" | "!=" | "<>" | "!==" | "<=" | ">=" | "|>" -> 4 + | "==" | "===" | "<" | ">" | "!=" | "<>" | "!==" | "<=" | ">=" | "|>" -> 4 | "+" | "+." | "-" | "-." | "++" -> 5 | "*" | "*." | "/" | "/." | "%" -> 6 | "**" -> 7 @@ -296,7 +296,7 @@ let is_unary_expression expr = (* TODO: tweak this to check for ghost ^ as template literal *) let is_binary_operator operator = match operator with - | ":=" | "||" | "&&" | "=" | "==" | "<" | ">" | "!=" | "!==" | "<=" | ">=" + | ":=" | "||" | "&&" | "==" | "===" | "<" | ">" | "!=" | "!==" | "<=" | ">=" | "|>" | "+" | "+." | "-" | "-." | "++" | "*" | "*." | "/" | "/." | "**" | "->" | "<>" | "%" -> true @@ -321,7 +321,7 @@ let is_binary_expression expr = let is_equality_operator operator = match operator with - | "=" | "==" | "!=" | "!==" -> true + | "==" | "===" | "!=" | "!==" -> true | _ -> false let is_rhs_binary_operator operator = diff --git a/compiler/syntax/src/res_printer.ml b/compiler/syntax/src/res_printer.ml index 6874f3eb24..3aee2aa5a7 100644 --- a/compiler/syntax/src/res_printer.ml +++ b/compiler/syntax/src/res_printer.ml @@ -3662,12 +3662,6 @@ and print_unary_expression ~state expr cmt_tbl = and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl = let print_binary_operator ~inline_rhs operator = - let operator_txt = - match operator with - | "=" -> "==" - | "==" -> "===" - | txt -> txt - in let spacing_before_operator = if operator = "->" then Doc.soft_line else if operator = "|>" then Doc.line @@ -3680,7 +3674,7 @@ and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl = else Doc.line in Doc.concat - [spacing_before_operator; Doc.text operator_txt; spacing_after_operator] + [spacing_before_operator; Doc.text operator; spacing_after_operator] in let print_operand ~is_lhs ~is_multiline expr parent_operator = let rec flatten ~is_lhs ~is_multiline expr parent_operator = diff --git a/runtime/Pervasives.res b/runtime/Pervasives.res index 6b8c637ebc..82b2914328 100644 --- a/runtime/Pervasives.res +++ b/runtime/Pervasives.res @@ -55,7 +55,7 @@ external mod: ('a, 'a) => 'a = "%mod" /* Comparisons */ /* Note: Later comparisons will be converted to unified operations too */ -external \"=": ('a, 'a) => bool = "%equal" +external \"==": ('a, 'a) => bool = "%equal" external \"!=": ('a, 'a) => bool = "%notequal" external \"<": ('a, 'a) => bool = "%lessthan" external \">": ('a, 'a) => bool = "%greaterthan" @@ -64,7 +64,7 @@ external \">=": ('a, 'a) => bool = "%greaterequal" external compare: ('a, 'a) => int = "%compare" external min: ('a, 'a) => 'a = "%min" external max: ('a, 'a) => 'a = "%max" -external \"==": ('a, 'a) => bool = "%eq" +external \"===": ('a, 'a) => bool = "%eq" external \"!==": ('a, 'a) => bool = "%noteq" /* Boolean operations */ diff --git a/runtime/Pervasives_mini.res b/runtime/Pervasives_mini.res index 47256f6f3a..7049284417 100644 --- a/runtime/Pervasives_mini.res +++ b/runtime/Pervasives_mini.res @@ -34,7 +34,7 @@ external mod: (int, int) => int = "%modint" /* Comparisons */ /* Note: Later comparisons will be converted to unified operations too */ -external \"=": ('a, 'a) => bool = "%equal" +external \"==": ('a, 'a) => bool = "%equal" external \"!=": ('a, 'a) => bool = "%notequal" external \"<": ('a, 'a) => bool = "%lessthan" external \">": ('a, 'a) => bool = "%greaterthan" @@ -43,7 +43,7 @@ external \">=": ('a, 'a) => bool = "%greaterequal" external compare: ('a, 'a) => int = "%compare" external min: ('a, 'a) => 'a = "%min" external max: ('a, 'a) => 'a = "%max" -external \"==": ('a, 'a) => bool = "%eq" +external \"===": ('a, 'a) => bool = "%eq" external \"!==": ('a, 'a) => bool = "%noteq" /* Boolean operations */ diff --git a/tests/syntax_tests/data/parsing/errors/expressions/expected/block.res.txt b/tests/syntax_tests/data/parsing/errors/expressions/expected/block.res.txt index abb4a962d2..6fdd1ca056 100644 --- a/tests/syntax_tests/data/parsing/errors/expressions/expected/block.res.txt +++ b/tests/syntax_tests/data/parsing/errors/expressions/expected/block.res.txt @@ -75,7 +75,7 @@ let findThreadByIdLinearScan [arity:2]~threads:((threads)[@res.namedArgLoc ]) | Group { id } -> id | Unknown { id } -> (unknown.id -> Js.String.make) -> FBID.ofStringUnsafe in - thisId == id) + thisId === id) [@res.braces ]))) [@res.braces ]) let x = ((loop 0 (Nil -> (push doc)))[@res.braces ]) diff --git a/tests/syntax_tests/data/parsing/errors/structure/expected/letBinding.res.txt b/tests/syntax_tests/data/parsing/errors/structure/expected/letBinding.res.txt index 739d1f5329..f0cf2ceef1 100644 --- a/tests/syntax_tests/data/parsing/errors/structure/expected/letBinding.res.txt +++ b/tests/syntax_tests/data/parsing/errors/structure/expected/letBinding.res.txt @@ -99,7 +99,7 @@ let rightResource = (ur.resources).find - (fun [arity:1]r -> r.account_id == ((connection.left).account).id) + (fun [arity:1]r -> r.account_id === ((connection.left).account).id) let x = ((let field = p -> parseFieldDeclaration in field)[@res.braces ]) let t = ((let (_, _, token) = scanner -> scan in token)[@res.braces ]) let (keyTable : int Belt.Map.String.t) = [%rescript.exprhole ] diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/arrow.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/arrow.res.txt index 60d6e9da1e..6c16e83722 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/arrow.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/arrow.res.txt @@ -52,9 +52,9 @@ let f [arity:4]~a:((a)[@res.namedArgLoc ][@attr ]) ((b)[@attrOnB ]) let f [arity:1]list = list () ;;match colour with | Red when - (l = l') || + (l == l') || (Clflags.classic.contents && - ((l = Nolabel) && (not (is_optional l')))) + ((l == Nolabel) && (not (is_optional l')))) -> (t1, t2) | _ -> () let arr = diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/binary.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/binary.res.txt index 4e54e2c4e0..dd3bd7262d 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/binary.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/binary.res.txt @@ -1,5 +1,5 @@ -;;node := (if newBalance == 2 then avl -> (rotateRight node) else node) -;;node := ((if newBalance == 2 then avl -> (rotateRight node) else node) +;;node := (if newBalance === 2 then avl -> (rotateRight node) else node) +;;node := ((if newBalance === 2 then avl -> (rotateRight node) else node) [@attr ]) let x = (match z with | _ -> false) z let x = ((match z with | _ -> false)[@attr ]) z @@ -13,7 +13,7 @@ let x = while condition do () done z let x = ((while condition do () done)[@attr ]) z let x = (a + (-1)) + (-2) let x = (a + (((-1))[@attr ])) + (((-2))[@attr ]) -let x = (a % a) = 0 +let x = (a % a) == 0 let x = a - b let x = a -. b ;;Constructor (a, b) diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/binaryNoEs6Arrow.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/binaryNoEs6Arrow.res.txt index d7bf10c836..b510458769 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/binaryNoEs6Arrow.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/binaryNoEs6Arrow.res.txt @@ -1,25 +1,25 @@ -;;if (color == Black) && ((sibling == None) || (parent == None)) then () +;;if (color === Black) && ((sibling === None) || (parent === None)) then () ;;if - ((color == Black) && ((!==) color Red)) && - ((sibling == None) || (parent == None)) + ((color === Black) && ((!==) color Red)) && + ((sibling === None) || (parent === None)) then () -;;match (color == Black) && ((sibling == None) || (parent == None)) with +;;match (color === Black) && ((sibling === None) || (parent === None)) with | _ -> () -;;match ((color == Black) && ((!==) color Red)) && - ((sibling == None) || (parent == None)) +;;match ((color === Black) && ((!==) color Red)) && + ((sibling === None) || (parent === None)) with | _ -> () -;;try (color == Black) && ((sibling == None) || (parent == None)) +;;try (color === Black) && ((sibling === None) || (parent === None)) with | _ -> () ;;try - ((color == Black) && (color == Red)) && - ((sibling == None) || (parent == None)) + ((color === Black) && (color === Red)) && + ((sibling === None) || (parent === None)) with | _ -> () -;;while (color == Black) && ((sibling == None) || (parent == None)) do () +;;while (color === Black) && ((sibling === None) || (parent === None)) do () done ;;while - ((color == Black) && (color == Red)) && - ((sibling == None) || (parent == None)) + ((color === Black) && (color === Red)) && + ((sibling === None) || (parent === None)) do () done ;;((div ~onClick:((fun [arity:1]event -> diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/block.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/block.res.txt index 48be97d9a8..81b64a4216 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/block.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/block.res.txt @@ -40,8 +40,8 @@ let res = [@res.braces ]) let nestedLet = ((let _ = 1 in ())[@res.braces ]) let nestedLet = ((let _ = 1 in 2)[@res.braces ]) -let init [arity:1]() = ((foo (1 == 1); [%assert 1 == 2])[@res.braces ]) -let init [arity:1]() = (([%assert 1 == 2]; foo (1 == 1); [%assert 1 == 2]) +let init [arity:1]() = ((foo (1 === 1); [%assert 1 === 2])[@res.braces ]) +let init [arity:1]() = (([%assert 1 === 2]; foo (1 === 1); [%assert 1 === 2]) [@res.braces ]) let f [arity:1]() = ((let x = 1 in fun [arity:1]_ -> ())[@res.braces ]) let reifyStyle (type a) [arity:1](x : 'a) = @@ -55,7 +55,7 @@ let reifyStyle (type a) [arity:1](x : 'a) = (({js|function(x,y) {return +(x instanceof y)}|js}) [@res.template ])] : 'a -> constructor -> bool (a:2)) end in - ((if (Js.typeof x) = {js|string|js} + ((if (Js.typeof x) == {js|string|js} then Obj.magic String else if Internal.instanceOf x Internal.canvasGradient diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/if.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/if.res.txt index da4cf19819..2691e6b6da 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/if.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/if.res.txt @@ -1,8 +1,8 @@ ;;if foo then true else false -;;if foo = 2 then let bar = 1 in let foo = 2 in bar + foo +;;if foo == 2 then let bar = 1 in let foo = 2 in bar + foo let ifThenElse = if foo then lala else doStuff x y z let ifElseIfThen = - if foo = bar + if foo == bar then f () - else if foo = bar2 then f1 () else if foo = bar3 then f2 () else f3 () + else if foo == bar2 then f1 () else if foo == bar3 then f2 () else f3 () let x = (if true then 1 else 2) + (if false then 2 else 3) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/infix.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/infix.res.txt index 923e7c0f8b..a2771425a1 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/infix.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/infix.res.txt @@ -2,5 +2,5 @@ ;;{js|string1|js} ++ {js|string2|js} ;;a != b ;;(!==) a b -;;a = b -;;a == b \ No newline at end of file +;;a == b +;;a === b \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/jsx.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/jsx.res.txt index 7e68d9c539..b419ba2906 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/jsx.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/jsx.res.txt @@ -159,7 +159,7 @@ let y = let pathFromState = Routes.stateToPath latestComponentBag.state in - ((if currentActualPath = pathFromState + ((if currentActualPath == pathFromState then None else dispatchEventless @@ -220,7 +220,7 @@ let icon = [@JSX ]) let _ = ((MessengerSharedPhotosAlbumViewPhotoReact.createElement - ?ref:((if foo#bar == baz + ?ref:((if foo#bar === baz then Some (foooooooooooooooooooooooo setRefChild) else None)[@res.namedArgLoc ][@res.ternary ]) ~key:((node#legacy_attachment_id)[@res.namedArgLoc ]) ~children:[] ()) diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/underscoreApply.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/underscoreApply.res.txt index 9a48ac55c2..5c29a6c063 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/underscoreApply.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/underscoreApply.res.txt @@ -9,7 +9,7 @@ let incr [arity:1]~v:((v)[@res.namedArgLoc ]) = v + 1 let l1 = List.length (List.map (fun [arity:1]__x -> incr ~v:__x) [1; 2; 3]) let l2 = List.length (List.map (fun [arity:1]__x -> incr ~v:__x) [1; 2; 3]) let optParam [arity:2]?v:((v)[@res.namedArgLoc ]) () = - ((if v = None then 0 else 1)[@res.ternary ]) + ((if v == None then 0 else 1)[@res.ternary ]) let l1 = List.length (List.map (fun [arity:1]__x -> optParam ?v:__x ()) [Some 1; None; Some 2]) diff --git a/tests/syntax_tests/data/parsing/infiniteLoops/expected/equalAfterBinaryExpr.res.txt b/tests/syntax_tests/data/parsing/infiniteLoops/expected/equalAfterBinaryExpr.res.txt index d8996c816f..e2f756a267 100644 --- a/tests/syntax_tests/data/parsing/infiniteLoops/expected/equalAfterBinaryExpr.res.txt +++ b/tests/syntax_tests/data/parsing/infiniteLoops/expected/equalAfterBinaryExpr.res.txt @@ -11,15 +11,15 @@ Did you mean `==` here? let rec _addLoop [arity:2]rbt currentNode = - ((if (Some currentNode) == (rbt -> root) + ((if (Some currentNode) === (rbt -> root) then currentNode.color <- Black else - if (currentNode.parent -> castNotOption).color == Black + if (currentNode.parent -> castNotOption).color === Black then () else if (((let uncle = uncleOf currentNode in - ((!==) uncle None) && ((uncle -> castNotOption).color == Red))) + ((!==) uncle None) && ((uncle -> castNotOption).color === Red))) [@res.braces ]) then ((currentNode.parent -> castNotOption).color <- Black; @@ -50,12 +50,12 @@ let rec _addLoop [arity:2]rbt currentNode = else rotateLeft rbt ((grandParentOf currentNode) -> castNotOption))) [@res.braces ]) let removeNode [arity:2]rbt node = - ((if nodeToRemove.color == Black + ((if nodeToRemove.color === Black then - (if successor.color == Red + (if successor.color === Red then (successor.color <- Black; - if successor.parent == None then rbt -> (rootSet (Some successor))) + if successor.parent === None then rbt -> (rootSet (Some successor))) else (let break = ref false in let successorRef = ref successor in @@ -68,7 +68,7 @@ let removeNode [arity:2]rbt node = let sibling = siblingOf successor in (if ((!==) sibling None) && - ((sibling -> castNotOption).color == Red) + ((sibling -> castNotOption).color === Red) then (successorParent.color <- Red; (sibling -> castNotOption).color <- Black; @@ -78,31 +78,31 @@ let removeNode [arity:2]rbt node = (let sibling = siblingOf successor in let siblingNN = sibling -> castNotOption in if - (successorParent.color == Black) && - ((sibling == None) || - (((siblingNN.color == Black) && - ((siblingNN.left == None) || - ((siblingNN.left -> castNotOption).color == + (successorParent.color === Black) && + ((sibling === None) || + (((siblingNN.color === Black) && + ((siblingNN.left === None) || + ((siblingNN.left -> castNotOption).color === Black))) && - ((siblingNN.right == None) || - ((siblingNN.right -> castNotOption).color == + ((siblingNN.right === None) || + ((siblingNN.right -> castNotOption).color === Black)))) then (if (!==) sibling None then siblingNN.color <- Red; successorRef.contents <- successorParent) else if - (successorParent.color == Red) && - ((sibling == None) || - (((siblingNN.color == Black) && - ((siblingNN.left == None) || - ((siblingNN.left -> castNotOption).color == - Black))) + (successorParent.color === Red) && + ((sibling === None) || + (((siblingNN.color === Black) && + ((siblingNN.left === None) || + ((siblingNN.left -> castNotOption).color + === Black))) && - ((siblingNN.right == None) || - ((siblingNN.right -> castNotOption).color == - Black)))) + ((siblingNN.right === None) || + ((siblingNN.right -> castNotOption).color + === Black)))) then (if (!==) sibling None then siblingNN.color <- Red; successorParent.color <- Black; @@ -110,17 +110,17 @@ let removeNode [arity:2]rbt node = else if ((!==) sibling None) && - ((sibling -> castNotOption).color == Black) + ((sibling -> castNotOption).color === Black) then (let sibling = sibling -> castNotOption in if (((isLeft successor) && - ((sibling.right == None) || - ((sibling.right -> castNotOption).color == + ((sibling.right === None) || + ((sibling.right -> castNotOption).color === Black))) && ((!==) sibling.left None)) && - ((sibling.left -> castNotOption).color == Red) + ((sibling.left -> castNotOption).color === Red) then (sibling.color <- Red; (sibling.left -> castNotOption).color <- Black; @@ -128,12 +128,13 @@ let removeNode [arity:2]rbt node = else if (((not (isLeft successor)) && - ((sibling.left == None) || - ((sibling.left -> castNotOption).color == - Black))) + ((sibling.left === None) || + ((sibling.left -> castNotOption).color + === Black))) && ((!==) sibling.right None)) && - ((sibling.right -> castNotOption).color == Red) + ((sibling.right -> castNotOption).color === + Red) then (sibling.color <- Red; (sibling.right -> castNotOption).color <- Black; @@ -152,5 +153,5 @@ let removeNode [arity:2]rbt node = rotateLeft rbt successorParent)))) done)); if isLeaf successor - then (if (rbt -> root) == (Some successor) then (rbt -> root) = None)) + then (if (rbt -> root) === (Some successor) then (rbt -> root) = None)) [@res.braces ]) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/infiniteLoops/expected/nonRecTypes.res.txt b/tests/syntax_tests/data/parsing/infiniteLoops/expected/nonRecTypes.res.txt index 9153cdd692..7dabe08322 100644 --- a/tests/syntax_tests/data/parsing/infiniteLoops/expected/nonRecTypes.res.txt +++ b/tests/syntax_tests/data/parsing/infiniteLoops/expected/nonRecTypes.res.txt @@ -144,7 +144,7 @@ include createNode ~value:((Js.Internal.raw_expr {js|0|js}) [@res.namedArgLoc ]) ~color:((Black)[@res.namedArgLoc ]) ~height:((0.)[@res.namedArgLoc ]) in - let isLeaf = Js.Internal.fn_mk1 (fun [arity:1]x -> x == leaf) in + let isLeaf = Js.Internal.fn_mk1 (fun [arity:1]x -> x === leaf) in (leaf, isLeaf) | Some successor -> (successor, (Js.Internal.fn_mk1 (fun [arity:1]_ -> false))) in @@ -156,12 +156,12 @@ include leftOrRightSet parent ~node:((nodeToRemove)[@res.namedArgLoc ]) (Some successor)); updateSumRecursive rbt successor; - if (colorGet nodeToRemove) == Black + if (colorGet nodeToRemove) === Black then - (if (colorGet successor) == Red + (if (colorGet successor) === Red then (colorSet successor Black; - if (parentGet successor) == None + if (parentGet successor) === None then rootSet rbt (Some successor)) else (let break = ref false in @@ -175,7 +175,7 @@ include let sibling = siblingOf successor in (if ((!==) sibling None) && - ((colorGet (castNotOption sibling)) == Red) + ((colorGet (castNotOption sibling)) === Red) then (colorSet successorParent Red; colorSet (castNotOption sibling) Black; @@ -185,35 +185,35 @@ include (let sibling = siblingOf successor in let siblingNN = castNotOption sibling in if - ((colorGet successorParent) == Black) && - ((sibling == None) || - ((((colorGet siblingNN) == Black) && - (((leftGet siblingNN) == None) || + ((colorGet successorParent) === Black) && + ((sibling === None) || + ((((colorGet siblingNN) === Black) && + (((leftGet siblingNN) === None) || ((colorGet (castNotOption (leftGet siblingNN))) - == Black))) + === Black))) && - (((rightGet siblingNN) == None) || + (((rightGet siblingNN) === None) || ((colorGet (castNotOption (rightGet siblingNN))) - == Black)))) + === Black)))) then (if (!==) sibling None then colorSet siblingNN Red; successorRef.contents <- successorParent) else if - ((colorGet successorParent) == Red) && - ((sibling == None) || - ((((colorGet siblingNN) == Black) && - (((leftGet siblingNN) == None) || + ((colorGet successorParent) === Red) && + ((sibling === None) || + ((((colorGet siblingNN) === Black) && + (((leftGet siblingNN) === None) || ((colorGet (castNotOption (leftGet siblingNN))) - == Black))) + === Black))) && - (((rightGet siblingNN) == None) || + (((rightGet siblingNN) === None) || ((colorGet (castNotOption (rightGet siblingNN))) - == Black)))) + === Black)))) then (if (!==) sibling None then colorSet siblingNN Red; colorSet successorParent Black; @@ -221,19 +221,19 @@ include else if ((!==) sibling None) && - ((colorGet (castNotOption sibling)) == Black) + ((colorGet (castNotOption sibling)) === Black) then (let sibling = castNotOption sibling in if (((isLeft successor) && - (((rightGet sibling) == None) || + (((rightGet sibling) === None) || ((colorGet (castNotOption (rightGet sibling))) - == Black))) + === Black))) && ((!==) (leftGet sibling) None)) && ((colorGet (castNotOption (leftGet sibling))) - == Red) + === Red) then (colorSet sibling Red; colorSet (castNotOption (leftGet sibling)) @@ -242,15 +242,15 @@ include else if (((not (isLeft successor)) && - (((leftGet sibling) == None) || + (((leftGet sibling) === None) || ((colorGet (castNotOption (leftGet sibling))) - == Black))) + === Black))) && ((!==) (rightGet sibling) None)) && ((colorGet (castNotOption (rightGet sibling))) - == Red) + === Red) then (colorSet sibling Red; colorSet (castNotOption (rightGet sibling)) @@ -273,7 +273,7 @@ include done)); if Js.Internal.fn_run1 isLeaf successor then - (if (rootGet rbt) == (Some successor) then rootSet rbt None; + (if (rootGet rbt) === (Some successor) then rootSet rbt None; (match parentGet successor with | None -> () | Some parent -> @@ -293,7 +293,7 @@ include | None -> None | Some node -> let cmp = Js.Internal.fn_run1 cb (valueGet node) in - if cmp == 0 + if cmp === 0 then Some node else if cmp < 0 @@ -310,7 +310,7 @@ include match node with | None -> 0. | Some n -> - if (lhs == None) && (rhs == None) + if (lhs === None) && (rhs === None) then sumGet n else if @@ -384,7 +384,7 @@ include | Some parent -> leftSpine +. (sumLeftSpine parent - ~fromRightChild:(((rightGet parent) == (Some node)) + ~fromRightChild:(((rightGet parent) === (Some node)) [@res.namedArgLoc ]))) [@res.braces ]) let getY [arity:1]node = diff --git a/tests/syntax_tests/data/parsing/other/expected/attributes.res.txt b/tests/syntax_tests/data/parsing/other/expected/attributes.res.txt index d4aa3e7c3a..44d0e2caff 100644 --- a/tests/syntax_tests/data/parsing/other/expected/attributes.res.txt +++ b/tests/syntax_tests/data/parsing/other/expected/attributes.res.txt @@ -1,6 +1,6 @@ let x = 1[@@attr :int] let x = 1[@@attr ?var] -let x = 1[@@attr ?var when x == 1] +let x = 1[@@attr ?var when x === 1] ;;[%ext :val x : int] ;;[%ext :val x : int val y : float] diff --git a/tests/syntax_tests/data/parsing/recovery/expression/expected/if.res.txt b/tests/syntax_tests/data/parsing/recovery/expression/expected/if.res.txt index 7a3e9537e8..224874dabb 100644 --- a/tests/syntax_tests/data/parsing/recovery/expression/expected/if.res.txt +++ b/tests/syntax_tests/data/parsing/recovery/expression/expected/if.res.txt @@ -16,4 +16,4 @@ Did you forget a `{` here? -;;if foo = bar then Js.log {js|if-branch|js} else Js.log {js|else-branch|js} \ No newline at end of file +;;if foo == bar then Js.log {js|if-branch|js} else Js.log {js|else-branch|js} \ No newline at end of file diff --git a/tests/tests/src/belt_list_test.res b/tests/tests/src/belt_list_test.res index 4d6f016424..3d324e0029 100644 --- a/tests/tests/src/belt_list_test.res +++ b/tests/tests/src/belt_list_test.res @@ -171,27 +171,27 @@ describe(__MODULE__, () => { test("removeAssoc", () => { let eqx = (x, y) => (x: int) == y - ok(__LOC__, N.hasAssoc(list{(1, "1"), (2, "2"), (3, "3")}, 2, \"=")) - ok(__LOC__, !N.hasAssoc(list{(1, "1"), (2, "2"), (3, "3")}, 4, \"=")) + ok(__LOC__, N.hasAssoc(list{(1, "1"), (2, "2"), (3, "3")}, 2, \"==")) + ok(__LOC__, !N.hasAssoc(list{(1, "1"), (2, "2"), (3, "3")}, 4, \"==")) ok(__LOC__, N.hasAssoc(list{(1, "1"), (2, "2"), (3, "3")}, 4, (x, y) => x + 1 == y)) eq( __LOC__, - N.removeAssoc(list{(1, "1"), (2, "2"), (3, "3")}, 3, \"="), + N.removeAssoc(list{(1, "1"), (2, "2"), (3, "3")}, 3, \"=="), list{(1, "1"), (2, "2")}, ) eq( __LOC__, - N.removeAssoc(list{(1, "1"), (2, "2"), (3, "3")}, 1, \"="), + N.removeAssoc(list{(1, "1"), (2, "2"), (3, "3")}, 1, \"=="), list{(2, "2"), (3, "3")}, ) eq( __LOC__, - N.removeAssoc(list{(1, "1"), (2, "2"), (3, "3")}, 2, \"="), + N.removeAssoc(list{(1, "1"), (2, "2"), (3, "3")}, 2, \"=="), list{(1, "1"), (3, "3")}, ) eq( __LOC__, - N.removeAssoc(list{(1, "1"), (2, "2"), (3, "3")}, 0, \"="), + N.removeAssoc(list{(1, "1"), (2, "2"), (3, "3")}, 0, \"=="), list{(1, "1"), (2, "2"), (3, "3")}, ) @@ -202,26 +202,26 @@ describe(__MODULE__, () => { let ll = list{(1, "1"), (2, "2"), (3, "3")} let ll0 = N.removeAssoc(ll, 0, eqx) ok(__LOC__, ll === ll0) - let ll1 = N.setAssoc(ll, 2, "22", \"=") + let ll1 = N.setAssoc(ll, 2, "22", \"==") eq(__LOC__, ll1, list{(1, "1"), (2, "22"), (3, "3")}) - let ll2 = N.setAssoc(ll1, 22, "2", \"=") + let ll2 = N.setAssoc(ll1, 22, "2", \"==") ok(__LOC__, ll2 == list{(22, "2"), ...ll1}) ok(__LOC__, N.tailExn(ll2) === ll1) ok( __LOC__, - N.setAssoc(list{(1, "a"), (2, "b"), (3, "c")}, 2, "x", \"=") == + N.setAssoc(list{(1, "a"), (2, "b"), (3, "c")}, 2, "x", \"==") == list{(1, "a"), (2, "x"), (3, "c")}, ) ok( __LOC__, - N.setAssoc(list{(1, "a"), (3, "c")}, 2, "2", \"=") == list{(2, "2"), (1, "a"), (3, "c")}, + N.setAssoc(list{(1, "a"), (3, "c")}, 2, "2", \"==") == list{(2, "2"), (1, "a"), (3, "c")}, ) - eq(__LOC__, N.setAssoc(list{}, 1, "1", \"="), list{(1, "1")}) - eq(__LOC__, N.setAssoc(list{(1, "2")}, 1, "1", \"="), list{(1, "1")}) + eq(__LOC__, N.setAssoc(list{}, 1, "1", \"=="), list{(1, "1")}) + eq(__LOC__, N.setAssoc(list{(1, "2")}, 1, "1", \"=="), list{(1, "1")}) - eq(__LOC__, N.setAssoc(list{(0, "0"), (1, "2")}, 1, "1", \"="), list{(0, "0"), (1, "1")}) - ok(__LOC__, N.getAssoc(list{(1, "a"), (2, "b"), (3, "c")}, 2, \"=") == Some("b")) - ok(__LOC__, N.getAssoc(list{(1, "a"), (2, "b"), (3, "c")}, 4, \"=") == None) + eq(__LOC__, N.setAssoc(list{(0, "0"), (1, "2")}, 1, "1", \"=="), list{(0, "0"), (1, "1")}) + ok(__LOC__, N.getAssoc(list{(1, "a"), (2, "b"), (3, "c")}, 2, \"==") == Some("b")) + ok(__LOC__, N.getAssoc(list{(1, "a"), (2, "b"), (3, "c")}, 4, \"==") == None) }) test("head/tail etc.", () => { @@ -344,7 +344,7 @@ describe(__MODULE__, () => { ok(__LOC__, !N.eq(list{1, 2, 3}, list{1, 2}, (x, y) => x == y)) ok(__LOC__, N.eq(list{1, 2, 3}, list{1, 2, 3}, (x, y) => x == y)) ok(__LOC__, !N.eq(list{1, 2, 3}, list{1, 2, 4}, (x, y) => x == y)) - ok(__LOC__, !N.eq(list{1, 2, 3}, list{1, 2, 3, 4}, \"=")) + ok(__LOC__, !N.eq(list{1, 2, 3}, list{1, 2, 3, 4}, \"==")) }) test("keepMap", () => { diff --git a/tests/tests/src/bigint_test.res b/tests/tests/src/bigint_test.res index ce79969d5d..1f8eef84eb 100644 --- a/tests/tests/src/bigint_test.res +++ b/tests/tests/src/bigint_test.res @@ -5,7 +5,7 @@ let approx = (loc, x, y) => Mt_global.collect_approx(test_id, suites, loc, x, y) let bigint_compare = (x: bigint, y) => Pervasives.compare(x, y) let generic_compare = Pervasives.compare let bigint_equal = (x: bigint, y) => x == y -let generic_equal = \"=" +let generic_equal = \"==" let bigint_notequal = (x: bigint, y) => x != y let generic_notequal = \"!=" let bigint_lessthan = (x: bigint, y) => x < y diff --git a/tests/tests/src/bs_array_test.res b/tests/tests/src/bs_array_test.res index 51ac45cd9d..e367311365 100644 --- a/tests/tests/src/bs_array_test.res +++ b/tests/tests/src/bs_array_test.res @@ -288,7 +288,7 @@ let () = { b(__LOC__, !A.every([0, 1, 2, 3, 4], x => x > 2)) b(__LOC__, A.some([1, 3, 7, 8], x => mod(x, 2) == 0)) b(__LOC__, !A.some([1, 3, 7], x => mod(x, 2) == 0)) - b(__LOC__, !A.eq([0, 1], [1], \"=")) + b(__LOC__, !A.eq([0, 1], [1], \"==")) b( __LOC__, { diff --git a/tests/tests/src/bs_mutable_set_test.res b/tests/tests/src/bs_mutable_set_test.res index fd2dbf5de0..7799ece7b7 100644 --- a/tests/tests/src/bs_mutable_set_test.res +++ b/tests/tests/src/bs_mutable_set_test.res @@ -96,7 +96,7 @@ include ( let ((aa, bb), pres) = N.split(v, 1000) b(__LOC__, pres) b(__LOC__, A.eq(N.toArray(aa), I.range(500, 999), (x, y) => x == y)) - b(__LOC__, A.eq(N.toArray(bb), I.range(1_001, 2_000), \"=")) + b(__LOC__, A.eq(N.toArray(bb), I.range(1_001, 2_000), \"==")) b(__LOC__, N.subset(aa, v)) b(__LOC__, N.subset(bb, v)) b(__LOC__, N.isEmpty(N.intersect(aa, bb))) @@ -104,8 +104,8 @@ include ( b(__LOC__, c) let ((aa, bb), pres) = N.split(v, 1_000) b(__LOC__, !pres) - b(__LOC__, A.eq(N.toArray(aa), I.range(500, 999), \"=")) - b(__LOC__, A.eq(N.toArray(bb), I.range(1_001, 2_000), \"=")) + b(__LOC__, A.eq(N.toArray(aa), I.range(500, 999), \"==")) + b(__LOC__, A.eq(N.toArray(bb), I.range(1_001, 2_000), \"==")) b(__LOC__, N.subset(aa, v)) b(__LOC__, N.subset(bb, v)) b(__LOC__, N.isEmpty(N.intersect(aa, bb))) @@ -216,7 +216,7 @@ let () = { let id = (loc, x) => { let u = N.fromSortedArrayUnsafe(x) N.checkInvariantInternal(u) - b(loc, A.every2(N.toArray(u), x, \"=")) + b(loc, A.every2(N.toArray(u), x, \"==")) } id(__LOC__, []) diff --git a/tests/tests/src/bs_poly_map_test.res b/tests/tests/src/bs_poly_map_test.res index 89331df4a6..41f755a63a 100644 --- a/tests/tests/src/bs_poly_map_test.res +++ b/tests/tests/src/bs_poly_map_test.res @@ -181,8 +181,8 @@ let () = { | _ => false }, ) - b(__LOC__, A.eq(M.keysToArray(v5), A.makeBy(5_000, i => i), \"=")) - b(__LOC__, A.eq(M.keysToArray(v6), A.makeBy(5_000, i => 5_001 + i), \"=")) + b(__LOC__, A.eq(M.keysToArray(v5), A.makeBy(5_000, i => i), \"==")) + b(__LOC__, A.eq(M.keysToArray(v6), A.makeBy(5_000, i => 5_001 + i), \"==")) let v7 = M.remove(v3, 5_000) let ((v8, v9), pres2) = M.split(v7, 5_000) @@ -193,8 +193,8 @@ let () = { | _ => false }, ) - b(__LOC__, A.eq(M.keysToArray(v8), A.makeBy(5_000, i => i), \"=")) - b(__LOC__, A.eq(M.keysToArray(v9), A.makeBy(5_000, i => 5_001 + i), \"=")) + b(__LOC__, A.eq(M.keysToArray(v8), A.makeBy(5_000, i => i), \"==")) + b(__LOC__, A.eq(M.keysToArray(v9), A.makeBy(5_000, i => 5_001 + i), \"==")) } Mt.from_pair_suites(__MODULE__, suites.contents) diff --git a/tests/tests/src/bs_poly_mutable_set_test.res b/tests/tests/src/bs_poly_mutable_set_test.res index d8e7e13a11..d96f876a22 100644 --- a/tests/tests/src/bs_poly_mutable_set_test.res +++ b/tests/tests/src/bs_poly_mutable_set_test.res @@ -89,8 +89,8 @@ let () = { eq(__LOC__, N.get(v, 1_200), Some(1_200)) let ((aa, bb), pres) = N.split(v, 1000) b(__LOC__, pres) - b(__LOC__, A.eq(N.toArray(aa), I.range(500, 999), \"=")) - b(__LOC__, A.eq(N.toArray(bb), I.range(1_001, 2_000), \"=")) + b(__LOC__, A.eq(N.toArray(aa), I.range(500, 999), \"==")) + b(__LOC__, A.eq(N.toArray(bb), I.range(1_001, 2_000), \"==")) b(__LOC__, N.subset(aa, v)) b(__LOC__, N.subset(bb, v)) b(__LOC__, N.isEmpty(N.intersect(aa, bb))) @@ -98,8 +98,8 @@ let () = { b(__LOC__, c) let ((aa, bb), pres) = N.split(v, 1_000) b(__LOC__, !pres) - b(__LOC__, A.eq(N.toArray(aa), I.range(500, 999), \"=")) - b(__LOC__, A.eq(N.toArray(bb), I.range(1_001, 2_000), \"=")) + b(__LOC__, A.eq(N.toArray(aa), I.range(500, 999), \"==")) + b(__LOC__, A.eq(N.toArray(bb), I.range(1_001, 2_000), \"==")) b(__LOC__, N.subset(aa, v)) b(__LOC__, N.subset(bb, v)) b(__LOC__, N.isEmpty(N.intersect(aa, bb))) diff --git a/tests/tests/src/core/Core_ErrorTests.mjs b/tests/tests/src/core/Core_ErrorTests.mjs index ce1cb6e63e..6eae577d36 100644 --- a/tests/tests/src/core/Core_ErrorTests.mjs +++ b/tests/tests/src/core/Core_ErrorTests.mjs @@ -3,6 +3,7 @@ import * as Exn from "rescript/lib/es6/Exn.js"; import * as Test from "./Test.mjs"; import * as Pervasives from "rescript/lib/es6/Pervasives.js"; +import * as Primitive_object from "rescript/lib/es6/Primitive_object.js"; import * as Primitive_exceptions from "rescript/lib/es6/Primitive_exceptions.js"; function panicTest() { @@ -25,7 +26,7 @@ function panicTest() { 43 ], "Should resolve test" - ], caught, (prim0, prim1) => prim0 === prim1, "Panic! uh oh"); + ], caught, Primitive_object.equal, "Panic! uh oh"); } panicTest(); diff --git a/tests/tests/src/float_test.res b/tests/tests/src/float_test.res index 8078fb2731..8802321393 100644 --- a/tests/tests/src/float_test.res +++ b/tests/tests/src/float_test.res @@ -12,7 +12,7 @@ let from_pairs = ps => let float_compare = (x: float, y) => Pervasives.compare(x, y) let generic_compare = Pervasives.compare let float_equal = (x: float, y) => x == y -let generic_equal = \"=" +let generic_equal = \"==" let float_notequal = (x: float, y) => x != y let generic_notequal = \"!=" let float_lessthan = (x: float, y) => x < y diff --git a/tests/tests/src/gpr_2487.res b/tests/tests/src/gpr_2487.res index 8a2763c427..6cb3b8be39 100644 --- a/tests/tests/src/gpr_2487.res +++ b/tests/tests/src/gpr_2487.res @@ -1,3 +1,3 @@ module A = Belt.Array -let b = A.eq([1, 2, 3], [1, 2, 3], \"=") +let b = A.eq([1, 2, 3], [1, 2, 3], \"==") diff --git a/tests/tests/src/variant.res b/tests/tests/src/variant.res index ece2b81624..5b4aaab9d7 100644 --- a/tests/tests/src/variant.res +++ b/tests/tests/src/variant.res @@ -45,7 +45,7 @@ module Path = { | Pident(string) | Pdot(t, string, int) | Papply(t, t) - let same = \"=" + let same = \"==" let compare = compare } diff --git a/tests/tools_tests/ppx/TestPpx.res b/tests/tools_tests/ppx/TestPpx.res index 83c6522430..2d09f3483a 100644 --- a/tests/tools_tests/ppx/TestPpx.res +++ b/tests/tools_tests/ppx/TestPpx.res @@ -54,4 +54,7 @@ module Pipe = { let concat = "a" ++ "b" let neq = 3 != 3 -let neq2 = 3 !== 3 \ No newline at end of file +let neq2 = 3 !== 3 + +let eq = 3 == 3 +let eq2 = 3 === 3 diff --git a/tests/tools_tests/src/expected/TestPpx.res.jsout b/tests/tools_tests/src/expected/TestPpx.res.jsout index 854a6e4ffe..6e0f326e86 100644 --- a/tests/tools_tests/src/expected/TestPpx.res.jsout +++ b/tests/tools_tests/src/expected/TestPpx.res.jsout @@ -82,6 +82,10 @@ let neq = false; let neq2 = false; +let eq = true; + +let eq2 = true; + exports.a = a; exports.b = b; exports.M = M; @@ -98,4 +102,6 @@ exports.Pipe = Pipe; exports.concat = concat; exports.neq = neq; exports.neq2 = neq2; +exports.eq = eq; +exports.eq2 = eq2; /* Not a pure module */ From 3000fd4ef0447c02fac66e69748444202e124f6f Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Tue, 14 Jan 2025 14:33:57 +0100 Subject: [PATCH 4/6] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba8844623c..2b6dd4dde9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ - AST cleanup: Remove `@res.partial` attribute from the internal representation, and add a flag to untyped and typed ASTs instead. https://github.com/rescript-lang/rescript/pull/7238 https://github.com/rescript-lang/rescript/pull/7240 - AST cleanup: Remove `structure_item_desc.Pstr_class`, `signature_item_desc.Psig_class`, `structure_item_desc.Pstr_class_type`, `signature_item_desc.Psig_class_type`, `structure_item_desc.Tstr_class`, `structure_item_desc.Tstr_class_type`, `signature_item_desc.Tsig_class`, `signature_item_desc.Tsig_class_type` from AST as it is unused. https://github.com/rescript-lang/rescript/pull/7242 - AST cleanup: remove "|." and rename "|." to "->" in the internal representation for the pipe operator. https://github.com/rescript-lang/rescript/pull/7244 +- AST cleanup: represent concatenation (`++`) and (dis)equality operators (`==`, `===`, `!=`, `!==`) just like in the syntax. https://github.com/rescript-lang/rescript/pull/7248 # 12.0.0-alpha.7 From 68a9bb4ae864484c00fb90299a4611d1137a3063 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Wed, 15 Jan 2025 10:59:14 +0100 Subject: [PATCH 5/6] Adapt core error test. --- tests/tests/src/core/Core_ErrorTests.mjs | 3 +-- tests/tests/src/core/Core_ErrorTests.res | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/tests/src/core/Core_ErrorTests.mjs b/tests/tests/src/core/Core_ErrorTests.mjs index 6eae577d36..ce1cb6e63e 100644 --- a/tests/tests/src/core/Core_ErrorTests.mjs +++ b/tests/tests/src/core/Core_ErrorTests.mjs @@ -3,7 +3,6 @@ import * as Exn from "rescript/lib/es6/Exn.js"; import * as Test from "./Test.mjs"; import * as Pervasives from "rescript/lib/es6/Pervasives.js"; -import * as Primitive_object from "rescript/lib/es6/Primitive_object.js"; import * as Primitive_exceptions from "rescript/lib/es6/Primitive_exceptions.js"; function panicTest() { @@ -26,7 +25,7 @@ function panicTest() { 43 ], "Should resolve test" - ], caught, Primitive_object.equal, "Panic! uh oh"); + ], caught, (prim0, prim1) => prim0 === prim1, "Panic! uh oh"); } panicTest(); diff --git a/tests/tests/src/core/Core_ErrorTests.res b/tests/tests/src/core/Core_ErrorTests.res index 3113346495..2595d88768 100644 --- a/tests/tests/src/core/Core_ErrorTests.res +++ b/tests/tests/src/core/Core_ErrorTests.res @@ -3,7 +3,7 @@ let panicTest = () => { | Exn.Error(err) => Error.message(err) } - Test.run(__POS_OF__("Should resolve test"), caught, \"==", Some("Panic! uh oh")) + Test.run(__POS_OF__("Should resolve test"), caught, \"===", Some("Panic! uh oh")) } panicTest() From 14eb6e10a8021a8a2b4ad58f43e1396729c96429 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Wed, 15 Jan 2025 11:15:17 +0100 Subject: [PATCH 6/6] Add error case for string concatenation. --- compiler/ml/error_message_utils.ml | 1 + .../build_tests/super_errors/expected/primitives2.res.expected | 2 +- .../super_errors/expected/unicode_location.res.expected | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler/ml/error_message_utils.ml b/compiler/ml/error_message_utils.ml index d565e7430a..1fa8fe7256 100644 --- a/compiler/ml/error_message_utils.ml +++ b/compiler/ml/error_message_utils.ml @@ -55,6 +55,7 @@ let error_expected_type_text ppf type_clash_context = operator | Some FunctionReturn -> fprintf ppf "But this function is expecting you to return:" + | Some StringConcat -> fprintf ppf "But string concatenation is expecting:" | _ -> fprintf ppf "But it's expected to have type:" let is_record_type ~extract_concrete_typedecl ~env ty = diff --git a/tests/build_tests/super_errors/expected/primitives2.res.expected b/tests/build_tests/super_errors/expected/primitives2.res.expected index d2f30716a2..29b554f51e 100644 --- a/tests/build_tests/super_errors/expected/primitives2.res.expected +++ b/tests/build_tests/super_errors/expected/primitives2.res.expected @@ -7,6 +7,6 @@ 3 │ This has type: int - But it's expected to have type: string + But string concatenation is expecting: string You can convert int to string with Belt.Int.toString. \ No newline at end of file diff --git a/tests/build_tests/super_errors/expected/unicode_location.res.expected b/tests/build_tests/super_errors/expected/unicode_location.res.expected index 55655bd54a..e14d1c9d76 100644 --- a/tests/build_tests/super_errors/expected/unicode_location.res.expected +++ b/tests/build_tests/super_errors/expected/unicode_location.res.expected @@ -8,6 +8,6 @@ 3 │ This has type: int - But it's expected to have type: string + But string concatenation is expecting: string You can convert int to string with Belt.Int.toString. \ No newline at end of file