• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

TyRoXx / NonlocalityOS / 14954402571

11 May 2025 09:23AM UTC coverage: 72.054% (+0.03%) from 72.022%
14954402571

push

github

TyRoXx
GH-248: Add brace syntax for expression disambiguation

45 of 53 new or added lines in 2 files covered. (84.91%)

7 existing lines in 2 files now uncovered.

3161 of 4387 relevant lines covered (72.05%)

2254.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.44
/lambda_compiler/src/type_checking.rs
1
use crate::{ast, compilation::CompilerOutput};
2
use astraea::{
3
    storage::{StoreError, StoreTree},
4
    tree::{HashedTree, Tree},
5
};
6
use lambda::name::{Name, NamespaceId};
7
use std::sync::Arc;
8

9
pub fn combine_parameter_names(parameter_names: &[Name], namespace_id: &NamespaceId) -> Name {
16✔
10
    let mut combined = String::new();
16✔
11
    for name in parameter_names {
36✔
12
        if !combined.is_empty() {
2✔
13
            combined.push('_');
2✔
14
        }
15
        combined.push_str(&name.key);
16
    }
17
    Name::new(*namespace_id, combined)
16✔
18
}
19

20
async fn check_tree_construction_or_argument_list(
9✔
21
    arguments: &[ast::Expression],
22
    generated_name_namespace: &NamespaceId,
23
    storage: &dyn StoreTree,
24
) -> Result<CompilerOutput, StoreError> {
25
    let mut errors = Vec::new();
9✔
26
    let mut checked_arguments = Vec::new();
9✔
27
    for argument in arguments {
25✔
28
        let output = Box::pin(check_types(argument, generated_name_namespace, storage)).await?;
16✔
29
        errors.extend(output.errors);
30
        if let Some(checked) = output.entry_point {
8✔
31
            checked_arguments.push(Arc::new(checked));
32
        } else {
NEW
33
            return Ok(CompilerOutput::new(None, errors));
×
34
        }
35
    }
36
    Ok(CompilerOutput {
9✔
37
        entry_point: Some(lambda::expressions::DeepExpression(
9✔
38
            lambda::expressions::Expression::ConstructTree(checked_arguments),
9✔
39
        )),
40
        errors,
9✔
41
    })
42
}
43

44
pub async fn check_types(
37✔
45
    syntax_tree: &ast::Expression,
46
    generated_name_namespace: &NamespaceId,
47
    storage: &dyn StoreTree,
48
) -> Result<CompilerOutput, StoreError> {
49
    match syntax_tree {
37✔
50
        ast::Expression::Identifier(name) => Ok(CompilerOutput::new(
8✔
51
            Some(lambda::expressions::DeepExpression(
8✔
52
                lambda::expressions::Expression::ReadVariable(name.clone()),
8✔
53
            )),
54
            Vec::new(),
8✔
55
        )),
56
        ast::Expression::StringLiteral(value) => Ok(CompilerOutput::new(
12✔
57
            Some(lambda::expressions::DeepExpression(
58
                lambda::expressions::Expression::Literal(
59
                    storage
6✔
60
                        .store_tree(&HashedTree::from(Arc::new(
6✔
61
                            Tree::from_string(value).unwrap(/*TODO*/),
6✔
62
                        )))
63
                        .await?,
6✔
64
                ),
65
            )),
66
            Vec::new(),
67
        )),
68
        ast::Expression::Apply { callee, arguments } => {
2✔
69
            let callee_output =
2✔
70
                Box::pin(check_types(callee, generated_name_namespace, storage)).await?;
2✔
71
            // TODO: optimize by special casing N=1 to avoid indirection
72
            let argument_output = Box::pin(check_tree_construction_or_argument_list(
2✔
73
                &arguments[..],
74
                generated_name_namespace,
75
                storage,
76
            ))
NEW
77
            .await?;
×
78
            let errors = callee_output
79
                .errors
80
                .into_iter()
81
                .chain(argument_output.errors)
82
                .collect();
83
            match (callee_output.entry_point, argument_output.entry_point) {
84
                (Some(callee_checked), Some(argument_checked)) => Ok(CompilerOutput {
2✔
85
                    entry_point: Some(lambda::expressions::DeepExpression(
2✔
86
                        lambda::expressions::Expression::Apply {
2✔
87
                            callee: Arc::new(callee_checked),
2✔
88
                            argument: Arc::new(argument_checked),
2✔
89
                        },
90
                    )),
91
                    errors,
2✔
92
                }),
93
                (None, _) | (_, None) => Ok(CompilerOutput::new(None, errors)),
×
94
            }
95
        }
96
        ast::Expression::Lambda {
97
            parameter_names,
13✔
98
            body,
13✔
99
        } => {
100
            let body_output =
13✔
101
                Box::pin(check_types(body, generated_name_namespace, storage)).await?;
13✔
102
            match body_output.entry_point {
103
                Some(body_checked) => Ok(CompilerOutput {
13✔
104
                    entry_point: Some(lambda::expressions::DeepExpression(
13✔
105
                        lambda::expressions::Expression::Lambda {
13✔
106
                            parameter_name: combine_parameter_names(
13✔
107
                                &parameter_names[..],
13✔
108
                                generated_name_namespace,
13✔
109
                            ),
110
                            body: Arc::new(body_checked),
13✔
111
                        },
112
                    )),
113
                    errors: body_output.errors,
13✔
114
                }),
115
                None => Ok(CompilerOutput::new(None, body_output.errors)),
×
116
            }
117
        }
118
        ast::Expression::ConstructTree(arguments) => {
7✔
119
            check_tree_construction_or_argument_list(
120
                &arguments[..],
7✔
121
                generated_name_namespace,
7✔
122
                storage,
7✔
123
            )
124
            .await
7✔
125
        }
126
        ast::Expression::Braces(expression) => {
1✔
127
            let output =
1✔
128
                Box::pin(check_types(expression, generated_name_namespace, storage)).await?;
1✔
129
            Ok(output)
130
        }
131
    }
132
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc