Skip to content

Commit

Permalink
Finished basic namespace resolution for functions
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacShelton committed Sep 20, 2024
1 parent c4dd3e6 commit 77fda01
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl Display for ResolvedName {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ResolvedName::Remote(name) => write!(f, "<remote>/{}", name),
ResolvedName::Project(name) => write!(f, "<project>/{}", name),
ResolvedName::Project(name) => write!(f, "{}", name),
}
}
}
13 changes: 12 additions & 1 deletion src/resolve/expr/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,18 @@ pub fn resolve_call_expr(
.at(source));
}

let resolved_name = ResolvedName::Project(call.function_name.basename.clone().into_boxed_str());
eprintln!("warning: function call name resolution not fully implemented yet");
let resolved_name = if !call.function_name.namespace.is_empty() {
ResolvedName::Project(
format!(
"{}{}",
call.function_name.namespace, call.function_name.basename
)
.into_boxed_str(),
)
} else {
ResolvedName::Project(call.function_name.basename.clone().into_boxed_str())
};

let Some(function_ref) = ctx.function_search_ctx.find_function(&resolved_name) else {
return Err(ResolveErrorKind::FailedToFindFunction {
Expand Down
6 changes: 2 additions & 4 deletions src/resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ pub fn resolve<'a>(
};

let function_ref = resolved_ast.functions.insert(resolved::Function {
name,
name: name.clone(),
parameters: resolve_parameters(
type_search_ctx,
source_files,
Expand Down Expand Up @@ -285,11 +285,9 @@ pub fn resolve<'a>(
.function_search_ctxs
.get_or_insert_with(file_id, || FunctionSearchCtx::new());

let resolved_name = ResolvedName::Project(function.name.clone().into_boxed_str());

function_search_context
.available
.entry(resolved_name)
.entry(name)
.or_insert_with(|| vec![function_ref]);
}
}
Expand Down

0 comments on commit 77fda01

Please sign in to comment.