fix return error

This commit is contained in:
nora 2021-10-31 21:04:46 +01:00
parent 53c2cdb085
commit 131229686a
3 changed files with 22 additions and 9 deletions

View file

@ -19,7 +19,7 @@ pub fn run_program(program: &str) {
let ast = parse::parse(tokens);
match ast {
Ok(ast) => println!("{:#?}", ast),
Ok(ast) => println!("{:?}", ast),
Err(err) => errors::display_error(program, err),
}
} else {

View file

@ -103,7 +103,11 @@ impl<'code> Parser<'code> {
let keyword_span = self.expect(TokenType::Fn)?.span;
let name = self.ident()?;
let args = self.fn_args()?;
self.inside_fn_depth += 1;
let body = self.block()?;
self.inside_fn_depth -= 1;
Ok(Stmt::FnDecl(FnDecl {
span: keyword_span.extend(body.span),
name,

25
test.sl
View file

@ -1,9 +1,18 @@
fn test() {
if true {
print;
} else if false {
dont_print;
} else {
"uwu";
fn fizzbuzz() {
let i = 0;
while i < 100 {
# don't have function calls yet :(
}
}
}
fn single_fizzbuzz(n) {
if n % 15 == 0 {
return "FizzBuzz";
} else if n % 5 == 0 {
return "Buzz";
} else if n % 3 == 0 {
return "Fizz";
} else {
return n;
}
}