1
//! Regression tests for `nil` flowing into a `Never`-classified wasm type
2
//! (ADR-0033 Phase 3, superseding ADR-0028 Commit A). Under the Common Lisp
3
//! boolean model an Index, Scalar, Money or Closure has NO valid nil — a
4
//! `nil` FOLD seed or closure argument sized to one of those types is a
5
//! compile error ("nil is not a scalar; initialise with 0"), not the
6
//! made-up-zero nil-punning the old `emit_nil_default` produced. Each
7
//! test below used to compile (Commit A's fix); Phase 3 asserts it no longer
8
//! does. `fold_symbol_nil_seed_pair_accumulator` is the one shape that stays
9
//! valid — a `PairRef` accumulator's nil IS the empty chain.
10

            
11
use super::common::{compile_and_validate, compile_expect_error};
12

            
13
const NIL_NOT_SCALAR: &str = "nil is not a scalar; initialise with 0";
14

            
15
/// A `FOLD` over a runtime list with a `nil` seed whose accumulator type
16
/// probes to `Ratio` is now a compile error.
17
#[test]
18
1
fn fold_nil_seed_ratio_accumulator() {
19
1
    let err = compile_expect_error(
20
1
        "(let* ((X (transaction-post-date 0))) \
21
1
           (fold (lambda (acc x) (+ x X)) nil (cons X nil)))",
22
1
    );
23
1
    assert!(err.contains(NIL_NOT_SCALAR), "got: {err}");
24
1
}
25

            
26
/// A runtime closure (captures the runtime `X`) whose parameter unifies to
27
/// `Ratio` invoked with a `nil` literal argument is now a compile error.
28
#[test]
29
1
fn closure_call_nil_arg_typed_param() {
30
1
    let err = compile_expect_error(
31
1
        "(let* ((X (transaction-post-date 0)) (F (lambda (A) (if (null? A) X A)))) \
32
1
           (funcall F nil))",
33
1
    );
34
1
    assert!(err.contains(NIL_NOT_SCALAR), "got: {err}");
35
1
}
36

            
37
/// Resolved-nil path: a runtime closure invoked with a SYMBOL bound to `nil`
38
/// is now a compile error.
39
#[test]
40
1
fn closure_call_symbol_nil_arg() {
41
1
    let err = compile_expect_error(
42
1
        "(let* ((X (transaction-post-date 0)) (Z nil) (F (lambda (A) (if (null? A) X A)))) \
43
1
           (funcall F Z))",
44
1
    );
45
1
    assert!(err.contains(NIL_NOT_SCALAR), "got: {err}");
46
1
}
47

            
48
/// Resolved-nil path: a FOLD seed that is a SYMBOL bound to `nil`, with a
49
/// `Ratio` accumulator, is now a compile error.
50
#[test]
51
1
fn fold_symbol_nil_seed_ratio_accumulator() {
52
1
    let err = compile_expect_error(
53
1
        "(let* ((X (transaction-post-date 0)) (Z nil)) \
54
1
           (fold (lambda (acc x) (+ x X)) Z (cons X nil)))",
55
1
    );
56
1
    assert!(err.contains(NIL_NOT_SCALAR), "got: {err}");
57
1
}
58

            
59
/// A `PairRef` accumulator's `nil` seed stays valid — `nil` IS the empty
60
/// `$pair` chain (`NilRepr::Null`), not a made-up numeric zero. A non-literal
61
/// nil seed still routes through the resolved-nil branch (which precedes
62
/// `PairRef` constant-list materialization), emitting the empty chain after
63
/// any seed effects.
64
#[test]
65
1
fn fold_symbol_nil_seed_pair_accumulator() {
66
1
    compile_and_validate(
67
1
        "(let* ((X (transaction-post-date 0)) (Z nil)) \
68
1
           (fold (lambda (acc x) (cons x acc)) Z (cons X nil)))",
69
1
    );
70
1
}