Lines
100 %
Functions
Branches
//! ADR-0033: list consumers accept a bare `AnyRef` operand (not just a
//! statically-typed `PairRef(elem)` chain) — null becomes `nil`, a `$pair`
//! passes `ref.test` and is cast, anything else throws a catchable
//! `TYPE-ERROR`. Covers CAR / CDR / LENGTH / REVERSE / APPEND / FOLD / MAP /
//! FILTER / DOLIST, each fed a genuinely `AnyRef`-typed operand — an `IF`
//! whose arms disagree widens to `AnyRef` (`(list 1)` vs `"a"`).
use super::common::{compile_and_validate, wrap_with_runtime_i32};
fn anyref_or_nil(then_form: &str) -> String {
wrap_with_runtime_i32(&format!("(let* ((V (if (> IDX 0) {then_form} \"a\"))) V)"))
}
#[test]
fn car_and_cdr_over_an_anyref_operand() {
let v = anyref_or_nil("(list 1)");
compile_and_validate(&format!("(let* ((V {v})) (car V))"));
compile_and_validate(&format!("(let* ((V {v})) (cdr V))"));
fn length_over_an_anyref_operand() {
compile_and_validate(&format!("(length {})", anyref_or_nil("(list 1 2)")));
fn reverse_over_an_anyref_operand() {
compile_and_validate(&format!("(reverse {})", anyref_or_nil("(list 1 2)")));
fn append_over_an_anyref_operand() {
compile_and_validate(&format!(
"(append {} (list 3))",
anyref_or_nil("(list 1 2)")
));
fn fold_over_an_anyref_operand() {
compile_and_validate(&wrap_with_runtime_i32(&format!(
"(fold (lambda (acc x) (cons x acc)) nil {})",
)));
fn map_over_an_anyref_operand() {
"(map (lambda (x) (null? x)) {})",
fn filter_over_an_anyref_operand() {
"(filter (lambda (x) (null? x)) {})",
fn dolist_over_an_anyref_operand() {
"(dolist (x {}) (null? x))",
fn car_of_a_non_list_anyref_compiles_the_runtime_throw_path() {
// The "not a list" TYPE-ERROR is a runtime throw, not a compile error —
// this only pins that the dynamic dispatch (null / $pair / anything
// else) still emits valid wasm when the operand is a non-list AnyRef.
compile_and_validate(&format!("(car {})", anyref_or_nil("1")));