-
Notifications
You must be signed in to change notification settings - Fork 499
/
unresolved_recipe.rs
63 lines (58 loc) · 1.68 KB
/
unresolved_recipe.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use super::*;
pub(crate) type UnresolvedRecipe<'src> = Recipe<'src, UnresolvedDependency<'src>>;
impl<'src> UnresolvedRecipe<'src> {
pub(crate) fn resolve(
self,
resolved: Vec<Rc<Recipe<'src>>>,
) -> CompileResult<'src, Recipe<'src>> {
assert_eq!(
self.dependencies.len(),
resolved.len(),
"UnresolvedRecipe::resolve: dependency count not equal to resolved count: {} != {}",
self.dependencies.len(),
resolved.len()
);
for (unresolved, resolved) in self.dependencies.iter().zip(&resolved) {
assert_eq!(unresolved.recipe.lexeme(), resolved.name.lexeme());
if !resolved
.argument_range()
.contains(&unresolved.arguments.len())
{
return Err(
unresolved
.recipe
.error(CompileErrorKind::DependencyArgumentCountMismatch {
dependency: unresolved.recipe.lexeme(),
found: unresolved.arguments.len(),
min: resolved.min_arguments(),
max: resolved.max_arguments(),
}),
);
}
}
let dependencies = self
.dependencies
.into_iter()
.zip(resolved)
.map(|(unresolved, resolved)| Dependency {
recipe: resolved,
arguments: unresolved.arguments,
})
.collect();
Ok(Recipe {
attributes: self.attributes,
body: self.body,
dependencies,
doc: self.doc,
file_depth: self.file_depth,
import_offsets: self.import_offsets,
name: self.name,
namepath: self.namepath,
parameters: self.parameters,
priors: self.priors,
private: self.private,
quiet: self.quiet,
shebang: self.shebang,
})
}
}