1
use super::*;
2
use crate::ast::{ClosureSigId, Number};
3
use crate::reader::Reader;
4
use crate::runtime::{Fraction, Symbol, SymbolKind};
5

            
6
180
fn sym(s: &str) -> Expr {
7
180
    Expr::Symbol(s.to_string())
8
180
}
9
82
fn list(items: Vec<Expr>) -> Expr {
10
82
    Expr::List(items)
11
82
}
12
10
fn num(n: i64) -> Expr {
13
10
    Expr::Number(Number::Index(n))
14
10
}
15

            
16
19
fn pinned(body: &Expr, name: &str) -> Option<WasmType> {
17
19
    pinned_in(body, name, &SymbolTable::new())
18
19
}
19

            
20
70
fn pinned_in(body: &Expr, name: &str, symbols: &SymbolTable) -> Option<WasmType> {
21
70
    pinned_param_type(body, name, &Scope::new(symbols, &[]))
22
70
}
23

            
24
46
fn with_local(name: &str, ty: WasmType) -> SymbolTable {
25
46
    let mut symbols = SymbolTable::with_builtins();
26
46
    symbols.define(Symbol::new(name, SymbolKind::Variable).with_value(Expr::WasmLocal(0, ty)));
27
46
    symbols
28
46
}
29

            
30
4
fn pair(elem: PairElement) -> Option<WasmType> {
31
4
    Some(WasmType::PairRef(elem))
32
4
}
33

            
34
#[test]
35
1
fn cons_cdr_literal_car_is_that_cell() {
36
1
    let body = list(vec![sym("CONS"), num(1), sym("acc")]);
37
1
    assert_eq!(pinned(&body, "acc"), pair(PairElement::I32));
38
1
}
39

            
40
#[test]
41
1
fn cons_cdr_nonliteral_car_widens_to_anyref() {
42
1
    let body = list(vec![sym("CONS"), sym("x"), sym("acc")]);
43
1
    assert_eq!(pinned(&body, "acc"), pair(PairElement::AnyRef));
44
1
    assert_eq!(pinned(&body, "x"), None);
45
1
}
46

            
47
#[test]
48
1
fn no_cons_cdr_use_is_unconstrained() {
49
1
    let body = list(vec![sym("*"), sym("x"), list(vec![sym("foo")])]);
50
1
    assert_eq!(pinned(&body, "x"), None);
51
1
}
52

            
53
#[test]
54
1
fn string_native_arg_pins_stringref() {
55
    // (string= s "x") → s is a string.
56
1
    let body = list(vec![sym("STRING="), sym("s"), Expr::String("x".into())]);
57
1
    assert_eq!(pinned(&body, "s"), Some(WasmType::StringRef));
58
1
}
59

            
60
#[test]
61
1
fn quoted_string_native_does_not_pin() {
62
    // (quote (string= x "a")) — quoted data must NOT pin `x` to StringRef.
63
1
    let body = list(vec![
64
1
        sym("quote"),
65
1
        list(vec![sym("string="), sym("x"), Expr::String("a".into())]),
66
1
    ]);
67
1
    assert_eq!(pinned(&body, "x"), None);
68
1
}
69

            
70
#[test]
71
1
fn quasiquoted_string_native_does_not_pin() {
72
1
    let body = list(vec![
73
1
        sym("quasiquote"),
74
1
        list(vec![sym("string="), sym("x"), Expr::String("a".into())]),
75
1
    ]);
76
1
    assert_eq!(pinned(&body, "x"), None);
77
1
}
78

            
79
#[test]
80
1
fn shadowing_let_body_does_not_retype_outer_param() {
81
    // (let ((x nil)) (cons 1 x)) — cdr is the INNER `x`; outer stays None.
82
1
    let inner = list(vec![
83
1
        sym("LET"),
84
1
        list(vec![list(vec![sym("x"), Expr::Nil])]),
85
1
        list(vec![sym("CONS"), num(1), sym("x")]),
86
1
    ]);
87
1
    assert_eq!(pinned(&inner, "x"), None);
88
1
}
89

            
90
#[test]
91
1
fn let_initializer_cons_cdr_is_still_outer_scope() {
92
    // (let ((acc (cons 1 acc))) acc) — the init `(cons 1 acc)` references the
93
    // OUTER `acc` (the binding isn't in scope for its own init), so `acc` IS
94
    // a list accumulator. Scanning must reach the init even though the let
95
    // rebinds `acc`.
96
1
    let form = list(vec![
97
1
        sym("LET"),
98
1
        list(vec![list(vec![
99
1
            sym("acc"),
100
1
            list(vec![sym("CONS"), num(1), sym("acc")]),
101
1
        ])]),
102
1
        sym("acc"),
103
1
    ]);
104
1
    assert_eq!(pinned(&form, "acc"), pair(PairElement::I32));
105
1
}
106

            
107
#[test]
108
1
fn dolist_list_expr_cons_cdr_is_outer_scope() {
109
    // (dolist (e (cons 1 acc)) e) — the list expr references outer `acc`.
110
1
    let form = list(vec![
111
1
        sym("DOLIST"),
112
1
        list(vec![sym("e"), list(vec![sym("CONS"), num(1), sym("acc")])]),
113
1
        sym("e"),
114
1
    ]);
115
1
    assert_eq!(pinned(&form, "acc"), pair(PairElement::I32));
116
1
}
117

            
118
#[test]
119
1
fn lambda_binder_shadows_outer_param() {
120
1
    let body = list(vec![
121
1
        list(vec![
122
1
            sym("LAMBDA"),
123
1
            list(vec![sym("x")]),
124
1
            list(vec![sym("CONS"), num(1), sym("x")]),
125
1
        ]),
126
1
        sym("y"),
127
1
    ]);
128
1
    assert_eq!(pinned(&body, "x"), None);
129
1
}
130

            
131
#[test]
132
1
fn short_binder_body_does_not_panic_on_slice() {
133
    // Regression (AFL): a too-short binder form — `(do)`, `(let)`,
134
    // `(lambda)` — used to index `&elems[2..]` / `&elems[1..]` out of range
135
    // and panic. Param inference is best-effort, so a malformed form must
136
    // contribute no pin (return None), never crash.
137
1
    for head in ["DO", "DO*", "LET", "LET*", "DOLIST", "LAMBDA"] {
138
6
        let bare = list(vec![sym(head)]);
139
6
        assert_eq!(pinned(&bare, "x"), None, "bare ({head})");
140
    }
141
    // Nested under a lambda body, mirroring the fuzz-found shape
142
    // `(lambda (s) (do))`.
143
1
    let nested = list(vec![sym("DO")]);
144
1
    assert_eq!(pinned(&nested, "s"), None);
145
1
}
146

            
147
#[test]
148
1
fn literal_car_cells_map_to_their_slots() {
149
1
    assert_eq!(car_cell_element(&num(3)), PairElement::I32);
150
1
    assert_eq!(car_cell_element(&Expr::Nil), PairElement::Bool);
151
1
    assert_eq!(car_cell_element(&Expr::T), PairElement::Bool);
152
1
    assert_eq!(
153
1
        car_cell_element(&Expr::String("s".into())),
154
1
        PairElement::StringRef
155
    );
156
1
    assert_eq!(car_cell_element(&sym("v")), PairElement::AnyRef);
157
1
    assert_eq!(
158
1
        car_cell_element(&Expr::Quote(Box::new(sym("v")))),
159
1
        PairElement::Symbol
160
    );
161
1
    assert_eq!(
162
1
        car_cell_element(&Expr::Keyword("K".into())),
163
1
        PairElement::Symbol
164
    );
165
1
}
166

            
167
#[test]
168
1
fn a_typed_variable_beside_the_param_pins_its_dimension() {
169
1
    let body = list(vec![sym("+"), sym("acc"), sym("k")]);
170
1
    for ty in [WasmType::I32, WasmType::Ratio, WasmType::Commodity] {
171
3
        assert_eq!(pinned_in(&body, "k", &with_local("acc", ty)), Some(ty));
172
    }
173
1
}
174

            
175
#[test]
176
1
fn each_operator_pins_the_dimensions_it_shares() {
177
1
    let additive = ["+", "-", "<", ">", "<=", ">=", "=", "/="];
178
1
    let multiplicative = ["*", "/", "mod"];
179
1
    for (op, ty) in additive
180
1
        .iter()
181
24
        .flat_map(|op| [WasmType::I32, WasmType::Ratio, WasmType::Commodity].map(|ty| (op, ty)))
182
    {
183
24
        let body = list(vec![sym(op), sym("m"), sym("k")]);
184
24
        assert_eq!(
185
24
            pinned_in(&body, "k", &with_local("m", ty)),
186
24
            Some(ty),
187
            "{op}"
188
        );
189
    }
190
1
    for op in multiplicative {
191
3
        for ty in [WasmType::I32, WasmType::Ratio] {
192
6
            let body = list(vec![sym(op), sym("m"), sym("k")]);
193
6
            assert_eq!(
194
6
                pinned_in(&body, "k", &with_local("m", ty)),
195
6
                Some(ty),
196
                "{op}"
197
            );
198
        }
199
3
        let money = list(vec![sym(op), sym("m"), sym("k")]);
200
3
        assert_eq!(
201
3
            pinned_in(&money, "k", &with_local("m", WasmType::Commodity)),
202
3
            None,
203
            "{op}"
204
        );
205
    }
206
1
}
207

            
208
#[test]
209
1
fn a_comparison_pins_like_arithmetic() {
210
1
    let body = list(vec![sym("<"), sym("k"), sym("n")]);
211
1
    assert_eq!(
212
1
        pinned_in(&body, "k", &with_local("n", WasmType::I32)),
213
1
        Some(WasmType::I32)
214
    );
215
1
}
216

            
217
#[test]
218
1
fn a_literal_neighbour_pins_its_kind() {
219
1
    let body = list(vec![sym("+"), sym("k"), num(2)]);
220
1
    assert_eq!(pinned(&body, "k"), Some(WasmType::I32));
221
1
}
222

            
223
#[test]
224
1
fn a_non_numeric_or_unknown_neighbour_never_pins() {
225
1
    let body = list(vec![sym("+"), sym("acc"), sym("k")]);
226
1
    assert_eq!(
227
1
        pinned_in(&body, "k", &with_local("acc", WasmType::StringRef)),
228
1
        None
229
    );
230
1
    assert_eq!(pinned_in(&body, "k", &SymbolTable::new()), None);
231
1
}
232

            
233
#[test]
234
1
fn a_param_not_beside_the_variable_is_not_pinned() {
235
1
    let body = list(vec![
236
1
        sym("+"),
237
1
        sym("acc"),
238
1
        list(vec![sym("*"), sym("k"), list(vec![sym("foo")])]),
239
1
    ]);
240
1
    assert_eq!(
241
1
        pinned_in(&body, "k", &with_local("acc", WasmType::I32)),
242
1
        None
243
    );
244
1
}
245

            
246
#[test]
247
1
fn an_inner_binder_hides_the_neighbour() {
248
1
    let bindings = list(vec![list(vec![sym("acc"), Expr::String("s".into())])]);
249
1
    let inner = list(vec![sym("+"), sym("acc"), sym("k")]);
250
1
    let body = list(vec![sym("let"), bindings, inner]);
251
1
    assert_eq!(
252
1
        pinned_in(&body, "k", &with_local("acc", WasmType::I32)),
253
1
        None
254
    );
255
1
}
256

            
257
#[test]
258
1
fn a_lambda_param_hides_the_neighbour() {
259
1
    let inner = list(vec![sym("+"), sym("acc"), sym("k")]);
260
1
    let body = list(vec![sym("lambda"), list(vec![sym("acc")]), inner]);
261
1
    assert_eq!(
262
1
        pinned_in(&body, "k", &with_local("acc", WasmType::I32)),
263
1
        None
264
    );
265
1
}
266

            
267
#[test]
268
1
fn infer_param_types_hides_the_lambdas_own_params() {
269
1
    let symbols = with_local("acc", WasmType::I32);
270
1
    let body = list(vec![sym("+"), sym("acc"), sym("k")]);
271
1
    let own = LambdaParams::simple(vec!["acc".to_string(), "k".to_string()]);
272
1
    assert_eq!(
273
1
        infer_params(&symbols, &own, &body).types,
274
1
        vec![Some(WasmType::I32); 2]
275
    );
276
1
    let captured = LambdaParams::simple(vec!["k".to_string()]);
277
1
    assert_eq!(
278
1
        infer_params(&symbols, &captured, &body).types,
279
1
        vec![Some(WasmType::I32)]
280
    );
281
1
}
282

            
283
#[test]
284
1
fn infer_param_types_pins_a_param_beside_a_literal_to_its_kind() {
285
1
    let symbols = SymbolTable::new();
286
1
    let params = LambdaParams::simple(vec!["x".to_string()]);
287
1
    let index = list(vec![sym("+"), sym("x"), num(1)]);
288
1
    assert_eq!(
289
1
        infer_params(&symbols, &params, &index).types,
290
1
        vec![Some(WasmType::I32)]
291
    );
292
1
    let half = Expr::Number(Number::Scalar(Fraction::new(1, 2)));
293
1
    let scalar = list(vec![sym("*"), sym("x"), half]);
294
1
    assert_eq!(
295
1
        infer_params(&symbols, &params, &scalar).types,
296
1
        vec![Some(WasmType::Ratio)]
297
    );
298
1
}
299

            
300
#[test]
301
1
fn infer_param_types_leaves_a_param_never_used_numerically_unpinned() {
302
1
    let params = LambdaParams::simple(vec!["x".to_string()]);
303
1
    assert_eq!(
304
1
        infer_params(&SymbolTable::new(), &params, &sym("x")).types,
305
1
        vec![None]
306
    );
307
1
}
308

            
309
#[test]
310
1
fn infer_param_types_pins_a_param_passed_to_a_typed_closure() {
311
1
    let sig = ClosureSigId(0);
312
1
    let mut symbols = with_local("f", WasmType::Closure(sig));
313
1
    symbols.record_closure_params(sig, &[WasmType::I32]);
314
1
    let params = LambdaParams::simple(vec!["y".to_string()]);
315
1
    let body = list(vec![sym("funcall"), sym("f"), sym("y")]);
316
1
    assert_eq!(
317
1
        infer_params(&symbols, &params, &body).types,
318
1
        vec![Some(WasmType::I32)]
319
    );
320
1
}
321

            
322
36
fn form(source: &str) -> Expr {
323
36
    Reader::parse_expr(source).expect("form parses")
324
36
}
325

            
326
9
fn pinned_form(source: &str, name: &str, symbols: &SymbolTable) -> Option<WasmType> {
327
9
    pinned_in(&form(source), &name.to_uppercase(), symbols)
328
9
}
329

            
330
#[test]
331
1
fn a_constant_bound_neighbour_pins_its_kind() {
332
1
    let mut symbols = SymbolTable::new();
333
1
    symbols.define(Symbol::new("A", SymbolKind::Variable).with_value(num(3)));
334
1
    assert_eq!(pinned_form("(+ x a)", "x", &symbols), Some(WasmType::I32));
335
1
}
336

            
337
#[test]
338
1
fn a_compound_operand_is_typed_by_its_result() {
339
1
    let scalar = with_local("R", WasmType::Ratio);
340
1
    assert_eq!(
341
1
        pinned_form("(+ x (* 2/1 r))", "x", &scalar),
342
1
        Some(WasmType::Ratio)
343
    );
344
1
    assert_eq!(
345
1
        pinned_form("(+ 1/1 x r)", "x", &scalar),
346
1
        Some(WasmType::Ratio)
347
    );
348
1
    let money = with_local("M", WasmType::Commodity);
349
1
    assert_eq!(
350
1
        pinned_form("(+ x (* 1/2 m))", "x", &money),
351
1
        Some(WasmType::Commodity)
352
    );
353
1
}
354

            
355
#[test]
356
1
fn a_compound_operand_mentioning_the_param_does_not_type_it() {
357
1
    let scalar = with_local("R", WasmType::Ratio);
358
1
    assert_eq!(pinned_form("(+ x (car x))", "x", &scalar), None);
359
1
}
360

            
361
#[test]
362
1
fn a_self_recursive_factory_ends_in_the_shared_ceiling_error() {
363
1
    for source in [
364
1
        "(defun mk () (lambda (x) (let ((g (mk))) (funcall g x)))) (funcall (mk) 2)",
365
1
        "(defun mk (a) (lambda (x) (let ((g (mk a))) (funcall g x)))) (funcall (mk 1) 2)",
366
1
    ] {
367
2
        let program = Reader::parse(source).expect("parses");
368
2
        let mut symbols = SymbolTable::with_builtins_for_wasm();
369
2
        let result = crate::compiler::Compiler::new().compile(&program, &mut symbols);
370
2
        assert!(
371
2
            matches!(result, Err(crate::error::Error::Resource(_))),
372
            "{source}: {result:?}"
373
        );
374
    }
375
1
}
376

            
377
#[test]
378
1
fn the_pins_its_subject_to_the_type_it_names() {
379
1
    let symbols = SymbolTable::with_builtins();
380
1
    for (source, pin) in [
381
1
        ("(the index x)", Some(WasmType::I32)),
382
1
        ("(the scalar x)", Some(WasmType::Ratio)),
383
1
        (
384
1
            "(list (+ (the scalar x) (length (list 1 x))))",
385
1
            Some(WasmType::Ratio),
386
1
        ),
387
1
        ("(the index y)", None),
388
1
    ] {
389
4
        assert_eq!(pinned_form(source, "x", &symbols), pin, "{source}");
390
    }
391
1
}
392

            
393
18
fn inferred(source: &str, symbols: &SymbolTable) -> Vec<Option<WasmType>> {
394
18
    let Expr::List(parts) = form(source) else {
395
        panic!("{source} is not a list");
396
    };
397
18
    let [_, Expr::List(names), body] = parts.as_slice() else {
398
        panic!("{source} is not a lambda");
399
    };
400
18
    let names = names
401
18
        .iter()
402
25
        .filter_map(|name| match name {
403
25
            Expr::Symbol(name) => Some(name.clone()),
404
            _ => None,
405
25
        })
406
        .collect();
407
18
    infer_params(symbols, &LambdaParams::simple(names), body).types
408
18
}
409

            
410
#[test]
411
1
fn a_parameter_no_use_pins_takes_the_one_dimension_its_body_accepts() {
412
1
    let symbols = SymbolTable::with_builtins();
413
1
    for (source, pins) in [
414
1
        ("(lambda (x) (index->scalar x))", vec![Some(WasmType::I32)]),
415
1
        (
416
1
            "(lambda (x) (scalar->index x))",
417
1
            vec![Some(WasmType::Ratio)],
418
1
        ),
419
1
        ("(lambda (x) (list x))", vec![Some(WasmType::I32)]),
420
1
        ("(lambda (x) (undefined-function x))", vec![None]),
421
1
    ] {
422
4
        assert_eq!(inferred(source, &symbols), pins, "{source}");
423
    }
424
1
}
425

            
426
#[test]
427
1
fn a_pinned_parameter_keeps_its_pin_beside_a_trial_typed_one() {
428
1
    let symbols = SymbolTable::with_builtins();
429
1
    let source = "(lambda (a s) (+ (the scalar s) (index->scalar a)))";
430
1
    assert_eq!(
431
1
        inferred(source, &symbols),
432
1
        vec![Some(WasmType::I32), Some(WasmType::Ratio)]
433
    );
434
1
}
435

            
436
#[test]
437
1
fn trial_typing_reaches_a_parameter_through_a_let_bound_lambda() {
438
1
    let symbols = SymbolTable::with_builtins();
439
1
    let source = "(lambda (x) (let ((f (lambda (v) (index->scalar v)))) (funcall f x)))";
440
1
    assert_eq!(inferred(source, &symbols), vec![Some(WasmType::I32)]);
441
1
}
442

            
443
#[test]
444
1
fn trial_typing_reaches_a_parameter_through_a_let_bound_closure_from_a_list() {
445
1
    let mut symbols = SymbolTable::with_builtins();
446
1
    let held = Expr::Lambda(
447
1
        LambdaParams::simple(vec!["N".to_string()]),
448
1
        Box::new(form("(index->scalar n)")),
449
1
    );
450
1
    symbols.define(
451
1
        Symbol::new("GS", SymbolKind::Variable)
452
1
            .with_value(Expr::Cons(Box::new(held), Box::new(Expr::Nil))),
453
1
    );
454
1
    let source = "(lambda (x) (let ((f (car gs))) (list (funcall f x))))";
455
1
    assert_eq!(inferred(source, &symbols), vec![Some(WasmType::I32)]);
456
1
}
457

            
458
2
fn define(symbols: &mut SymbolTable, (name, kind): (&str, SymbolKind), param: &str, body: &str) {
459
2
    let params = LambdaParams::simple(vec![param.to_string()]);
460
2
    let lambda = Expr::Lambda(params, Box::new(form(body)));
461
2
    symbols.define(Symbol::new(name, kind).with_function(lambda));
462
2
}
463

            
464
#[test]
465
1
fn unpinned_parameters_are_typed_jointly() {
466
1
    let symbols = SymbolTable::with_builtins();
467
1
    for (source, pins) in [
468
1
        (
469
1
            "(lambda (a b) (list a (index->scalar b)))",
470
1
            vec![Some(WasmType::I32); 2],
471
1
        ),
472
1
        (
473
1
            "(lambda (acc x) (+ acc (index->scalar x)))",
474
1
            vec![Some(WasmType::Ratio), Some(WasmType::I32)],
475
1
        ),
476
1
        (
477
1
            "(lambda (a b c d) (list a b c d))",
478
1
            vec![Some(WasmType::I32); 4],
479
1
        ),
480
1
    ] {
481
3
        assert_eq!(inferred(source, &symbols), pins, "{source}");
482
    }
483
1
}
484

            
485
#[test]
486
1
fn money_beside_another_dimension_never_fits() {
487
1
    let symbols = SymbolTable::with_builtins();
488
1
    let source = "(lambda (m s) (list (+ m (the money s))))";
489
1
    assert_eq!(
490
1
        inferred(source, &symbols),
491
1
        vec![Some(WasmType::Commodity), Some(WasmType::Commodity)]
492
    );
493
1
}
494

            
495
#[test]
496
1
fn a_callee_default_takes_its_literals_kind_in_a_trial() {
497
1
    let mut symbols = SymbolTable::with_builtins();
498
1
    let params = LambdaParams {
499
1
        required: vec!["N".to_string()],
500
1
        optional: vec![("K".to_string(), Some(num(1)))],
501
1
        ..LambdaParams::simple(Vec::new())
502
1
    };
503
1
    let lambda = Expr::Lambda(params, Box::new(form("(+ n k)")));
504
1
    symbols.define(Symbol::new("HD", SymbolKind::Function).with_function(lambda));
505
1
    assert_eq!(
506
1
        inferred("(lambda (x) (list (hd x)))", &symbols),
507
1
        vec![Some(WasmType::I32)]
508
    );
509
1
}
510

            
511
#[test]
512
1
fn trial_typing_reaches_a_parameter_through_its_callee() {
513
1
    let mut symbols = SymbolTable::with_builtins();
514
1
    define(
515
1
        &mut symbols,
516
1
        ("H", SymbolKind::Function),
517
1
        "Y",
518
1
        "(index->scalar y)",
519
1
    );
520
1
    define(
521
1
        &mut symbols,
522
1
        ("DBL", SymbolKind::Macro),
523
1
        "V",
524
1
        "`(index->scalar ,v)",
525
1
    );
526
1
    for source in [
527
1
        "(lambda (x) (h x))",
528
1
        "(lambda (x) (funcall #'h x))",
529
1
        "(lambda (x) (dbl x))",
530
1
        "(lambda (x) (labels ((g (y) (index->scalar y))) (g x)))",
531
1
        "(lambda (x) (let ((v x)) (index->scalar v)))",
532
1
    ] {
533
5
        assert_eq!(
534
5
            inferred(source, &symbols),
535
5
            vec![Some(WasmType::I32)],
536
            "{source}"
537
        );
538
    }
539
1
}
540

            
541
#[test]
542
1
fn a_probe_out_of_its_budget_pins_nothing() {
543
1
    let mut symbols = SymbolTable::with_builtins();
544
25
    while symbols.enter_shared_recursion().is_ok() {}
545
1
    assert_eq!(
546
1
        inferred("(lambda (x) (index->scalar x))", &symbols),
547
1
        vec![None]
548
    );
549
1
}
550

            
551
#[test]
552
1
fn only_a_parameter_several_dimensions_fit_is_ambiguous() {
553
1
    let symbols = SymbolTable::with_builtins();
554
1
    let params = LambdaParams::simple(vec!["A".to_string(), "B".to_string()]);
555
1
    let body = form("(list a (index->scalar b))");
556
1
    assert_eq!(
557
1
        infer_params(&symbols, &params, &body).ambiguous,
558
1
        vec![true, false]
559
    );
560
1
}
561

            
562
#[test]
563
1
fn four_unpinned_parameters_are_trial_typed_and_five_are_not() {
564
1
    let symbols = SymbolTable::with_builtins();
565
1
    let four = LambdaParams::simple(["A", "B", "C", "D"].map(String::from).to_vec());
566
1
    let found = infer_params(&symbols, &four, &form("(list a b c d)"));
567
1
    assert_eq!(found.types, vec![Some(WasmType::I32); 4]);
568
1
    assert_eq!(found.ambiguous, vec![true; 4]);
569
1
    let five = LambdaParams::simple(["A", "B", "C", "D", "E"].map(String::from).to_vec());
570
1
    let found = infer_params(&symbols, &five, &form("(list a b c d e)"));
571
1
    assert_eq!(found.types, vec![None; 5]);
572
1
    assert_eq!(found.ambiguous, vec![true; 5]);
573
1
}
574

            
575
#[test]
576
1
fn a_first_fit_placeholder_is_no_type_evidence() {
577
1
    let symbols = SymbolTable::with_builtins();
578
1
    let params = LambdaParams::simple(vec!["X".to_string()]);
579
1
    assert!(!has_type_evidence(&symbols, &params, &form("(list x)"), 0));
580
1
    assert!(has_type_evidence(
581
1
        &symbols,
582
1
        &params,
583
1
        &form("(index->scalar x)"),
584
1
        0
585
1
    ));
586
1
}