1
//! The home type of a DO variable: its init joined with the hint the previous
2
//! attempt's refused stores left.
3

            
4
use crate::ast::{PairElement, WasmType};
5
use crate::compiler::join::Arm;
6
use crate::error::Error;
7

            
8
use super::super::binding::var_home_type;
9

            
10
#[test]
11
1
fn a_nil_init_var_joins_the_type_its_step_gives() {
12
1
    let step = || Ok(Some(WasmType::I32));
13
1
    assert_eq!(
14
1
        var_home_type(Arm::Nil, None, step).expect("home"),
15
1
        WasmType::AnyRef
16
    );
17
1
    assert_eq!(
18
1
        var_home_type(Arm::Nil, None, || Ok(Some(WasmType::PairRef(
19
1
            PairElement::I32
20
1
        ))))
21
1
        .expect("home"),
22
1
        WasmType::PairRef(PairElement::I32)
23
    );
24
1
}
25

            
26
#[test]
27
1
fn a_hint_widens_the_home_of_a_literal_init() {
28
    let unsized_step = || Err(Error::Compile("not asked".to_string()));
29
1
    let literal = Arm::NumberLiteral(WasmType::I32);
30
1
    assert_eq!(
31
1
        var_home_type(literal, Some(WasmType::Ratio), unsized_step).expect("home"),
32
1
        WasmType::Ratio
33
    );
34
1
    assert_eq!(
35
1
        var_home_type(literal, None, unsized_step).expect("home"),
36
1
        WasmType::I32
37
    );
38
1
    assert_eq!(
39
1
        var_home_type(
40
1
            Arm::Value(WasmType::I32),
41
1
            Some(WasmType::Ratio),
42
1
            unsized_step
43
1
        )
44
1
        .expect("home"),
45
1
        WasmType::AnyRef
46
    );
47
1
}