1
//! Diverging IF / HANDLER-CASE arms and runtime COND tests whose dead residue
2
//! (a value compiled after the `throw`/`br`) must not reach the enclosing
3
//! `else`/`end`. The frame seals it there when it reads the arm dead; an
4
//! UNWIND-PROTECT whose body raises is the subset where the frame sees the
5
//! arm live, so only the client seals (`compile_arm`, the runtime COND chain)
6
//! keep it valid (plan 0014 slices 4.0c-1b, 4.0c-2, 4.0c-3a).
7

            
8
use super::common::compile_and_validate;
9

            
10
const RAISING: &str = r#"(unwind-protect (error 'boom "m") 1)"#;
11

            
12
14
fn validates_top_level_and_let_bound(form: &str) {
13
14
    compile_and_validate(form);
14
14
    compile_and_validate(&format!("(let ((v {form})) v)"));
15
14
}
16

            
17
#[test]
18
1
fn an_if_arm_is_sealed_by_compile_arm() {
19
1
    validates_top_level_and_let_bound(&format!(r#"(if (> (entity-count) 5) "s" {RAISING})"#));
20
1
}
21

            
22
#[test]
23
1
fn an_if_arm_whose_eager_call_argument_raises_is_sealed_by_compile_arm() {
24
1
    validates_top_level_and_let_bound(&format!(r#"(if (> (entity-count) 5) "s" (+ 1 {RAISING}))"#));
25
1
}
26

            
27
#[test]
28
1
fn a_handler_case_body_is_sealed_by_compile_arm() {
29
1
    validates_top_level_and_let_bound(&format!(r#"(handler-case {RAISING} (boom (e) "x"))"#));
30
1
}
31

            
32
#[test]
33
1
fn a_handler_case_body_whose_eager_call_argument_raises_is_sealed_by_compile_arm() {
34
1
    validates_top_level_and_let_bound(&format!(r#"(handler-case (+ 1 {RAISING}) (boom (e) "x"))"#));
35
1
}
36

            
37
#[test]
38
1
fn a_runtime_cond_test_is_sealed_by_the_chain() {
39
1
    validates_top_level_and_let_bound(&format!(
40
1
        r#"(cond ((> (entity-count) 5) "s") ({RAISING} "t") (t "u"))"#
41
1
    ));
42
1
}
43

            
44
#[test]
45
1
fn a_runtime_cond_test_whose_eager_call_argument_raises_is_sealed_by_the_chain() {
46
1
    validates_top_level_and_let_bound(&format!(
47
1
        r#"(cond ((> (entity-count) 5) "s") ((+ 1 {RAISING}) "t"))"#
48
1
    ));
49
1
}
50

            
51
/// ISS-160, like the COND clause below.
52
#[test]
53
1
fn an_if_arm_with_a_value_after_its_error_is_sealed_by_the_frame() {
54
1
    validates_top_level_and_let_bound(
55
1
        r#"(if (> (entity-count) 5) "s" (progn (error 'boom "m") 1))"#,
56
1
    );
57
1
}
58

            
59
/// ISS-160: the top-level spelling's diverging arm is cleared by the frame's
60
/// pre-`end` seal.
61
#[test]
62
1
fn a_cond_clause_with_a_value_after_its_error_is_sealed_by_the_frame() {
63
1
    validates_top_level_and_let_bound(
64
1
        r#"(cond ((> (entity-count) 5) "s") (t (error 'boom "m") 1))"#,
65
1
    );
66
1
}
67

            
68
/// ISS-160's then-arm spelling: the chain's `br` to its typed block would
69
/// consume the residue before any boundary seal, so it is skipped.
70
#[test]
71
1
fn an_if_then_arm_with_a_value_after_its_error_takes_no_branch() {
72
1
    validates_top_level_and_let_bound(
73
1
        r#"(if (> (entity-count) 5) (progn (error 'boom "m") 1) "s")"#,
74
1
    );
75
1
}
76

            
77
/// ISS-160's non-tail COND clause, the same `br` as the then arm.
78
#[test]
79
1
fn a_non_tail_cond_clause_with_a_value_after_its_error_takes_no_branch() {
80
1
    validates_top_level_and_let_bound(
81
1
        r#"(cond ((> (entity-count) 5) (error 'boom "m") 1) (t "s"))"#,
82
1
    );
83
1
}
84

            
85
#[test]
86
1
fn an_if_arm_adding_to_an_error_is_sealed_by_the_frame() {
87
1
    validates_top_level_and_let_bound(r#"(if (> (entity-count) 5) "s" (+ 1 (error 'boom "m")))"#);
88
1
}
89

            
90
#[test]
91
1
fn an_if_arm_adding_to_a_return_from_is_sealed_by_the_frame() {
92
1
    validates_top_level_and_let_bound(
93
1
        r#"(block b (if (> (entity-count) 5) "s" (+ 1 (return-from b "q"))))"#,
94
1
    );
95
1
}
96

            
97
#[test]
98
1
fn a_handler_case_body_adding_to_an_error_is_sealed_by_the_frame() {
99
1
    validates_top_level_and_let_bound(r#"(handler-case (+ 1 (error 'boom "m")) (boom (e) "x"))"#);
100
1
}
101

            
102
#[test]
103
1
fn a_runtime_cond_test_with_a_value_after_its_error_is_sealed_by_the_frame() {
104
1
    validates_top_level_and_let_bound(
105
1
        r#"(cond ((> (entity-count) 5) "s") ((progn (error 'boom "m") 1) "t"))"#,
106
1
    );
107
1
}