From d6bc53ed08f300850df3f15f7c4d3399bd49c120 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Thu, 5 Dec 2024 09:16:16 +0100 Subject: [PATCH 1/3] Fix nullable to opt conversion. --- compiler/ml/translcore.ml | 2 +- lib/es6/Nullable.js | 32 ++++++++++++++++---------------- lib/js/Nullable.js | 32 ++++++++++++++++---------------- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/compiler/ml/translcore.ml b/compiler/ml/translcore.ml index 27b8152d44..e150606370 100644 --- a/compiler/ml/translcore.ml +++ b/compiler/ml/translcore.ml @@ -393,7 +393,7 @@ let primitives_table = ("#typeof", Ptypeof); ("#is_nullable", Pisnullable); ("#null_to_opt", Pnullable_to_opt); - ("#nullable_to_opt", Pnull_to_opt); + ("#nullable_to_opt", Pnullable_to_opt); ("#undefined_to_opt", Pundefined_to_opt); ("#makemutablelist", Pmakelist Mutable); ("#import", Pimport); diff --git a/lib/es6/Nullable.js b/lib/es6/Nullable.js index 714f9d68a8..13415fc964 100644 --- a/lib/es6/Nullable.js +++ b/lib/es6/Nullable.js @@ -11,23 +11,23 @@ function fromOption(option) { } function equal(a, b, eq) { - return Option.equal(a === null ? undefined : Primitive_option.some(a), b === null ? undefined : Primitive_option.some(b), eq); + return Option.equal((a == null) ? undefined : Primitive_option.some(a), (b == null) ? undefined : Primitive_option.some(b), eq); } function compare(a, b, cmp) { - return Option.compare(a === null ? undefined : Primitive_option.some(a), b === null ? undefined : Primitive_option.some(b), cmp); + return Option.compare((a == null) ? undefined : Primitive_option.some(a), (b == null) ? undefined : Primitive_option.some(b), cmp); } function getOr(value, $$default) { - if (value !== null) { - return value; - } else { + if (value == null) { return $$default; + } else { + return value; } } function getExn(value) { - if (value !== null) { + if (!(value == null)) { return value; } throw { @@ -38,33 +38,33 @@ function getExn(value) { } function forEach(value, f) { - if (value !== null) { + if (!(value == null)) { return f(value); } } function map(value, f) { - if (value !== null) { - return f(value); - } else { + if (value == null) { return value; + } else { + return f(value); } } function mapOr(value, $$default, f) { - if (value !== null) { - return f(value); - } else { + if (value == null) { return $$default; + } else { + return f(value); } } function flatMap(value, f) { - if (value !== null) { - return f(value); - } else { + if (value == null) { return value; + } else { + return f(value); } } diff --git a/lib/js/Nullable.js b/lib/js/Nullable.js index eeb1eee1fb..d89d21173f 100644 --- a/lib/js/Nullable.js +++ b/lib/js/Nullable.js @@ -11,23 +11,23 @@ function fromOption(option) { } function equal(a, b, eq) { - return Option.equal(a === null ? undefined : Primitive_option.some(a), b === null ? undefined : Primitive_option.some(b), eq); + return Option.equal((a == null) ? undefined : Primitive_option.some(a), (b == null) ? undefined : Primitive_option.some(b), eq); } function compare(a, b, cmp) { - return Option.compare(a === null ? undefined : Primitive_option.some(a), b === null ? undefined : Primitive_option.some(b), cmp); + return Option.compare((a == null) ? undefined : Primitive_option.some(a), (b == null) ? undefined : Primitive_option.some(b), cmp); } function getOr(value, $$default) { - if (value !== null) { - return value; - } else { + if (value == null) { return $$default; + } else { + return value; } } function getExn(value) { - if (value !== null) { + if (!(value == null)) { return value; } throw { @@ -38,33 +38,33 @@ function getExn(value) { } function forEach(value, f) { - if (value !== null) { + if (!(value == null)) { return f(value); } } function map(value, f) { - if (value !== null) { - return f(value); - } else { + if (value == null) { return value; + } else { + return f(value); } } function mapOr(value, $$default, f) { - if (value !== null) { - return f(value); - } else { + if (value == null) { return $$default; + } else { + return f(value); } } function flatMap(value, f) { - if (value !== null) { - return f(value); - } else { + if (value == null) { return value; + } else { + return f(value); } } From 8657a492099da3d442a4a8efcf15466fd4922084 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Thu, 5 Dec 2024 09:19:31 +0100 Subject: [PATCH 2/3] One more typo. --- compiler/ml/translcore.ml | 2 +- lib/es6/Null.js | 32 ++++++++++++++++---------------- lib/js/Null.js | 32 ++++++++++++++++---------------- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/compiler/ml/translcore.ml b/compiler/ml/translcore.ml index e150606370..de3dbadeaa 100644 --- a/compiler/ml/translcore.ml +++ b/compiler/ml/translcore.ml @@ -392,7 +392,7 @@ let primitives_table = ("#undefined", Pundefined); ("#typeof", Ptypeof); ("#is_nullable", Pisnullable); - ("#null_to_opt", Pnullable_to_opt); + ("#null_to_opt", Pnull_to_opt); ("#nullable_to_opt", Pnullable_to_opt); ("#undefined_to_opt", Pundefined_to_opt); ("#makemutablelist", Pmakelist Mutable); diff --git a/lib/es6/Null.js b/lib/es6/Null.js index 5913fddfb1..11cf9f43ce 100644 --- a/lib/es6/Null.js +++ b/lib/es6/Null.js @@ -12,23 +12,23 @@ function fromOption(option) { } function equal(a, b, eq) { - return Option.equal((a == null) ? undefined : Primitive_option.some(a), (b == null) ? undefined : Primitive_option.some(b), eq); + return Option.equal(a === null ? undefined : Primitive_option.some(a), b === null ? undefined : Primitive_option.some(b), eq); } function compare(a, b, cmp) { - return Option.compare((a == null) ? undefined : Primitive_option.some(a), (b == null) ? undefined : Primitive_option.some(b), cmp); + return Option.compare(a === null ? undefined : Primitive_option.some(a), b === null ? undefined : Primitive_option.some(b), cmp); } function getOr(value, $$default) { - if (value == null) { - return $$default; - } else { + if (value !== null) { return value; + } else { + return $$default; } } function getExn(value) { - if (!(value == null)) { + if (value !== null) { return value; } throw { @@ -39,33 +39,33 @@ function getExn(value) { } function forEach(value, f) { - if (!(value == null)) { + if (value !== null) { return f(value); } } function map(value, f) { - if (value == null) { - return null; - } else { + if (value !== null) { return f(value); + } else { + return null; } } function mapOr(value, $$default, f) { - if (value == null) { - return $$default; - } else { + if (value !== null) { return f(value); + } else { + return $$default; } } function flatMap(value, f) { - if (value == null) { - return null; - } else { + if (value !== null) { return f(value); + } else { + return null; } } diff --git a/lib/js/Null.js b/lib/js/Null.js index 1f79c22c94..701d356403 100644 --- a/lib/js/Null.js +++ b/lib/js/Null.js @@ -12,23 +12,23 @@ function fromOption(option) { } function equal(a, b, eq) { - return Option.equal((a == null) ? undefined : Primitive_option.some(a), (b == null) ? undefined : Primitive_option.some(b), eq); + return Option.equal(a === null ? undefined : Primitive_option.some(a), b === null ? undefined : Primitive_option.some(b), eq); } function compare(a, b, cmp) { - return Option.compare((a == null) ? undefined : Primitive_option.some(a), (b == null) ? undefined : Primitive_option.some(b), cmp); + return Option.compare(a === null ? undefined : Primitive_option.some(a), b === null ? undefined : Primitive_option.some(b), cmp); } function getOr(value, $$default) { - if (value == null) { - return $$default; - } else { + if (value !== null) { return value; + } else { + return $$default; } } function getExn(value) { - if (!(value == null)) { + if (value !== null) { return value; } throw { @@ -39,33 +39,33 @@ function getExn(value) { } function forEach(value, f) { - if (!(value == null)) { + if (value !== null) { return f(value); } } function map(value, f) { - if (value == null) { - return null; - } else { + if (value !== null) { return f(value); + } else { + return null; } } function mapOr(value, $$default, f) { - if (value == null) { - return $$default; - } else { + if (value !== null) { return f(value); + } else { + return $$default; } } function flatMap(value, f) { - if (value == null) { - return null; - } else { + if (value !== null) { return f(value); + } else { + return null; } } From 35bb5e4b59474182f4b55afd9e23a59175347a82 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Thu, 5 Dec 2024 09:44:57 +0100 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d1196006f..ce8062e9ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ #### :bug: Bug fix - Fix bug where a ref assignment is moved ouside a conditional. https://github.com/rescript-lang/rescript/pull/7176 +- Fix nullable to opt conversion. https://github.com/rescript-lang/rescript/pull/7193 #### :house: Internal - Use latest compiler for tests. https://github.com/rescript-lang/rescript/pull/7186