forked from M-Labs/nac3
fixed bugs
This commit is contained in:
parent
ebe1027ffa
commit
3ecf57a588
|
@ -137,11 +137,15 @@ pub fn get_typenames<'b: 'a, 'a>(stmts: &'b [Statement]) -> (Vec<&'a str>, Vec<&
|
||||||
fn resolve_function<'b: 'a, 'a>(
|
fn resolve_function<'b: 'a, 'a>(
|
||||||
ctx: &'a TopLevelContext,
|
ctx: &'a TopLevelContext,
|
||||||
fun: &'b StatementType,
|
fun: &'b StatementType,
|
||||||
|
method: bool,
|
||||||
) -> Result<FnDef, String> {
|
) -> Result<FnDef, String> {
|
||||||
if let StatementType::FunctionDef { args, returns, .. } = &fun {
|
if let StatementType::FunctionDef { args, returns, .. } = &fun {
|
||||||
|
let args = if method {
|
||||||
|
args.args[1..].iter()
|
||||||
|
} else {
|
||||||
|
args.args.iter()
|
||||||
|
};
|
||||||
let args: Result<Vec<_>, _> = args
|
let args: Result<Vec<_>, _> = args
|
||||||
.args
|
|
||||||
.iter()
|
|
||||||
.map(|arg| type_from_expr(ctx, &arg.annotation.as_ref().unwrap().node))
|
.map(|arg| type_from_expr(ctx, &arg.annotation.as_ref().unwrap().node))
|
||||||
.collect();
|
.collect();
|
||||||
let args = args?;
|
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() {
|
for stmt in stmts.iter() {
|
||||||
match &stmt.node {
|
match &stmt.node {
|
||||||
StatementType::ClassDef {
|
StatementType::ClassDef {
|
||||||
|
@ -186,7 +190,10 @@ pub fn resolve_signatures<'b: 'a, 'a>(ctx: &'a mut TopLevelContext<'a>, stmts: &
|
||||||
fields.insert(name, ty);
|
fields.insert(name, ty);
|
||||||
}
|
}
|
||||||
StatementType::FunctionDef { name, .. } => {
|
StatementType::FunctionDef { name, .. } => {
|
||||||
functions.insert(&name[..], resolve_function(ctx, &stmt.node).unwrap());
|
functions.insert(
|
||||||
|
&name[..],
|
||||||
|
resolve_function(ctx, &stmt.node, true).unwrap(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
|
@ -203,7 +210,7 @@ pub fn resolve_signatures<'b: 'a, 'a>(ctx: &'a mut TopLevelContext<'a>, stmts: &
|
||||||
class.base.methods.clone_from(&functions);
|
class.base.methods.clone_from(&functions);
|
||||||
}
|
}
|
||||||
StatementType::FunctionDef { name, .. } => {
|
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!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue