Lines
100 %
Functions
Branches
//! CONS / `$pair` construction codegen. The Commodity-specific
//! type-mismatch tests moved into the inline `list::tests` module
//! since they exercise the private `infer_pair_element` directly —
//! script-mode lacks a Commodity producer, and the unit tests are
//! the right level for that contract.
use super::common::{compile_and_validate, compile_expect_error};
#[test]
fn nil_car_in_runtime_string_cell_is_compile_error_not_car_trap() {
// A runtime string element forces the cell to `PairElement::StringRef`.
// A `nil` car must stay a COMPILE error — not a typed null that `CAR`'s
// non-null cast would trap on at runtime. (Value cells coerce nil to a real
// zero; ref cells keep the strict match.)
let err =
compile_expect_error("(let* ((idx (entity-count))) (cons nil (cons (tag-name idx) nil)))");
assert!(
err.contains("CONS car") || err.contains("string"),
"expected a car type-mismatch compile error, got: {err}",
);
}
fn integer_cons_chain() {
// P3a 3a.2: all-integer literal cons chain rides $pair with
// `PairElement::I32`. Replaces the pre-migration i32-only `$cons`.
compile_and_validate("(cons 1 (cons 2 (cons 3 nil)))");
fn pair_of_ratios() {
// P3a 3a.3: per-element pair codegen handles Ratio cars without
// the legacy `capture_pending_ratio` helper.
compile_and_validate("(cons (/ 1 2) (cons (/ 3 4) nil))");
fn pair_of_strings() {
compile_and_validate("(cons \"hi\" (cons \"world\" nil))");