From 835efe4ab799f4f0e44699a4f6aeca5ea31b00bb Mon Sep 17 00:00:00 2001 From: aspeddro Date: Mon, 17 Mar 2025 10:12:56 -0300 Subject: [PATCH 01/15] Add `throw` Deprecate `raise` and rename references --- lib/es6/Stdlib.js | 7 ++++++- lib/js/Stdlib.js | 7 ++++++- runtime/Belt_List.res | 8 ++++---- runtime/Belt_MutableQueue.res | 4 ++-- runtime/Belt_Option.res | 2 +- runtime/Belt_Result.res | 2 +- runtime/Belt_internalAVLset.res | 2 +- runtime/Belt_internalAVLtree.res | 2 +- runtime/Belt_internalMapInt.res | 2 +- runtime/Belt_internalMapString.res | 2 +- runtime/Belt_internalSetInt.res | 2 +- runtime/Belt_internalSetString.res | 2 +- runtime/Pervasives.res | 6 +++--- runtime/Pervasives_mini.res | 1 + runtime/Primitive_array.res | 4 ++-- runtime/Primitive_bigint.res | 4 ++-- runtime/Primitive_int.res | 4 ++-- runtime/Primitive_lazy.res | 6 +++--- runtime/Primitive_module.res | 2 +- runtime/Primitive_object.res | 4 ++-- runtime/Primitive_string.res | 2 +- runtime/Primitive_util.res | 2 +- runtime/Stdlib.res | 1 + runtime/Stdlib_Error.res | 2 ++ runtime/Stdlib_Error.resi | 18 ++++++++++++++++++ runtime/Stdlib_Exn.res | 14 +++++++------- runtime/Stdlib_Int.res | 2 +- runtime/Stdlib_List.res | 8 ++++---- runtime/Stdlib_Null.res | 2 +- runtime/Stdlib_Nullable.res | 2 +- runtime/Stdlib_Result.res | 2 +- .../src/expected/CompletionExpressions.res.txt | 6 ++++++ .../CompletionFunctionArguments.res.txt | 12 ++++++++++++ .../src/expected/CompletionJsxProps.res.txt | 12 ++++++++++++ .../typescript-react-example/package-lock.json | 1 + 35 files changed, 111 insertions(+), 48 deletions(-) diff --git a/lib/es6/Stdlib.js b/lib/es6/Stdlib.js index 39bdaf88ea..630225be34 100644 --- a/lib/es6/Stdlib.js +++ b/lib/es6/Stdlib.js @@ -3,6 +3,10 @@ import * as Stdlib_Error from "./Stdlib_Error.js"; import * as Primitive_object from "./Primitive_object.js"; +function $$throw(prim) { + throw prim; +} + function assertEqual(a, b) { if (!Primitive_object.notequal(a, b)) { return; @@ -11,7 +15,7 @@ function assertEqual(a, b) { RE_EXN_ID: "Assert_failure", _1: [ "Stdlib.res", - 117, + 118, 4 ], Error: new Error() @@ -154,6 +158,7 @@ export { $$BigInt64Array, $$BigUint64Array, panic, + $$throw, assertEqual, } /* No side effect */ diff --git a/lib/js/Stdlib.js b/lib/js/Stdlib.js index 4ac16823db..cef1461217 100644 --- a/lib/js/Stdlib.js +++ b/lib/js/Stdlib.js @@ -3,6 +3,10 @@ let Stdlib_Error = require("./Stdlib_Error.js"); let Primitive_object = require("./Primitive_object.js"); +function $$throw(prim) { + throw prim; +} + function assertEqual(a, b) { if (!Primitive_object.notequal(a, b)) { return; @@ -11,7 +15,7 @@ function assertEqual(a, b) { RE_EXN_ID: "Assert_failure", _1: [ "Stdlib.res", - 117, + 118, 4 ], Error: new Error() @@ -153,5 +157,6 @@ exports.$$Uint8ClampedArray = $$Uint8ClampedArray; exports.$$BigInt64Array = $$BigInt64Array; exports.$$BigUint64Array = $$BigUint64Array; exports.panic = panic; +exports.$$throw = $$throw; exports.assertEqual = assertEqual; /* No side effect */ diff --git a/runtime/Belt_List.res b/runtime/Belt_List.res index cf00c5611e..b282a596ac 100644 --- a/runtime/Belt_List.res +++ b/runtime/Belt_List.res @@ -88,7 +88,7 @@ let head = x => let headExn = x => switch x { - | list{} => raise(Not_found) + | list{} => throw(Not_found) | list{x, ..._} => x } @@ -100,7 +100,7 @@ let tail = x => let tailExn = x => switch x { - | list{} => raise(Not_found) + | list{} => throw(Not_found) | list{_, ...t} => t } @@ -126,7 +126,7 @@ let rec nthAuxAssert = (x, n) => } else { nthAuxAssert(t, n - 1) } - | _ => raise(Not_found) + | _ => throw(Not_found) } let get = (x, n) => @@ -138,7 +138,7 @@ let get = (x, n) => let getExn = (x, n) => if n < 0 { - raise(Not_found) + throw(Not_found) } else { nthAuxAssert(x, n) } diff --git a/runtime/Belt_MutableQueue.res b/runtime/Belt_MutableQueue.res index 855fc03bf2..40d39c319d 100644 --- a/runtime/Belt_MutableQueue.res +++ b/runtime/Belt_MutableQueue.res @@ -72,7 +72,7 @@ let peekUndefined = q => let peekExn = q => switch q.first { - | None => raise(Not_found) + | None => throw(Not_found) | Some(v) => v.content } @@ -95,7 +95,7 @@ let pop = q => let popExn = q => /* TO fix */ switch q.first { - | None => raise(Not_found) + | None => throw(Not_found) | Some(x) => let next = x.next if next == None { diff --git a/runtime/Belt_Option.res b/runtime/Belt_Option.res index 3d6b18ff5a..cd2f7e0596 100644 --- a/runtime/Belt_Option.res +++ b/runtime/Belt_Option.res @@ -37,7 +37,7 @@ let forEach = (opt, f) => let getExn = x => switch x { | Some(x) => x - | None => raise(Not_found) + | None => throw(Not_found) } external getUnsafe: option<'a> => 'a = "%identity" diff --git a/runtime/Belt_Result.res b/runtime/Belt_Result.res index a6ded4bff6..d85948a96d 100644 --- a/runtime/Belt_Result.res +++ b/runtime/Belt_Result.res @@ -29,7 +29,7 @@ type t<'a, 'b> = result<'a, 'b> = let getExn = x => switch x { | Ok(x) => x - | Error(_) => raise(Not_found) + | Error(_) => throw(Not_found) } let mapWithDefault = (opt, default, f) => diff --git a/runtime/Belt_internalAVLset.res b/runtime/Belt_internalAVLset.res index 422e30b9db..46954fd095 100644 --- a/runtime/Belt_internalAVLset.res +++ b/runtime/Belt_internalAVLset.res @@ -590,7 +590,7 @@ let rec getUndefined = (n: t<_>, x, ~cmp) => let rec getExn = (n: t<_>, x, ~cmp) => switch n { - | None => raise(Not_found) + | None => throw(Not_found) | Some(t) /* Node(l, v, r, _) */ => let v = t.value let c = Belt_Id.getCmpInternal(cmp)(x, v) diff --git a/runtime/Belt_internalAVLtree.res b/runtime/Belt_internalAVLtree.res index e47c211d41..cdb0dc67f0 100644 --- a/runtime/Belt_internalAVLtree.res +++ b/runtime/Belt_internalAVLtree.res @@ -713,7 +713,7 @@ let rec getUndefined = (n, x, ~cmp) => let rec getExn = (n, x, ~cmp) => switch n { - | None => raise(Not_found) + | None => throw(Not_found) | Some(n) /* Node(l, v, d, r, _) */ => let v = n.key let c = Belt_Id.getCmpInternal(cmp)(x, v) diff --git a/runtime/Belt_internalMapInt.res b/runtime/Belt_internalMapInt.res index f60cbd9b24..f51cef9417 100644 --- a/runtime/Belt_internalMapInt.res +++ b/runtime/Belt_internalMapInt.res @@ -65,7 +65,7 @@ let rec getUndefined = (n, x: key) => let rec getExn = (n, x: key) => switch n { - | None => raise(Not_found) + | None => throw(Not_found) | Some(n) => let v = n.N.key if x == v { diff --git a/runtime/Belt_internalMapString.res b/runtime/Belt_internalMapString.res index 4ac6c00535..1fd5f024e2 100644 --- a/runtime/Belt_internalMapString.res +++ b/runtime/Belt_internalMapString.res @@ -65,7 +65,7 @@ let rec getUndefined = (n, x: key) => let rec getExn = (n, x: key) => switch n { - | None => raise(Not_found) + | None => throw(Not_found) | Some(n) => let v = n.N.key if x == v { diff --git a/runtime/Belt_internalSetInt.res b/runtime/Belt_internalSetInt.res index 676e955778..6831794d34 100644 --- a/runtime/Belt_internalSetInt.res +++ b/runtime/Belt_internalSetInt.res @@ -106,7 +106,7 @@ let rec getUndefined = (n: t, x: value) => let rec getExn = (n: t, x: value) => switch n { - | None => raise(Not_found) + | None => throw(Not_found) | Some(t) => let v = t.value if x == v { diff --git a/runtime/Belt_internalSetString.res b/runtime/Belt_internalSetString.res index ef38792cc8..3983818d48 100644 --- a/runtime/Belt_internalSetString.res +++ b/runtime/Belt_internalSetString.res @@ -106,7 +106,7 @@ let rec getUndefined = (n: t, x: value) => let rec getExn = (n: t, x: value) => switch n { - | None => raise(Not_found) + | None => throw(Not_found) | Some(t) => let v = t.value if x == v { diff --git a/runtime/Pervasives.res b/runtime/Pervasives.res index d657dd782f..bb5810cf55 100644 --- a/runtime/Pervasives.res +++ b/runtime/Pervasives.res @@ -1,6 +1,6 @@ /** Since [others] depend on this file, its public mli files **should not - export types** introduced here, otherwise it would cause + export types** introduced here, otherwise it would cause conflicts here. If the type exported here is also exported in modules from others, @@ -16,10 +16,10 @@ __unsafe_cast: 'a => 'b = "%identity" external raise: exn => 'a = "%raise" @deprecated("Use custom exception instead") -let failwith = s => raise(Failure(s)) +let failwith = s => throw(Failure(s)) @deprecated("Use custom exception instead") -let invalid_arg = s => raise(Invalid_argument(s)) +let invalid_arg = s => throw(Invalid_argument(s)) @deprecated("Use custom exception instead") exception Exit diff --git a/runtime/Pervasives_mini.res b/runtime/Pervasives_mini.res index 7049284417..f9f0f21a05 100644 --- a/runtime/Pervasives_mini.res +++ b/runtime/Pervasives_mini.res @@ -1,5 +1,6 @@ /* Exceptions */ external raise: exn => 'a = "%raise" +external throw: exn => 'a = "%raise" /* Debugging */ diff --git a/runtime/Primitive_array.res b/runtime/Primitive_array.res index b521bd1e4c..6a7d994d4d 100644 --- a/runtime/Primitive_array.res +++ b/runtime/Primitive_array.res @@ -2,14 +2,14 @@ let length = Primitive_array_extern.length let get = (xs, index) => if index < 0 || index >= length(xs) { - raise(Invalid_argument("index out of bounds")) + throw(Invalid_argument("index out of bounds")) } else { xs->Primitive_array_extern.getUnsafe(index) } let set = (xs, index, newval) => if index < 0 || index >= length(xs) { - raise(Invalid_argument("index out of bounds")) + throw(Invalid_argument("index out of bounds")) } else { xs->Primitive_array_extern.setUnsafe(index, newval) } diff --git a/runtime/Primitive_bigint.res b/runtime/Primitive_bigint.res index cb576a9357..8f34ecb4c2 100644 --- a/runtime/Primitive_bigint.res +++ b/runtime/Primitive_bigint.res @@ -25,7 +25,7 @@ external div: (bigint, bigint) => bigint = "%divbigint" let div = (x: bigint, y: bigint) => if y == 0n { - raise(Division_by_zero) + throw(Division_by_zero) } else { div(x, y) } @@ -34,7 +34,7 @@ external mod_: (bigint, bigint) => bigint = "%modbigint" let mod_ = (x: bigint, y: bigint) => if y == 0n { - raise(Division_by_zero) + throw(Division_by_zero) } else { mod_(x, y) } diff --git a/runtime/Primitive_int.res b/runtime/Primitive_int.res index 25afa896ee..ce5c4abe0b 100644 --- a/runtime/Primitive_int.res +++ b/runtime/Primitive_int.res @@ -23,14 +23,14 @@ let max = (x: int, y: int): int => let div = (x: int, y: int) => if y == 0 { - raise(Division_by_zero) + throw(Division_by_zero) } else { Primitive_int_extern.div(x, y) } let mod_ = (x: int, y: int) => if y == 0 { - raise(Division_by_zero) + throw(Division_by_zero) } else { Primitive_int_extern.mod_(x, y) } diff --git a/runtime/Primitive_lazy.res b/runtime/Primitive_lazy.res index 9fb7a4f643..f77595bb1f 100644 --- a/runtime/Primitive_lazy.res +++ b/runtime/Primitive_lazy.res @@ -50,7 +50,7 @@ exception Undefined } ) -%%private(let raise_undefined = () => raise(Undefined)) +%%private(let raise_undefined = () => throw(Undefined)) /* Assume [blk] is a block with tag lazy */ %%private( @@ -59,8 +59,8 @@ exception Undefined blk.value = fnToVal(raise_undefined) try forward_with_closure(blk, closure) catch { | e => - blk.value = fnToVal(() => raise(e)) - raise(e) + blk.value = fnToVal(() => throw(e)) + throw(e) } } ) diff --git a/runtime/Primitive_module.res b/runtime/Primitive_module.res index c71f1c6ab8..7a6b7ef57c 100644 --- a/runtime/Primitive_module.res +++ b/runtime/Primitive_module.res @@ -19,7 +19,7 @@ module type Empty = {} in the lambda layer */ let init = (loc: (string, int, int), shape: shape) => { - let undef_module = _ => raise(Undefined_recursive_module(loc)) + let undef_module = _ => throw(Undefined_recursive_module(loc)) let rec loop = (shape: shape, struct_: Obj.t, idx) => switch shape { | Function => Obj.setField(struct_, idx, Obj.magic(undef_module)) diff --git a/runtime/Primitive_object.res b/runtime/Primitive_object.res index 62fdfa743b..cb976d3f2b 100644 --- a/runtime/Primitive_object.res +++ b/runtime/Primitive_object.res @@ -94,7 +94,7 @@ let rec compare = (a: t, b: t): int => | ("boolean", "boolean") => Pervasives.compare((magic(a): bool), magic(b)) | ("boolean", _) => 1 | (_, "boolean") => -1 - | ("function", "function") => raise(Invalid_argument("compare: functional value")) + | ("function", "function") => throw(Invalid_argument("compare: functional value")) | ("function", _) => 1 | (_, "function") => -1 | ("bigint", "bigint") @@ -261,7 +261,7 @@ let rec equal = (a: t, b: t): bool => } else { let b_type = Js.typeof(b) if a_type == "function" || b_type == "function" { - raise(Invalid_argument("equal: functional value")) + throw(Invalid_argument("equal: functional value")) } /* first, check using reference equality */ else if ( /* a_type = "object" || "symbol" */ diff --git a/runtime/Primitive_string.res b/runtime/Primitive_string.res index fe6c2b127b..4a07228a02 100644 --- a/runtime/Primitive_string.res +++ b/runtime/Primitive_string.res @@ -23,7 +23,7 @@ let max = (x: string, y: string): string => let getChar = (s, i) => if i >= Primitive_string_extern.length(s) || i < 0 { - raise(Invalid_argument("index out of bounds")) + throw(Invalid_argument("index out of bounds")) } else { Primitive_string_extern.getChar(s, i) } diff --git a/runtime/Primitive_util.res b/runtime/Primitive_util.res index 1b4cb015b9..f2a5bd7e5c 100644 --- a/runtime/Primitive_util.res +++ b/runtime/Primitive_util.res @@ -2,7 +2,7 @@ module Js = Primitive_js_extern let raiseWhenNotFound = x => if Js.testAny(x) { - raise(Not_found) + throw(Not_found) } else { x } diff --git a/runtime/Stdlib.res b/runtime/Stdlib.res index 743a4a651c..990c8cc1f3 100644 --- a/runtime/Stdlib.res +++ b/runtime/Stdlib.res @@ -100,6 +100,7 @@ async function main() { external import: 'a => promise<'a> = "%import" let panic = Error.panic +let throw = Error.throw /** `assertEqual(a, b)` check if `a` is equal `b`. If not raise a panic exception diff --git a/runtime/Stdlib_Error.res b/runtime/Stdlib_Error.res index 558a1bbb60..c93f289cb7 100644 --- a/runtime/Stdlib_Error.res +++ b/runtime/Stdlib_Error.res @@ -40,4 +40,6 @@ module URIError = { external raise: t => 'a = "%raise" +external throw: t => 'a = "%raise" + let panic = msg => make(`Panic! ${msg}`)->raise diff --git a/runtime/Stdlib_Error.resi b/runtime/Stdlib_Error.resi index b8bf3a5585..e9c08f8e8e 100644 --- a/runtime/Stdlib_Error.resi +++ b/runtime/Stdlib_Error.resi @@ -155,8 +155,26 @@ if 5 > 10 { } ``` */ +@deprecated("Use `Error.throw` instead.") external raise: t => 'a = "%raise" +/** +Throw and exception provided `Error.t`, which will stop execution. + +## Examples + +```rescript +let error = Error.make("Everything is upside down.") + +if 5 > 10 { + error->Error.throw +} else { + Console.log("Phew, sanity still rules.") +} +``` +*/ +external throw: t => 'a = "%raise" + /** Raises a panic exception with the given message. diff --git a/runtime/Stdlib_Exn.res b/runtime/Stdlib_Exn.res index 1a7f7da952..3721cb9007 100644 --- a/runtime/Stdlib_Exn.res +++ b/runtime/Stdlib_Exn.res @@ -43,38 +43,38 @@ type error external anyToExnInternal: 'a => exn = "%wrap_exn" -let raiseError = str => raise((Obj.magic((makeError(str): error)): exn)) +let raiseError = str => throw((Obj.magic((makeError(str): error)): exn)) type eval_error @new external makeEvalError: string => eval_error = "EvalError" -let raiseEvalError = str => raise((Obj.magic((makeEvalError(str): eval_error)): exn)) +let raiseEvalError = str => throw((Obj.magic((makeEvalError(str): eval_error)): exn)) type range_error @new external makeRangeError: string => range_error = "RangeError" -let raiseRangeError = str => raise((Obj.magic((makeRangeError(str): range_error)): exn)) +let raiseRangeError = str => throw((Obj.magic((makeRangeError(str): range_error)): exn)) type reference_error @new external makeReferenceError: string => reference_error = "ReferenceError" -let raiseReferenceError = str => raise(Obj.magic(makeReferenceError(str))) +let raiseReferenceError = str => throw(Obj.magic(makeReferenceError(str))) type syntax_error @new external makeSyntaxError: string => syntax_error = "SyntaxError" -let raiseSyntaxError = str => raise(Obj.magic(makeSyntaxError(str))) +let raiseSyntaxError = str => throw(Obj.magic(makeSyntaxError(str))) type type_error @new external makeTypeError: string => type_error = "TypeError" -let raiseTypeError = str => raise(Obj.magic(makeTypeError(str))) +let raiseTypeError = str => throw(Obj.magic(makeTypeError(str))) type uri_error @new external makeURIError: string => uri_error = "URIError" -let raiseUriError = str => raise(Obj.magic(makeURIError(str))) +let raiseUriError = str => throw(Obj.magic(makeURIError(str))) /* TODO add predicate to tell which error is which " */ diff --git a/runtime/Stdlib_Int.res b/runtime/Stdlib_Int.res index 569c038f44..002105144b 100644 --- a/runtime/Stdlib_Int.res +++ b/runtime/Stdlib_Int.res @@ -64,7 +64,7 @@ let range = (start, end, ~options: rangeOptions={}) => { let step = switch options.step { | None => isInverted ? -1 : 1 | Some(0) if start !== end => - Stdlib_Error.raise(Stdlib_Error.RangeError.make("Incorrect range arguments")) + Stdlib_Error.throw(Stdlib_Error.RangeError.make("Incorrect range arguments")) | Some(n) => n } diff --git a/runtime/Stdlib_List.res b/runtime/Stdlib_List.res index a4004f4b6e..d1ef998db5 100644 --- a/runtime/Stdlib_List.res +++ b/runtime/Stdlib_List.res @@ -108,7 +108,7 @@ let head = x => let headExn = x => switch x { - | list{} => raise(Not_found) + | list{} => throw(Not_found) | list{x, ..._} => x } @@ -120,7 +120,7 @@ let tail = x => let tailExn = x => switch x { - | list{} => raise(Not_found) + | list{} => throw(Not_found) | list{_, ...t} => t } @@ -146,7 +146,7 @@ let rec nthAuxAssert = (x, n) => } else { nthAuxAssert(t, n - 1) } - | _ => raise(Not_found) + | _ => throw(Not_found) } let get = (x, n) => @@ -158,7 +158,7 @@ let get = (x, n) => let getExn = (x, n) => if n < 0 { - raise(Not_found) + throw(Not_found) } else { nthAuxAssert(x, n) } diff --git a/runtime/Stdlib_Null.res b/runtime/Stdlib_Null.res index 8ebc877df7..ebb4b6f7d8 100644 --- a/runtime/Stdlib_Null.res +++ b/runtime/Stdlib_Null.res @@ -32,7 +32,7 @@ let getWithDefault = getOr let getExn: t<'a> => 'a = value => switch value->toOption { | Some(x) => x - | None => raise(Invalid_argument("Null.getExn: value is null")) + | None => throw(Invalid_argument("Null.getExn: value is null")) } external getUnsafe: t<'a> => 'a = "%identity" diff --git a/runtime/Stdlib_Nullable.res b/runtime/Stdlib_Nullable.res index 4d394cf5bb..9b841059f2 100644 --- a/runtime/Stdlib_Nullable.res +++ b/runtime/Stdlib_Nullable.res @@ -35,7 +35,7 @@ let getWithDefault = getOr let getExn: t<'a> => 'a = value => switch value->toOption { | Some(x) => x - | None => raise(Invalid_argument("Nullable.getExn: value is null or undefined")) + | None => throw(Invalid_argument("Nullable.getExn: value is null or undefined")) } external getUnsafe: t<'a> => 'a = "%identity" diff --git a/runtime/Stdlib_Result.res b/runtime/Stdlib_Result.res index 0c37cfabad..ae5e7c7ee6 100644 --- a/runtime/Stdlib_Result.res +++ b/runtime/Stdlib_Result.res @@ -26,7 +26,7 @@ type t<'res, 'err> = result<'res, 'err> = Ok('res) | Error('err) let getExn = x => switch x { | Ok(x) => x - | Error(_) => raise(Not_found) + | Error(_) => throw(Not_found) } let mapOr = (opt, default, f) => diff --git a/tests/analysis_tests/tests/src/expected/CompletionExpressions.res.txt b/tests/analysis_tests/tests/src/expected/CompletionExpressions.res.txt index 057b6130d6..8a96cc3233 100644 --- a/tests/analysis_tests/tests/src/expected/CompletionExpressions.res.txt +++ b/tests/analysis_tests/tests/src/expected/CompletionExpressions.res.txt @@ -369,6 +369,12 @@ Path fnTakingRecord "detail": "bool", "documentation": null, "sortText": "A true" + }, { + "label": "throw", + "kind": 12, + "tags": [], + "detail": "Error.t => 'a", + "documentation": null }, { "label": "typeof", "kind": 12, diff --git a/tests/analysis_tests/tests/src/expected/CompletionFunctionArguments.res.txt b/tests/analysis_tests/tests/src/expected/CompletionFunctionArguments.res.txt index ae28106430..3bf6491f95 100644 --- a/tests/analysis_tests/tests/src/expected/CompletionFunctionArguments.res.txt +++ b/tests/analysis_tests/tests/src/expected/CompletionFunctionArguments.res.txt @@ -43,6 +43,12 @@ Path someFn "tags": [], "detail": "bool", "documentation": null + }, { + "label": "throw", + "kind": 12, + "tags": [], + "detail": "Error.t => 'a", + "documentation": null }, { "label": "typeof", "kind": 12, @@ -367,6 +373,12 @@ Path someOtherFn "tags": [], "detail": "bool", "documentation": null + }, { + "label": "throw", + "kind": 12, + "tags": [], + "detail": "Error.t => 'a", + "documentation": null }, { "label": "typeof", "kind": 12, diff --git a/tests/analysis_tests/tests/src/expected/CompletionJsxProps.res.txt b/tests/analysis_tests/tests/src/expected/CompletionJsxProps.res.txt index 11d4780017..4970f4df88 100644 --- a/tests/analysis_tests/tests/src/expected/CompletionJsxProps.res.txt +++ b/tests/analysis_tests/tests/src/expected/CompletionJsxProps.res.txt @@ -35,6 +35,12 @@ Path CompletionSupport.TestComponent.make "detail": "bool", "documentation": null, "sortText": "A true" + }, { + "label": "throw", + "kind": 12, + "tags": [], + "detail": "Error.t => 'a", + "documentation": null }, { "label": "typeof", "kind": 12, @@ -367,6 +373,12 @@ Path CompletionSupport.TestComponent.make "tags": [], "detail": "[> #two]", "documentation": null + }, { + "label": "throw", + "kind": 12, + "tags": [], + "detail": "Error.t => 'a", + "documentation": null }, { "label": "typeof", "kind": 12, diff --git a/tests/gentype_tests/typescript-react-example/package-lock.json b/tests/gentype_tests/typescript-react-example/package-lock.json index 8b0560ac74..3c4be344a0 100644 --- a/tests/gentype_tests/typescript-react-example/package-lock.json +++ b/tests/gentype_tests/typescript-react-example/package-lock.json @@ -21,6 +21,7 @@ } }, "../../..": { + "name": "rescript", "version": "12.0.0-alpha.10", "dev": true, "hasInstallScript": true, From 0061043bb3bebd392cb2bcc9c31a0c523b04a909 Mon Sep 17 00:00:00 2001 From: aspeddro Date: Tue, 18 Mar 2025 13:19:55 -0300 Subject: [PATCH 02/15] remove raise from Pervasives_mini.res --- runtime/Pervasives_mini.res | 1 - 1 file changed, 1 deletion(-) diff --git a/runtime/Pervasives_mini.res b/runtime/Pervasives_mini.res index f9f0f21a05..1954949eaf 100644 --- a/runtime/Pervasives_mini.res +++ b/runtime/Pervasives_mini.res @@ -1,5 +1,4 @@ /* Exceptions */ -external raise: exn => 'a = "%raise" external throw: exn => 'a = "%raise" /* Debugging */ From 54a06c90013a8b45088a5c94d9b0e40fb8e8a644 Mon Sep 17 00:00:00 2001 From: aspeddro Date: Wed, 19 Mar 2025 13:00:05 -0300 Subject: [PATCH 03/15] convert to external and add deprecated attr --- lib/es6/Stdlib.js | 7 +------ lib/js/Stdlib.js | 7 +------ runtime/Pervasives.res | 4 +++- runtime/Stdlib.res | 18 +++++++++++++++++- runtime/Stdlib_Error.resi | 4 +++- 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/lib/es6/Stdlib.js b/lib/es6/Stdlib.js index 630225be34..d66a21ff5c 100644 --- a/lib/es6/Stdlib.js +++ b/lib/es6/Stdlib.js @@ -3,10 +3,6 @@ import * as Stdlib_Error from "./Stdlib_Error.js"; import * as Primitive_object from "./Primitive_object.js"; -function $$throw(prim) { - throw prim; -} - function assertEqual(a, b) { if (!Primitive_object.notequal(a, b)) { return; @@ -15,7 +11,7 @@ function assertEqual(a, b) { RE_EXN_ID: "Assert_failure", _1: [ "Stdlib.res", - 118, + 134, 4 ], Error: new Error() @@ -158,7 +154,6 @@ export { $$BigInt64Array, $$BigUint64Array, panic, - $$throw, assertEqual, } /* No side effect */ diff --git a/lib/js/Stdlib.js b/lib/js/Stdlib.js index cef1461217..ea221f16b3 100644 --- a/lib/js/Stdlib.js +++ b/lib/js/Stdlib.js @@ -3,10 +3,6 @@ let Stdlib_Error = require("./Stdlib_Error.js"); let Primitive_object = require("./Primitive_object.js"); -function $$throw(prim) { - throw prim; -} - function assertEqual(a, b) { if (!Primitive_object.notequal(a, b)) { return; @@ -15,7 +11,7 @@ function assertEqual(a, b) { RE_EXN_ID: "Assert_failure", _1: [ "Stdlib.res", - 118, + 134, 4 ], Error: new Error() @@ -157,6 +153,5 @@ exports.$$Uint8ClampedArray = $$Uint8ClampedArray; exports.$$BigInt64Array = $$BigInt64Array; exports.$$BigUint64Array = $$BigUint64Array; exports.panic = panic; -exports.$$throw = $$throw; exports.assertEqual = assertEqual; /* No side effect */ diff --git a/runtime/Pervasives.res b/runtime/Pervasives.res index bb5810cf55..a9a5abf735 100644 --- a/runtime/Pervasives.res +++ b/runtime/Pervasives.res @@ -12,7 +12,9 @@ external /* Internal */ __unsafe_cast: 'a => 'b = "%identity" /* Exceptions */ - +@deprecated( + "`raise` has been renamed to `throw` to align with JavaScript vocabulary. Please use `throw`" +) external raise: exn => 'a = "%raise" @deprecated("Use custom exception instead") diff --git a/runtime/Stdlib.res b/runtime/Stdlib.res index 990c8cc1f3..2fb34f3fbd 100644 --- a/runtime/Stdlib.res +++ b/runtime/Stdlib.res @@ -100,7 +100,23 @@ async function main() { external import: 'a => promise<'a> = "%import" let panic = Error.panic -let throw = Error.throw + +/** +Throw and exception which will stop execution. + +## Examples + +```rescript +let error = Error.make("Everything is upside down.") + +if 5 > 10 { + error->throw +} else { + Console.log("Phew, sanity still rules.") +} +``` +*/ +external throw: Error.t => 'a = "%raise" /** `assertEqual(a, b)` check if `a` is equal `b`. If not raise a panic exception diff --git a/runtime/Stdlib_Error.resi b/runtime/Stdlib_Error.resi index e9c08f8e8e..5ade34d790 100644 --- a/runtime/Stdlib_Error.resi +++ b/runtime/Stdlib_Error.resi @@ -155,7 +155,9 @@ if 5 > 10 { } ``` */ -@deprecated("Use `Error.throw` instead.") +@deprecated( + "`raise` has been renamed to `throw` to align with JavaScript vocabulary. Please use `throw`" +) external raise: t => 'a = "%raise" /** From ad6cd695b684dd9f00fa22f69a52eed36a954115 Mon Sep 17 00:00:00 2001 From: aspeddro Date: Wed, 19 Mar 2025 13:02:30 -0300 Subject: [PATCH 04/15] restore tests/gentype_tests/typescript-react-example/package-lock.json --- tests/gentype_tests/typescript-react-example/package-lock.json | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/gentype_tests/typescript-react-example/package-lock.json b/tests/gentype_tests/typescript-react-example/package-lock.json index 3c4be344a0..8b0560ac74 100644 --- a/tests/gentype_tests/typescript-react-example/package-lock.json +++ b/tests/gentype_tests/typescript-react-example/package-lock.json @@ -21,7 +21,6 @@ } }, "../../..": { - "name": "rescript", "version": "12.0.0-alpha.10", "dev": true, "hasInstallScript": true, From 69ebdcaf6d3bb8bdbbdb364b6251de9b29a3a594 Mon Sep 17 00:00:00 2001 From: aspeddro Date: Wed, 19 Mar 2025 13:12:42 -0300 Subject: [PATCH 05/15] update analysis output --- .../tests/src/expected/CompletionExpressions.res.txt | 2 +- .../tests/src/expected/CompletionFunctionArguments.res.txt | 4 ++-- .../tests/src/expected/CompletionJsxProps.res.txt | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/analysis_tests/tests/src/expected/CompletionExpressions.res.txt b/tests/analysis_tests/tests/src/expected/CompletionExpressions.res.txt index 8a96cc3233..4baabd9931 100644 --- a/tests/analysis_tests/tests/src/expected/CompletionExpressions.res.txt +++ b/tests/analysis_tests/tests/src/expected/CompletionExpressions.res.txt @@ -374,7 +374,7 @@ Path fnTakingRecord "kind": 12, "tags": [], "detail": "Error.t => 'a", - "documentation": null + "documentation": {"kind": "markdown", "value": "\nThrow and exception which will stop execution.\n\n## Examples\n\n```rescript\nlet error = Error.make(\"Everything is upside down.\")\n\nif 5 > 10 {\n error->throw\n} else {\n Console.log(\"Phew, sanity still rules.\")\n}\n```\n"} }, { "label": "typeof", "kind": 12, diff --git a/tests/analysis_tests/tests/src/expected/CompletionFunctionArguments.res.txt b/tests/analysis_tests/tests/src/expected/CompletionFunctionArguments.res.txt index 3bf6491f95..ec1c4c7fc0 100644 --- a/tests/analysis_tests/tests/src/expected/CompletionFunctionArguments.res.txt +++ b/tests/analysis_tests/tests/src/expected/CompletionFunctionArguments.res.txt @@ -48,7 +48,7 @@ Path someFn "kind": 12, "tags": [], "detail": "Error.t => 'a", - "documentation": null + "documentation": {"kind": "markdown", "value": "\nThrow and exception which will stop execution.\n\n## Examples\n\n```rescript\nlet error = Error.make(\"Everything is upside down.\")\n\nif 5 > 10 {\n error->throw\n} else {\n Console.log(\"Phew, sanity still rules.\")\n}\n```\n"} }, { "label": "typeof", "kind": 12, @@ -378,7 +378,7 @@ Path someOtherFn "kind": 12, "tags": [], "detail": "Error.t => 'a", - "documentation": null + "documentation": {"kind": "markdown", "value": "\nThrow and exception which will stop execution.\n\n## Examples\n\n```rescript\nlet error = Error.make(\"Everything is upside down.\")\n\nif 5 > 10 {\n error->throw\n} else {\n Console.log(\"Phew, sanity still rules.\")\n}\n```\n"} }, { "label": "typeof", "kind": 12, diff --git a/tests/analysis_tests/tests/src/expected/CompletionJsxProps.res.txt b/tests/analysis_tests/tests/src/expected/CompletionJsxProps.res.txt index 4970f4df88..fb71332e27 100644 --- a/tests/analysis_tests/tests/src/expected/CompletionJsxProps.res.txt +++ b/tests/analysis_tests/tests/src/expected/CompletionJsxProps.res.txt @@ -40,7 +40,7 @@ Path CompletionSupport.TestComponent.make "kind": 12, "tags": [], "detail": "Error.t => 'a", - "documentation": null + "documentation": {"kind": "markdown", "value": "\nThrow and exception which will stop execution.\n\n## Examples\n\n```rescript\nlet error = Error.make(\"Everything is upside down.\")\n\nif 5 > 10 {\n error->throw\n} else {\n Console.log(\"Phew, sanity still rules.\")\n}\n```\n"} }, { "label": "typeof", "kind": 12, @@ -378,7 +378,7 @@ Path CompletionSupport.TestComponent.make "kind": 12, "tags": [], "detail": "Error.t => 'a", - "documentation": null + "documentation": {"kind": "markdown", "value": "\nThrow and exception which will stop execution.\n\n## Examples\n\n```rescript\nlet error = Error.make(\"Everything is upside down.\")\n\nif 5 > 10 {\n error->throw\n} else {\n Console.log(\"Phew, sanity still rules.\")\n}\n```\n"} }, { "label": "typeof", "kind": 12, From cad94554aa3ea44c10b1c9e6e937176b7b0c8c17 Mon Sep 17 00:00:00 2001 From: aspeddro Date: Thu, 20 Mar 2025 15:47:11 -0300 Subject: [PATCH 06/15] update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a70aff209..1324b49bf8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - Add `inert` attribute to `JsxDOM.domProps`. https://github.com/rescript-lang/rescript/pull/7326 - Make reanalyze exception tracking work with the new stdlib. https://github.com/rescript-lang/rescript/pull/7328 - Fix Pervasive.max using boolean comparison for floats. https://github.com/rescript-lang/rescript/pull/7333 +- Rename `raise` to `throw` to align with JavaScript vocabulary. `raise` has been deprecated. https://github.com/rescript-lang/rescript/pull/7346 #### :boom: Breaking Change From 86ee1d108ba93167b85026f64db053c1def386bb Mon Sep 17 00:00:00 2001 From: aspeddro Date: Fri, 21 Mar 2025 11:43:54 -0300 Subject: [PATCH 07/15] move `throw` to Pervasives.res --- lib/es6/Stdlib.js | 2 +- lib/js/Stdlib.js | 2 +- runtime/Pervasives.res | 17 +++++++++++++++++ runtime/Stdlib.res | 17 ----------------- .../src/expected/CompletionExpressions.res.txt | 6 ------ .../CompletionFunctionArguments.res.txt | 12 ------------ .../src/expected/CompletionJsxProps.res.txt | 12 ------------ 7 files changed, 19 insertions(+), 49 deletions(-) diff --git a/lib/es6/Stdlib.js b/lib/es6/Stdlib.js index f30cc98e59..3d8f644de2 100644 --- a/lib/es6/Stdlib.js +++ b/lib/es6/Stdlib.js @@ -12,7 +12,7 @@ function assertEqual(a, b) { RE_EXN_ID: "Assert_failure", _1: [ "Stdlib.res", - 134, + 117, 4 ], Error: new Error() diff --git a/lib/js/Stdlib.js b/lib/js/Stdlib.js index 7cf4adb4d6..faf8270b03 100644 --- a/lib/js/Stdlib.js +++ b/lib/js/Stdlib.js @@ -12,7 +12,7 @@ function assertEqual(a, b) { RE_EXN_ID: "Assert_failure", _1: [ "Stdlib.res", - 134, + 117, 4 ], Error: new Error() diff --git a/runtime/Pervasives.res b/runtime/Pervasives.res index a9a5abf735..a68aa414eb 100644 --- a/runtime/Pervasives.res +++ b/runtime/Pervasives.res @@ -25,6 +25,23 @@ let invalid_arg = s => throw(Invalid_argument(s)) @deprecated("Use custom exception instead") exception Exit +/** +Throw and exception which will stop execution. + +## Examples + +```rescript +let error = Error.make("Everything is upside down.") + +if 5 > 10 { + error->throw +} else { + Console.log("Phew, sanity still rules.") +} +``` +*/ +external throw: Stdlib_Error.t => 'a = "%raise" + /* Composition operators */ external \"|>": ('a, 'a => 'b) => 'b = "%revapply" diff --git a/runtime/Stdlib.res b/runtime/Stdlib.res index 2fb34f3fbd..743a4a651c 100644 --- a/runtime/Stdlib.res +++ b/runtime/Stdlib.res @@ -101,23 +101,6 @@ external import: 'a => promise<'a> = "%import" let panic = Error.panic -/** -Throw and exception which will stop execution. - -## Examples - -```rescript -let error = Error.make("Everything is upside down.") - -if 5 > 10 { - error->throw -} else { - Console.log("Phew, sanity still rules.") -} -``` -*/ -external throw: Error.t => 'a = "%raise" - /** `assertEqual(a, b)` check if `a` is equal `b`. If not raise a panic exception diff --git a/tests/analysis_tests/tests/src/expected/CompletionExpressions.res.txt b/tests/analysis_tests/tests/src/expected/CompletionExpressions.res.txt index 4baabd9931..057b6130d6 100644 --- a/tests/analysis_tests/tests/src/expected/CompletionExpressions.res.txt +++ b/tests/analysis_tests/tests/src/expected/CompletionExpressions.res.txt @@ -369,12 +369,6 @@ Path fnTakingRecord "detail": "bool", "documentation": null, "sortText": "A true" - }, { - "label": "throw", - "kind": 12, - "tags": [], - "detail": "Error.t => 'a", - "documentation": {"kind": "markdown", "value": "\nThrow and exception which will stop execution.\n\n## Examples\n\n```rescript\nlet error = Error.make(\"Everything is upside down.\")\n\nif 5 > 10 {\n error->throw\n} else {\n Console.log(\"Phew, sanity still rules.\")\n}\n```\n"} }, { "label": "typeof", "kind": 12, diff --git a/tests/analysis_tests/tests/src/expected/CompletionFunctionArguments.res.txt b/tests/analysis_tests/tests/src/expected/CompletionFunctionArguments.res.txt index ec1c4c7fc0..ae28106430 100644 --- a/tests/analysis_tests/tests/src/expected/CompletionFunctionArguments.res.txt +++ b/tests/analysis_tests/tests/src/expected/CompletionFunctionArguments.res.txt @@ -43,12 +43,6 @@ Path someFn "tags": [], "detail": "bool", "documentation": null - }, { - "label": "throw", - "kind": 12, - "tags": [], - "detail": "Error.t => 'a", - "documentation": {"kind": "markdown", "value": "\nThrow and exception which will stop execution.\n\n## Examples\n\n```rescript\nlet error = Error.make(\"Everything is upside down.\")\n\nif 5 > 10 {\n error->throw\n} else {\n Console.log(\"Phew, sanity still rules.\")\n}\n```\n"} }, { "label": "typeof", "kind": 12, @@ -373,12 +367,6 @@ Path someOtherFn "tags": [], "detail": "bool", "documentation": null - }, { - "label": "throw", - "kind": 12, - "tags": [], - "detail": "Error.t => 'a", - "documentation": {"kind": "markdown", "value": "\nThrow and exception which will stop execution.\n\n## Examples\n\n```rescript\nlet error = Error.make(\"Everything is upside down.\")\n\nif 5 > 10 {\n error->throw\n} else {\n Console.log(\"Phew, sanity still rules.\")\n}\n```\n"} }, { "label": "typeof", "kind": 12, diff --git a/tests/analysis_tests/tests/src/expected/CompletionJsxProps.res.txt b/tests/analysis_tests/tests/src/expected/CompletionJsxProps.res.txt index 7bda8b09f7..ad2b74dba3 100644 --- a/tests/analysis_tests/tests/src/expected/CompletionJsxProps.res.txt +++ b/tests/analysis_tests/tests/src/expected/CompletionJsxProps.res.txt @@ -35,12 +35,6 @@ Path CompletionSupport.TestComponent.make "detail": "bool", "documentation": null, "sortText": "A true" - }, { - "label": "throw", - "kind": 12, - "tags": [], - "detail": "Error.t => 'a", - "documentation": {"kind": "markdown", "value": "\nThrow and exception which will stop execution.\n\n## Examples\n\n```rescript\nlet error = Error.make(\"Everything is upside down.\")\n\nif 5 > 10 {\n error->throw\n} else {\n Console.log(\"Phew, sanity still rules.\")\n}\n```\n"} }, { "label": "typeof", "kind": 12, @@ -379,12 +373,6 @@ Path CompletionSupport.TestComponent.make "tags": [], "detail": "[> #two]", "documentation": null - }, { - "label": "throw", - "kind": 12, - "tags": [], - "detail": "Error.t => 'a", - "documentation": {"kind": "markdown", "value": "\nThrow and exception which will stop execution.\n\n## Examples\n\n```rescript\nlet error = Error.make(\"Everything is upside down.\")\n\nif 5 > 10 {\n error->throw\n} else {\n Console.log(\"Phew, sanity still rules.\")\n}\n```\n"} }, { "label": "typeof", "kind": 12, From 9a4c60bd8f387f4a97b6761b890efbe3695fab3d Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Mon, 24 Mar 2025 18:47:12 -0300 Subject: [PATCH 08/15] Update runtime/Pervasives.res Co-authored-by: Christoph Knittel --- runtime/Pervasives.res | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/Pervasives.res b/runtime/Pervasives.res index a68aa414eb..80c7f4aeb4 100644 --- a/runtime/Pervasives.res +++ b/runtime/Pervasives.res @@ -26,7 +26,7 @@ let invalid_arg = s => throw(Invalid_argument(s)) @deprecated("Use custom exception instead") exception Exit /** -Throw and exception which will stop execution. +Raises the given exception, terminating execution unless caught by a surrounding try/catch block. ## Examples From cafdbedfdc6a79f2d68603b1cfc2c3bfd01c3a75 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Mon, 24 Mar 2025 18:47:22 -0300 Subject: [PATCH 09/15] Update runtime/Pervasives.res Co-authored-by: Christoph Knittel --- runtime/Pervasives.res | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/Pervasives.res b/runtime/Pervasives.res index 80c7f4aeb4..7031a76b4b 100644 --- a/runtime/Pervasives.res +++ b/runtime/Pervasives.res @@ -34,7 +34,7 @@ Raises the given exception, terminating execution unless caught by a surrounding let error = Error.make("Everything is upside down.") if 5 > 10 { - error->throw + throw(error) } else { Console.log("Phew, sanity still rules.") } From aa214cda6eada9c39f8e681bef483f4370aa189f Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Mon, 24 Mar 2025 18:47:36 -0300 Subject: [PATCH 10/15] Update runtime/Pervasives.res Co-authored-by: Christoph Knittel --- runtime/Pervasives.res | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/Pervasives.res b/runtime/Pervasives.res index 7031a76b4b..606e640b6c 100644 --- a/runtime/Pervasives.res +++ b/runtime/Pervasives.res @@ -13,7 +13,7 @@ __unsafe_cast: 'a => 'b = "%identity" /* Exceptions */ @deprecated( - "`raise` has been renamed to `throw` to align with JavaScript vocabulary. Please use `throw`" + "`raise` has been renamed to `throw` to align with JavaScript vocabulary. Please use `throw` instead" ) external raise: exn => 'a = "%raise" From 3de67711d1fe81389cf8c907169edae6aeadaf65 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Mon, 24 Mar 2025 18:47:47 -0300 Subject: [PATCH 11/15] Update runtime/Stdlib_Error.resi Co-authored-by: Christoph Knittel --- runtime/Stdlib_Error.resi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/Stdlib_Error.resi b/runtime/Stdlib_Error.resi index 3940222530..cc746d52a3 100644 --- a/runtime/Stdlib_Error.resi +++ b/runtime/Stdlib_Error.resi @@ -156,7 +156,7 @@ if 5 > 10 { ``` */ @deprecated( - "`raise` has been renamed to `throw` to align with JavaScript vocabulary. Please use `throw`" + "`raise` has been renamed to `throw` to align with JavaScript vocabulary. Please use `throw` instead" ) external raise: t => 'a = "%raise" From 86860f16f11d67cfa5ebc9f8cce09f368d9c82cb Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Mon, 24 Mar 2025 18:47:57 -0300 Subject: [PATCH 12/15] Update runtime/Stdlib_Error.resi Co-authored-by: Christoph Knittel --- runtime/Stdlib_Error.resi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/Stdlib_Error.resi b/runtime/Stdlib_Error.resi index cc746d52a3..5d99c7283f 100644 --- a/runtime/Stdlib_Error.resi +++ b/runtime/Stdlib_Error.resi @@ -161,7 +161,7 @@ if 5 > 10 { external raise: t => 'a = "%raise" /** -Throw and exception provided `Error.t`, which will stop execution. +Raises the given exception, terminating execution unless caught by a surrounding try/catch block. ## Examples From 263f9fd7a3736205661ece016e81f58f098eee82 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Mon, 24 Mar 2025 18:48:11 -0300 Subject: [PATCH 13/15] Update runtime/Stdlib_Error.resi Co-authored-by: Christoph Knittel --- runtime/Stdlib_Error.resi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/Stdlib_Error.resi b/runtime/Stdlib_Error.resi index 5d99c7283f..45cbed665d 100644 --- a/runtime/Stdlib_Error.resi +++ b/runtime/Stdlib_Error.resi @@ -169,7 +169,7 @@ Raises the given exception, terminating execution unless caught by a surrounding let error = Error.make("Everything is upside down.") if 5 > 10 { - error->Error.throw + Error.throw(error) } else { Console.log("Phew, sanity still rules.") } From 518bb75e914718195bedd26a00f45fd5b5e1cf56 Mon Sep 17 00:00:00 2001 From: aspeddro Date: Mon, 24 Mar 2025 19:09:18 -0300 Subject: [PATCH 14/15] update Stdlib_Bool and Stdlib_Char --- runtime/Pervasives.res | 2 +- runtime/Stdlib_Bool.res | 2 +- runtime/Stdlib_Char.res | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/Pervasives.res b/runtime/Pervasives.res index b7b8f8c8b4..83c693881f 100644 --- a/runtime/Pervasives.res +++ b/runtime/Pervasives.res @@ -34,7 +34,7 @@ Raises the given exception, terminating execution unless caught by a surrounding let error = Error.make("Everything is upside down.") if 5 > 10 { - throw(error) + throw(error) } else { Console.log("Phew, sanity still rules.") } diff --git a/runtime/Stdlib_Bool.res b/runtime/Stdlib_Bool.res index 0d4371ddfc..27f04f31df 100644 --- a/runtime/Stdlib_Bool.res +++ b/runtime/Stdlib_Bool.res @@ -19,7 +19,7 @@ let fromStringExn = param => switch param { | "true" => true | "false" => false - | _ => raise(Invalid_argument(`Bool.fromStringExn: value is neither "true" nor "false"`)) + | _ => throw(Invalid_argument(`Bool.fromStringExn: value is neither "true" nor "false"`)) } external compare: (bool, bool) => Stdlib_Ordering.t = "%compare" diff --git a/runtime/Stdlib_Char.res b/runtime/Stdlib_Char.res index 7e28ed66ae..f846c78a0f 100644 --- a/runtime/Stdlib_Char.res +++ b/runtime/Stdlib_Char.res @@ -10,7 +10,7 @@ external fromIntUnsafe: int => t = "%identity" let fromIntExn = n => if n < 0 || n > 255 { - raise(Invalid_argument("`Char.fromIntExn` expects an integer between 0 and 255")) + throw(Invalid_argument("`Char.fromIntExn` expects an integer between 0 and 255")) } else { fromIntUnsafe(n) } From a36b71d1e699032411c417d4def7fe3ff69aa06a Mon Sep 17 00:00:00 2001 From: aspeddro Date: Mon, 24 Mar 2025 19:44:33 -0300 Subject: [PATCH 15/15] remove comment --- runtime/Pervasives.res | 8 -------- 1 file changed, 8 deletions(-) diff --git a/runtime/Pervasives.res b/runtime/Pervasives.res index 83c693881f..c029346f79 100644 --- a/runtime/Pervasives.res +++ b/runtime/Pervasives.res @@ -1,11 +1,3 @@ -/** - Since [others] depend on this file, its public mli files **should not - export types** introduced here, otherwise it would cause - conflicts here. - - If the type exported here is also exported in modules from others, - you will get a type not equivalent. -*/ @deprecated("Do not use. This will be removed in v13") external /* Internal */