Skip to content

Commit

Permalink
Simplify resolve_symbol_and_mod_path.
Browse files Browse the repository at this point in the history
  • Loading branch information
tritao committed Oct 26, 2024
1 parent a36c607 commit 0171c70
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions sway-core/src/semantic_analysis/type_resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ pub fn resolve_qualified_call_path(
subst_ctx: &SubstTypesContext,
check_visibility: VisibilityCheck,
) -> Result<ResolvedDeclaration, ErrorEmitted> {
// println!("resolve_qualified_call_path {:?}", qualified_call_path);

let type_engine = engines.te();
if let Some(qualified_path_root) = qualified_call_path.clone().qualified_path_root {
let root_type_id = match &&*type_engine.get(qualified_path_root.ty.type_id) {
Expand Down Expand Up @@ -319,7 +321,7 @@ pub fn resolve_call_path(
.cloned()
.collect();

let (decl, mod_path) = resolve_symbol_and_mod_path(
let decl = resolve_symbol(
handler,
engines,
&root.module,
Expand Down Expand Up @@ -366,19 +368,25 @@ pub fn resolve_call_path(
Ok(decl)
}

fn resolve_symbol_and_mod_path(
fn resolve_symbol(
handler: &Handler,
engines: &Engines,
module: &Module,
mod_path: &ModulePath,
symbol: &Ident,
self_type: Option<TypeId>,
) -> Result<(ResolvedDeclaration, Vec<Ident>), ErrorEmitted> {
) -> Result<ResolvedDeclaration, ErrorEmitted> {
// println!("resolve_symbol_and_mod_path");
// println!(" => mod_path: {:?}", mod_path);
// println!(" => symbol: {:?}", symbol);
// println!(" => self_type: {:?}", self_type);

let mut current_module = module;
// This block tries to resolve associated types
let mut current_mod_path = vec![];
let mut decl_opt = None;
for ident in mod_path.iter() {
// println!(" .. resolving {:?}", ident);
if let Some(decl) = decl_opt {
decl_opt = Some(resolve_associated_type_or_item(
handler,
Expand All @@ -405,6 +413,7 @@ fn resolve_symbol_and_mod_path(
}
}
}
// println!(" .. = {:?}", decl_opt);
}
if let Some(decl) = decl_opt {
let decl = resolve_associated_type_or_item(
Expand All @@ -416,7 +425,8 @@ fn resolve_symbol_and_mod_path(
None,
self_type,
)?;
return Ok((decl, current_mod_path));
// println!("resolve_associated_type_or_item => {:?}", decl);
return Ok(decl);
}

module
Expand All @@ -426,7 +436,7 @@ fn resolve_symbol_and_mod_path(
.current_lexical_scope()
.items
.resolve_symbol(handler, engines, symbol)?;
Ok((decl, mod_path.to_vec()))
Ok(decl)
})
}

Expand Down Expand Up @@ -510,11 +520,13 @@ fn resolve_associated_type_or_item(
as_trait: Option<CallPath>,
self_type: Option<TypeId>,
) -> Result<ResolvedDeclaration, ErrorEmitted> {
// println!("resolve_associated_type_or_item");
let type_info = decl_to_type_info(handler, engines, symbol, decl)?;
// println!(" => type_info {:?}", type_info);

let type_id = engines
.te()
.insert(engines, type_info, symbol.span().source_id());

resolve_associated_item_from_type_id(
handler, engines, module, symbol, type_id, as_trait, self_type,
)
Expand Down

0 comments on commit 0171c70

Please sign in to comment.