Lines
100 %
Functions
Branches
//! Regression tests for `nil` flowing into a `Never`-classified wasm type
//! (ADR-0033 Phase 3, superseding ADR-0028 Commit A). Under the Common Lisp
//! boolean model an Index, Scalar, Money or Closure has NO valid nil — a
//! `nil` FOLD seed or closure argument sized to one of those types is a
//! compile error ("nil is not a scalar; initialise with 0"), not the
//! made-up-zero nil-punning the old `emit_nil_default` produced. Each
//! test below used to compile (Commit A's fix); Phase 3 asserts it no longer
//! does. `fold_symbol_nil_seed_pair_accumulator` is the one shape that stays
//! valid — a `PairRef` accumulator's nil IS the empty chain.
use super::common::{compile_and_validate, compile_expect_error};
const NIL_NOT_SCALAR: &str = "nil is not a scalar; initialise with 0";
/// A `FOLD` over a runtime list with a `nil` seed whose accumulator type
/// probes to `Ratio` is now a compile error.
#[test]
fn fold_nil_seed_ratio_accumulator() {
let err = compile_expect_error(
"(let* ((X (transaction-post-date 0))) \
(fold (lambda (acc x) (+ x X)) nil (cons X nil)))",
);
assert!(err.contains(NIL_NOT_SCALAR), "got: {err}");
}
/// A runtime closure (captures the runtime `X`) whose parameter unifies to
/// `Ratio` invoked with a `nil` literal argument is now a compile error.
fn closure_call_nil_arg_typed_param() {
"(let* ((X (transaction-post-date 0)) (F (lambda (A) (if (null? A) X A)))) \
(funcall F nil))",
/// Resolved-nil path: a runtime closure invoked with a SYMBOL bound to `nil`
/// is now a compile error.
fn closure_call_symbol_nil_arg() {
"(let* ((X (transaction-post-date 0)) (Z nil) (F (lambda (A) (if (null? A) X A)))) \
(funcall F Z))",
/// Resolved-nil path: a FOLD seed that is a SYMBOL bound to `nil`, with a
/// `Ratio` accumulator, is now a compile error.
fn fold_symbol_nil_seed_ratio_accumulator() {
"(let* ((X (transaction-post-date 0)) (Z nil)) \
(fold (lambda (acc x) (+ x X)) Z (cons X nil)))",
/// A `PairRef` accumulator's `nil` seed stays valid — `nil` IS the empty
/// `$pair` chain (`NilRepr::Null`), not a made-up numeric zero. A non-literal
/// nil seed still routes through the resolved-nil branch (which precedes
/// `PairRef` constant-list materialization), emitting the empty chain after
/// any seed effects.
fn fold_symbol_nil_seed_pair_accumulator() {
compile_and_validate(
(fold (lambda (acc x) (cons x acc)) Z (cons X nil)))",