diff --git a/nac3core/src/type_check/signature.rs b/nac3core/src/type_check/signature.rs index 1383cfb868..32654b78d5 100644 --- a/nac3core/src/type_check/signature.rs +++ b/nac3core/src/type_check/signature.rs @@ -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 { if let StatementType::FunctionDef { args, returns, .. } = &fun { + let args = if method { + args.args[1..].iter() + } else { + args.args.iter() + }; let args: Result, _> = 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!(), }