1
//! CONS / `$pair` construction codegen. The Commodity-specific
2
//! type-mismatch tests moved into the inline `list::tests` module
3
//! since they exercise the private `infer_pair_element` directly —
4
//! script-mode lacks a Commodity producer, and the unit tests are
5
//! the right level for that contract.
6

            
7
use super::common::compile_and_validate;
8

            
9
#[test]
10
1
fn nil_car_beside_runtime_string_cell_widens_to_anyref() {
11
    // A `nil` car takes the Bool slot, so beside a string cell the chain widens
12
    // to AnyRef and nil rides as a null ref — never a typed null in a string
13
    // cell that `CAR`'s non-null cast would trap on.
14
1
    compile_and_validate("(let* ((idx (entity-count))) (cons nil (cons (tag-name idx) nil)))");
15
1
}
16

            
17
#[test]
18
1
fn integer_cons_chain() {
19
    // P3a 3a.2: all-integer literal cons chain rides $pair with
20
    // `PairElement::I32`. Replaces the pre-migration i32-only `$cons`.
21
1
    compile_and_validate("(cons 1 (cons 2 (cons 3 nil)))");
22
1
}
23

            
24
#[test]
25
1
fn pair_of_ratios() {
26
    // P3a 3a.3: per-element pair codegen handles Ratio cars without
27
    // the legacy `capture_pending_ratio` helper.
28
1
    compile_and_validate("(cons (/ 1 2) (cons (/ 3 4) nil))");
29
1
}
30

            
31
#[test]
32
1
fn pair_of_strings() {
33
1
    compile_and_validate("(cons \"hi\" (cons \"world\" nil))");
34
1
}