fixed bugs

signature
pca006132 2021-01-08 16:54:34 +08:00
parent ebe1027ffa
commit 3ecf57a588
1 changed files with 12 additions and 5 deletions

View File

@ -137,11 +137,15 @@ pub fn get_typenames<'b: 'a, 'a>(stmts: &'b [Statement]) -> (Vec<&'a str>, Vec<&
fn resolve_function<'b: 'a, 'a>(
ctx: &'a TopLevelContext,
fun: &'b StatementType,
method: bool,
) -> Result<FnDef, String> {
if let StatementType::FunctionDef { args, returns, .. } = &fun {
let args = if method {
args.args[1..].iter()
} else {
args.args.iter()
};
let args: Result<Vec<_>, _> = args
.args
.iter()
.map(|arg| type_from_expr(ctx, &arg.annotation.as_ref().unwrap().node))
.collect();
let args = args?;
@ -155,7 +159,7 @@ fn resolve_function<'b: 'a, 'a>(
}
}
pub fn resolve_signatures<'b: 'a, 'a>(ctx: &'a mut TopLevelContext<'a>, stmts: &'b [Statement]) {
pub fn resolve_signatures<'b: 'a, 'a>(ctx: &mut TopLevelContext<'a>, stmts: &'b [Statement]) {
for stmt in stmts.iter() {
match &stmt.node {
StatementType::ClassDef {
@ -186,7 +190,10 @@ pub fn resolve_signatures<'b: 'a, 'a>(ctx: &'a mut TopLevelContext<'a>, stmts: &
fields.insert(name, ty);
}
StatementType::FunctionDef { name, .. } => {
functions.insert(&name[..], resolve_function(ctx, &stmt.node).unwrap());
functions.insert(
&name[..],
resolve_function(ctx, &stmt.node, true).unwrap(),
);
}
_ => unimplemented!(),
}
@ -203,7 +210,7 @@ pub fn resolve_signatures<'b: 'a, 'a>(ctx: &'a mut TopLevelContext<'a>, stmts: &
class.base.methods.clone_from(&functions);
}
StatementType::FunctionDef { name, .. } => {
ctx.add_fn(&name[..], resolve_function(ctx, &stmt.node).unwrap());
ctx.add_fn(&name[..], resolve_function(ctx, &stmt.node, false).unwrap());
}
_ => unimplemented!(),
}