Skip to content

Commit

Permalink
Merge pull request #60 from Ph0enixKM/A91
Browse files Browse the repository at this point in the history
A91 Import error when imported symbol that does not exist
  • Loading branch information
Ph0enixKM committed Nov 6, 2023
2 parents 356a435 + 2219d93 commit 8d3f92a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
45 changes: 31 additions & 14 deletions src/modules/imports/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,39 @@ pub struct Import {
}

impl Import {
fn handle_export(&mut self, meta: &mut ParserMetadata, pub_funs: Vec<FunctionDecl>) -> 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<FunctionDecl>) -> 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(())
Expand Down
2 changes: 1 addition & 1 deletion src/std/main.ab
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 8d3f92a

Please sign in to comment.