improve do & recur errs
This commit is contained in:
parent
4c9659271b
commit
e9b52e1488
|
@ -167,10 +167,7 @@ pub fn run(src: &'static str) {
|
|||
|
||||
pub fn main() {
|
||||
let src = "
|
||||
match foo with {
|
||||
:a -> :b
|
||||
:c -> :d
|
||||
}
|
||||
do 42 > recur ()
|
||||
";
|
||||
run(src);
|
||||
// struct_scalpel::print_dissection_info::<value::Value>()
|
||||
|
|
|
@ -282,6 +282,8 @@ impl<'a> Validator<'a> {
|
|||
self.ast = expr;
|
||||
self.span = *span;
|
||||
self.validate();
|
||||
|
||||
//TODO: check arity of call
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
@ -389,13 +391,25 @@ impl<'a> Validator<'a> {
|
|||
self.validate();
|
||||
self.status.tail_position = tailpos;
|
||||
}
|
||||
// TODO: fix the tail call here?
|
||||
Ast::Do(terms) => {
|
||||
for term in terms {
|
||||
if terms.len() < 2 {
|
||||
return self.err("do expressions must have at least two terms".to_string());
|
||||
}
|
||||
for term in terms.iter().take(terms.len() - 1) {
|
||||
let (expr, span) = term;
|
||||
self.ast = expr;
|
||||
self.span = *span;
|
||||
self.validate();
|
||||
}
|
||||
|
||||
let (expr, span) = terms.last().unwrap();
|
||||
self.ast = expr;
|
||||
self.span = *span;
|
||||
if matches!(expr, Ast::Recur(_)) {
|
||||
self.err("`recur` may not be used in `do` forms".to_string());
|
||||
}
|
||||
self.validate();
|
||||
}
|
||||
Ast::Repeat(times, body) => {
|
||||
self.status.tail_position = false;
|
||||
|
@ -427,7 +441,8 @@ impl<'a> Validator<'a> {
|
|||
}
|
||||
Ast::Recur(args) => {
|
||||
if !self.status.in_loop {
|
||||
self.err("you may only use `recur` in a loop form".to_string());
|
||||
self.err("you may only use `recur` in a `loop` form".to_string());
|
||||
return;
|
||||
}
|
||||
if !self.status.tail_position {
|
||||
self.err("you may only use `recur` in tail position".to_string());
|
||||
|
|
Loading…
Reference in New Issue
Block a user