From 51a673cc6bf7a172d8951cb0825dac0bb9362ae4 Mon Sep 17 00:00:00 2001 From: Jacob Johannsen Date: Thu, 5 Sep 2024 20:57:23 +0200 Subject: [PATCH] Fix path in shadow check in asm blocks --- sway-core/src/language/call_path.rs | 66 ++++++++++++------- .../ast_node/declaration/impl_trait.rs | 2 +- .../ast_node/declaration/supertrait.rs | 3 +- .../ast_node/expression/typed_expression.rs | 2 +- .../semantic_analysis/namespace/namespace.rs | 2 +- .../src/semantic_analysis/namespace/root.rs | 4 +- .../ast_elements/trait_constraint.rs | 3 +- 7 files changed, 54 insertions(+), 28 deletions(-) diff --git a/sway-core/src/language/call_path.rs b/sway-core/src/language/call_path.rs index 35b7ee332f0..33e44c93a24 100644 --- a/sway-core/src/language/call_path.rs +++ b/sway-core/src/language/call_path.rs @@ -386,16 +386,19 @@ 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() @@ -403,6 +406,7 @@ impl CallPath { .get(&self.suffix) .cloned() { +// if problem { dbg!("In item synonyms"); }; Some(path) } else if let Some(paths_and_decls) = m .current_items() @@ -410,39 +414,57 @@ impl CallPath { .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 = vec![]; - - if !is_external { - prefixes.push(namespace.current_package_name().clone()); +// let mut prefixes: Vec = 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 diff --git a/sway-core/src/semantic_analysis/ast_node/declaration/impl_trait.rs b/sway-core/src/semantic_analysis/ast_node/declaration/impl_trait.rs index d5d0fe71524..3b1ed1140ca 100644 --- a/sway-core/src/semantic_analysis/ast_node/declaration/impl_trait.rs +++ b/sway-core/src/semantic_analysis/ast_node/declaration/impl_trait.rs @@ -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(), diff --git a/sway-core/src/semantic_analysis/ast_node/declaration/supertrait.rs b/sway-core/src/semantic_analysis/ast_node/declaration/supertrait.rs index 3d7a5e4c866..09a6aadd8dd 100644 --- a/sway-core/src/semantic_analysis/ast_node/declaration/supertrait.rs +++ b/sway-core/src/semantic_analysis/ast_node/declaration/supertrait.rs @@ -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(), diff --git a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression.rs b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression.rs index 913724ac355..84e322f25c0 100644 --- a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression.rs +++ b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression.rs @@ -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, ); diff --git a/sway-core/src/semantic_analysis/namespace/namespace.rs b/sway-core/src/semantic_analysis/namespace/namespace.rs index 782bcafe179..0b3722f9e1e 100644 --- a/sway-core/src/semantic_analysis/namespace/namespace.rs +++ b/sway-core/src/semantic_analysis/namespace/namespace.rs @@ -306,7 +306,7 @@ impl Namespace { self_type: Option, ) -> Result { 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); diff --git a/sway-core/src/semantic_analysis/namespace/root.rs b/sway-core/src/semantic_analysis/namespace/root.rs index d5a1e9d9802..63e6b569d60 100644 --- a/sway-core/src/semantic_analysis/namespace/root.rs +++ b/sway-core/src/semantic_analysis/namespace/root.rs @@ -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))) diff --git a/sway-core/src/type_system/ast_elements/trait_constraint.rs b/sway-core/src/type_system/ast_elements/trait_constraint.rs index d5828a620bd..4f70589f9a7 100644 --- a/sway-core/src/type_system/ast_elements/trait_constraint.rs +++ b/sway-core/src/type_system/ast_elements/trait_constraint.rs @@ -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(),