Working type checker with functions
This commit is contained in:
+2
-14
@@ -11,27 +11,15 @@ pub fn walk_ast(top_scope: Arc<Scope>, tl: &mut Vec<parser::ast::TopLevel>) {
|
|||||||
match tl {
|
match tl {
|
||||||
parser::ast::TopLevel::Import(_) => unimplemented!(),
|
parser::ast::TopLevel::Import(_) => unimplemented!(),
|
||||||
|
|
||||||
parser::ast::TopLevel::FunctionDecl {
|
parser::ast::TopLevel::FunctionDecl { params, body, .. } => {
|
||||||
export,
|
|
||||||
name,
|
|
||||||
params,
|
|
||||||
return_type,
|
|
||||||
body,
|
|
||||||
} => {
|
|
||||||
let scope = LocalScope::new(top_scope.clone());
|
let scope = LocalScope::new(top_scope.clone());
|
||||||
|
|
||||||
scope.with_params(params);
|
scope.with_params(params);
|
||||||
|
|
||||||
scope.with_block(body);
|
scope.with_block(body);
|
||||||
|
|
||||||
println!("{:?}", scope);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parser::ast::TopLevel::StructDecl {
|
parser::ast::TopLevel::StructDecl { .. } => {}
|
||||||
export,
|
|
||||||
name,
|
|
||||||
fields,
|
|
||||||
} => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,6 +92,13 @@ impl LocalScope {
|
|||||||
}
|
}
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
},
|
},
|
||||||
|
Postfix::Call(_args) => match &*current_type {
|
||||||
|
TypeRef::Function(s) => {
|
||||||
|
// TODO: arg checking
|
||||||
|
current_type = s.return_type.clone()?;
|
||||||
|
}
|
||||||
|
_ => unimplemented!(),
|
||||||
|
},
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -3,7 +3,7 @@ struct Test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function add() {
|
function add() {
|
||||||
let output = test().x;
|
let output = test();
|
||||||
}
|
}
|
||||||
|
|
||||||
function test(): Test { }
|
function test(): int { }
|
||||||
Reference in New Issue
Block a user