Skip to content

Commit 04d78b0

Browse files
authored
Fix cloning empty Maybe values in Javascript (#1080)
* Fix cloning empty Maybe values in Javascript * Fix indent * Remove branch name from js root binding
1 parent b1f87d3 commit 04d78b0

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

alan/test.ln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,13 @@ export fn{Test} main {
12501250
test
12511251
.assert(eq, maybe5.exists, true)
12521252
.assert(eq, maybeNot.exists, false);
1253+
})
1254+
.it('can be cloned', fn (test: Mut{Testing}) {
1255+
const maybe5 = Maybe{i64}(5);
1256+
const maybeNot = Maybe{i64}();
1257+
test
1258+
.assert(eq, maybe5.clone.exists, true)
1259+
.assert(eq, maybeNot.clone.exists, false);
12531260
});
12541261

12551262
test.describe("Tree")

alan_std.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ export class FuzzySet {
130130
}
131131

132132
export function clone(v) {
133-
if (v instanceof Array) {
133+
if (v === null) {
134+
return null;
135+
} else if (v instanceof Array) {
134136
return v.map(clone);
135137
} else if (v instanceof FuzzySet) {
136138
return v.union(new FuzzySet());

0 commit comments

Comments
 (0)