Skip to content

Commit

Permalink
Fix path in shadow check in asm blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
jjcnn committed Sep 5, 2024
1 parent cacbd4e commit 51a673c
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 28 deletions.
66 changes: 44 additions & 22 deletions sway-core/src/language/call_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,63 +386,85 @@ impl CallPath {
}
},
CallPathType::Ambiguous => {
// let problem = self.suffix.as_str() == "Ord" && matches!(self.callpath_type, CallPathType::Ambiguous);

if self.prefixes.is_empty() {
// Given a path to a symbol that has no prefixes, discover the path to the symbol as a
// combination of the package name in which the symbol is defined and the path to the
// current submodule.
let mut synonym_prefixes = vec![];
let mut is_external = false;
let mut is_absolute = false;
// let mut synonym_prefixes = vec![];
// let mut is_external = false;
// let mut is_absolute = false;

if let Some(mod_path) = namespace.current_module().read(engines, |m| {
if m.current_items().symbols().contains_key(&self.suffix) {
// if problem { dbg!("In symbols"); };
None
} else if let Some((_, path, _, _)) = m
.current_items()
.use_item_synonyms
.get(&self.suffix)
.cloned()
{
// if problem { dbg!("In item synonyms"); };
Some(path)
} else if let Some(paths_and_decls) = m
.current_items()
.use_glob_synonyms
.get(&self.suffix)
.cloned()
{
// if problem { dbg!("In glob_synonyms"); };
if paths_and_decls.len() == 1 {
Some(paths_and_decls[0].0.clone())
} else {
None
}
} else {
// if problem { dbg!("Not bound"); };
None
}
}) {
synonym_prefixes.clone_from(&mod_path);
is_absolute = true;
is_external = namespace.module_is_external(&mod_path);
// if problem { dbg!(&mod_path); };
CallPath {
prefixes: mod_path.clone(),
suffix: self.suffix.clone(),
callpath_type: CallPathType::Resolved,
}
// synonym_prefixes.clone_from(&mod_path);
// is_absolute = true;
// is_external = namespace.module_is_external(&mod_path);
}
else {
CallPath {
prefixes: namespace.current_mod_path.clone(),
suffix: self.suffix.clone(),
callpath_type: CallPathType::Resolved,
}

let mut prefixes: Vec<Ident> = vec![];

if !is_external {
prefixes.push(namespace.current_package_name().clone());
// let mut prefixes: Vec<Ident> = vec![];
//
// if !is_external {
// prefixes.push(namespace.current_package_name().clone());
// if problem { dbg!(&prefixes); };

if !is_absolute {
for mod_path in namespace.current_mod_path() {
prefixes.push(mod_path.clone());
}
}
// if !is_absolute {
// for mod_path in namespace.current_mod_path() {
// prefixes.push(mod_path.clone());
// }
// }
// if problem { dbg!(&prefixes); };
}

prefixes.extend(synonym_prefixes);

CallPath {
prefixes,
suffix: self.suffix.clone(),
callpath_type: CallPathType::Resolved,
}
// prefixes.extend(synonym_prefixes);

// if problem { dbg!(&prefixes); };
//
// CallPath {
// prefixes,
// suffix: self.suffix.clone(),
// callpath_type: CallPathType::Resolved,
// }
} else if namespace.current_module_has_submodule(&self.prefixes[0])
{
// Qualified path relative to the current module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1607,7 +1607,7 @@ fn handle_supertraits(
// we allow ABIs as superABIs now
}
_ => {
//println!("impl_trait");
// println!("impl_trait");
handler.emit_err(CompileError::TraitNotFound {
name: supertrait.name.to_string(),
span: supertrait.name.span(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ pub(crate) fn insert_supertraits_into_namespace(
});
}
_ => {
//println!("supertrait");
// println!("supertrait");
// dbg!(&supertrait.name);
handler.emit_err(CompileError::TraitNotFound {
name: supertrait.name.to_string(),
span: supertrait.name.span(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2703,7 +2703,7 @@ fn check_asm_block_validity(
&CallPath {
prefixes: vec![],
suffix: sway_types::BaseIdent::new(span.clone()),
callpath_type: CallPathType::Resolved,
callpath_type: CallPathType::Ambiguous,
},
None,
);
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/semantic_analysis/namespace/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ impl Namespace {
self_type: Option<TypeId>,
) -> Result<ResolvedDeclaration, ErrorEmitted> {
let full_path = call_path.to_fullpath(engines, &self);
// let problem = call_path.suffix.as_str() == "AbiEncode";
// let problem = true; //call_path.suffix.as_str() == "Ord";
// if problem {
// dbg!(call_path);
// dbg!(&full_path);
Expand Down
4 changes: 3 additions & 1 deletion sway-core/src/semantic_analysis/namespace/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,9 @@ impl Root {
// The root module in that package may have a different name than the name we
// use to refer to the package, so replace it.
let mut new_mod_path = vec!(ext_root.current_package_name().clone());
new_mod_path.clone_from_slice(&mod_path[1..]);
for id in mod_path.iter().skip(1) {
new_mod_path.push(id.clone());
}
ext_root.resolve_symbol_and_mod_path_inner(handler, engines, &new_mod_path, symbol, self_type)
},
None => Err(handler.emit_err(crate::namespace::module::module_not_found(mod_path)))
Expand Down
3 changes: 2 additions & 1 deletion sway-core/src/type_system/ast_elements/trait_constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ impl TraitConstraint {
});
}
_ => {
//println!("trait_constraint");
// println!("trait_constraint");
// dbg!(&trait_name);
handler.emit_err(CompileError::TraitNotFound {
name: trait_name.to_string(),
span: trait_name.span(),
Expand Down

0 comments on commit 51a673c

Please sign in to comment.