diff --git a/src/modules/imports/import.rs b/src/modules/imports/import.rs index bf264aca..22640a80 100644 --- a/src/modules/imports/import.rs +++ b/src/modules/imports/import.rs @@ -20,22 +20,39 @@ pub struct Import { } impl Import { - fn handle_export(&mut self, meta: &mut ParserMetadata, pub_funs: Vec) -> SyntaxResult { - for mut fun in pub_funs { - if !self.is_all { - match self.export_defs.iter().find(|(name, ..)| fun.name == *name) { - Some((_, Some(alias), _)) => fun.name = alias.clone(), - Some((_, None, _)) => (), - None => continue, + fn handle_export(&mut self, meta: &mut ParserMetadata, mut pub_funs: Vec) -> SyntaxResult { + if !self.is_all { + for def in self.export_defs.iter() { + let (name, alias, tok) = def.clone(); + let fun = match pub_funs.iter_mut().find(|fun| fun.name == name) { + Some(fun) => fun, + // Check if the function that is being imported is defined + None => return error!(meta, tok.clone() => { + message: format!("Function '{}' is not defined", name) + }) + }; + if let Some(alias) = alias { + fun.name = alias; + } + fun.is_public = self.is_pub; + let name = fun.name.clone(); + // Check if current function name is already defined + if meta.add_fun_declaration_existing(fun.clone()).is_none() { + return error!(meta, self.token_import.clone() => { + message: format!("Function '{}' is already defined", name) + }) } } - // Determine if imported functions should be exported further - fun.is_public = self.is_pub; - let name = fun.name.clone(); - if meta.add_fun_declaration_existing(fun).is_none() { - return error!(meta, self.token_import.clone() => { - message: format!("Function '{}' is already defined", name) - }) + } else { + for mut fun in pub_funs { + // Determine if imported functions should be exported further + fun.is_public = self.is_pub; + let name = fun.name.clone(); + if meta.add_fun_declaration_existing(fun).is_none() { + return error!(meta, self.token_import.clone() => { + message: format!("Function '{}' is already defined", name) + }) + } } } Ok(()) diff --git a/src/std/main.ab b/src/std/main.ab index 273cd6d3..f00481a8 100644 --- a/src/std/main.ab +++ b/src/std/main.ab @@ -86,7 +86,7 @@ pub fun sum(list: [Num]): Num { return unsafe $echo "{list}" | awk '\{s=0; for (i=1; i<=NF; i++) s+=\$i; print s}'$ as Num } -pub fun hasFailed(command: Text): Bool { +pub fun has_failed(command: Text): Bool { unsafe silent $eval {command}$ return status != 0 }