Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/codegen_deno.ml
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ let common_prelude = {|
const Some = (value) => ({ tag: "Some", value });
const None = { tag: "None" };
const Ok = (value) => ({ tag: "Ok", value });
const Err = (error) => ({ tag: "Err", error });
const Err = (value) => ({ tag: "Err", value });
const Unit = null;
const __as_regexMatch = (s, pat) => new RegExp(pat).test(String(s));
const __as_wasmInstance = (bytes) =>
Expand Down
2 changes: 1 addition & 1 deletion lib/js_codegen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ let prelude = {|// ---- AffineScript JS runtime (MVP) ----
const Some = (value) => ({ tag: "Some", value });
const None = { tag: "None" };
const Ok = (value) => ({ tag: "Ok", value });
const Err = (error) => ({ tag: "Err", error });
const Err = (value) => ({ tag: "Err", value });
const Unit = null;
const print = (s) => { (typeof Deno !== "undefined" ? Deno.stdout.writeSync(new TextEncoder().encode(String(s))) : process.stdout.write(String(s))); };
const println = (s) => { console.log(String(s)); };
Expand Down
2 changes: 1 addition & 1 deletion lib/lua_codegen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ local function as_print(s) io.write(tostring(s)) end
local Some = function(v) return { tag = "Some", value = v } end
local None = { tag = "None" }
local Ok = function(v) return { tag = "Ok", value = v } end
local Err = function(e) return { tag = "Err", error = e } end
local Err = function(v) return { tag = "Err", value = v } end
local function read_line() local l = io.read("l"); return l or "" end

|}
Expand Down
24 changes: 24 additions & 0 deletions tests/codegen-bun/result_payload.affine
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: MPL-2.0
// Regression: an `Err(e)` arm must bind the payload. The runtime prelude
// built Err as { tag, error } while every match lowering reads the
// single-payload convention `.value`, so `e` was `undefined` (found while
// writing kyX, metadatastician/kyx).

use prelude::{ Result, Ok, Err, Option, Some, None };

fn check(s: String) -> Result<Int, String> {
if s == "ok" { Ok(1) } else { Err("bad: " ++ s) }
}

pub fn err_message(s: String) -> String {
match check(s) { Ok(n) => "ok", Err(m) => m }
}

pub fn ok_value(s: String) -> Int {
match check(s) { Ok(n) => n, Err(m) => 0 }
}

pub fn nested_err() -> String {
let r: Option<Result<Int, String>> = Some(Err("inner"));
match r { Some(Err(m)) => m, Some(Ok(n)) => "ok", None => "none" }
}
10 changes: 10 additions & 0 deletions tests/codegen-bun/result_payload.harness.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MPL-2.0
import * as subject from "./result_payload.bun.js";

const expect = (label, got, want) => {
if (got !== want) throw new Error(`${label}: got ${JSON.stringify(got)}, want ${JSON.stringify(want)}`);
};
expect("Err payload binds", subject.err_message("x"), "bad: x");
expect("Ok arm still binds", subject.ok_value("ok"), 1);
expect("Err payload in a nested pattern", subject.nested_err(), "inner");
console.log("result_payload: ok");
9 changes: 9 additions & 0 deletions tools/run_codegen_bun_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@
for js in "$TEST_DIR"/*.harness.mjs; do
name="$(basename "$js")"
harness_total=$((harness_total + 1))
# Each harness imports <stem>.bun.js; compile its subject first (step 1
# already compiled host_profile).
subject_src="$TEST_DIR/${name%.harness.mjs}.affine"
if [ "$subject_src" != "$src" ]; then

Check failure on line 91 in tools/run_codegen_bun_tests.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use '[[' instead of '[' for conditional tests. The '[[' construct is safer and more feature-rich.

See more on https://sonarcloud.io/project/issues?id=hyperpolymath_affinescript&issues=AaHbvb0_kRD0nal3ynih&open=AaHbvb0_kRD0nal3ynih&pullRequest=791
if ! "${COMPILE_CMD[@]}" "$subject_src" -o "${subject_src%.affine}.bun.js" --bun-esm; then

Check warning on line 92 in tools/run_codegen_bun_tests.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Merge this if statement with the enclosing one.

See more on https://sonarcloud.io/project/issues?id=hyperpolymath_affinescript&issues=AaHbvb0_kRD0nal3ynii&open=AaHbvb0_kRD0nal3ynii&pullRequest=791
fail "compile failed for $(basename "$subject_src")"
continue
fi
fi
if ! (cd "$TEST_DIR" && AFFINESCRIPT_BUN_PROBE=estate bun "$name" alpha beta); then
fail "bun harness failed: $name"
fi
Expand Down
Loading