diff --git a/sway-core/src/language/call_path.rs b/sway-core/src/language/call_path.rs index ab00ad21b45..58d4afdde45 100644 --- a/sway-core/src/language/call_path.rs +++ b/sway-core/src/language/call_path.rs @@ -179,14 +179,23 @@ impl DebugWithEngines for QualifiedCallPath { #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)] pub enum CallPathType { - // An unresolved path on the form `::X::Y`. The path must be resolved relative to the package - // root module. + /// An unresolved path on the form `::X::Y::Z`. The path must be resolved relative to the package + /// root module. + /// The path can be converted to a full path by prepending the package name, so if the path + /// `::X::Y::Z` occurs in package `A`, then the corresponding full path will be `A::X::Y::Z`. RelativeToPackageRoot, - // An unresolved path on the form `X::Y`. The path must either be resolved relative to the - // current module or as an absolute path. + /// An unresolved path on the form `X::Y::Z`. The path must either be resolved relative to the + /// current module, in which case `X` is either a submodule or a name bound in the current + /// module, or as a full path, in which case `X` is the name of the current package. + /// If the path is resolved relative to the current module, and the current module has a module + /// path `A::B::C`, then the corresponding full path is `A::B::C::X::Y::Z`. + /// If the path is resolved as a full path, then the full path is obviously `X::Y::Z`. Ambiguous, - // A fully resolved, absolute path - Resolved, + /// A full path on the form `X::Y::Z`. The first identifier `X` refers to the current package + /// name. After that comes a (possibly empty) series of names of submodules. Then comes the name + /// of an item (a type, a trait, a function, or something else declared in that + /// module). Additionally, there may be additional names such as the name of an enum variant. + Full, } /// In the expression `a::b::c()`, `a` and `b` are the prefixes and `c` is the suffix. @@ -306,7 +315,7 @@ impl CallPath { .map(|&x| Ident::new_no_span(x.into())) .collect(), suffix: path.last().map(|&x| Ident::new_no_span(x.into())).unwrap(), - callpath_type: CallPathType::Resolved, + callpath_type: CallPathType::Full, } } @@ -332,7 +341,7 @@ impl CallPath { let new_callpath_type = match self.callpath_type { CallPathType::RelativeToPackageRoot | CallPathType::Ambiguous => CallPathType::Ambiguous, - CallPathType::Resolved => CallPathType::RelativeToPackageRoot, + CallPathType::Full => CallPathType::RelativeToPackageRoot, }; CallPath { prefixes: self.prefixes[1..self.prefixes.len()].to_vec(), @@ -360,7 +369,7 @@ impl CallPath { for mod_path in namespace.current_mod_path() { res.prefixes.push(mod_path.clone()) } - res.callpath_type = CallPathType::Resolved; + res.callpath_type = CallPathType::Full; res } @@ -373,7 +382,7 @@ impl CallPath { /// and are left unchanged since `std` is a root of the package `std`. pub fn to_fullpath(&self, _engines: &Engines, namespace: &Namespace) -> CallPath { match self.callpath_type { - CallPathType::Resolved => self.clone(), + CallPathType::Full => self.clone(), CallPathType::RelativeToPackageRoot => { let mut prefixes = vec!(); for ident in self.prefixes.iter() { @@ -382,7 +391,7 @@ impl CallPath { Self { prefixes, suffix: self.suffix.clone(), - callpath_type: CallPathType::Resolved, + callpath_type: CallPathType::Full, } }, CallPathType::Ambiguous => { @@ -429,7 +438,7 @@ impl CallPath { // CallPath { // prefixes: mod_path.clone(), // suffix: self.suffix.clone(), -// callpath_type: CallPathType::Resolved, +// callpath_type: CallPathType::Full, // } // // synonym_prefixes.clone_from(&mod_path); // // is_absolute = true; @@ -439,7 +448,7 @@ impl CallPath { CallPath { prefixes: namespace.current_mod_path.clone(), suffix: self.suffix.clone(), - callpath_type: CallPathType::Resolved, + callpath_type: CallPathType::Full, } // // let mut prefixes: Vec = vec![]; @@ -463,7 +472,7 @@ impl CallPath { // // CallPath { // // prefixes, // // suffix: self.suffix.clone(), -// // callpath_type: CallPathType::Resolved, +// // callpath_type: CallPathType::Full, // // } } else if namespace.current_module_has_submodule(&self.prefixes[0]) { @@ -482,14 +491,14 @@ impl CallPath { CallPath { prefixes: namespace.prepend_module_path(&self.prefixes), suffix: self.suffix.clone(), - callpath_type: CallPathType::Resolved, + callpath_type: CallPathType::Full, } } else { // Fully qualified path CallPath { prefixes: self.prefixes.clone(), suffix: self.suffix.clone(), - callpath_type: CallPathType::Resolved, + callpath_type: CallPathType::Full, } } }, diff --git a/sway-core/src/language/ty/declaration/struct.rs b/sway-core/src/language/ty/declaration/struct.rs index 7b33b558349..ca1a983c435 100644 --- a/sway-core/src/language/ty/declaration/struct.rs +++ b/sway-core/src/language/ty/declaration/struct.rs @@ -155,7 +155,7 @@ pub struct StructAccessInfo { impl StructAccessInfo { pub fn get_info(engines: &Engines, struct_decl: &TyStructDecl, namespace: &Namespace) -> Self { assert!( - matches!(struct_decl.call_path.callpath_type, CallPathType::Resolved), + matches!(struct_decl.call_path.callpath_type, CallPathType::Full), "The call path of the struct declaration must always be fully resolved." ); 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 88fde0600b4..b2e8e3b2c5b 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 @@ -89,7 +89,7 @@ impl ty::TyExpression { span: span.clone(), } .to_var_name(), - callpath_type: CallPathType::Resolved, + callpath_type: CallPathType::Full, }; let mut method_name_binding = TypeBinding { inner: MethodName::FromTrait { diff --git a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/method_application.rs b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/method_application.rs index 3f4a05cb554..927e7bbd5bd 100644 --- a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/method_application.rs +++ b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/method_application.rs @@ -817,7 +817,7 @@ pub(crate) fn resolve_method_name( } path }, - CallPathType::Resolved => call_path.prefixes.clone(), + CallPathType::Full => call_path.prefixes.clone(), CallPathType::Ambiguous => { if ctx.namespace().current_module().submodules().contains_key(call_path.prefixes.first().unwrap().as_str()) { ctx.namespace().prepend_module_path(&call_path.prefixes) diff --git a/sway-core/src/semantic_analysis/namespace/root.rs b/sway-core/src/semantic_analysis/namespace/root.rs index 8f33ab5a29a..ea118818663 100644 --- a/sway-core/src/semantic_analysis/namespace/root.rs +++ b/sway-core/src/semantic_analysis/namespace/root.rs @@ -873,7 +873,7 @@ impl Root { // .chain(&call_path.prefixes) // .cloned() // .collect(); - assert!(matches!(call_path.callpath_type, CallPathType::Resolved)); + assert!(matches!(call_path.callpath_type, CallPathType::Full)); self.resolve_symbol_and_mod_path( handler, engines, diff --git a/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs b/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs index 9f1972ba27a..e9e71b685d5 100644 --- a/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs +++ b/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs @@ -2527,7 +2527,7 @@ fn op_call( Ident::new_with_override("ops".into(), op_span.clone()), ], suffix: Ident::new_with_override(name.into(), op_span.clone()), - callpath_type: CallPathType::Resolved, + callpath_type: CallPathType::Full, }, }, type_arguments: TypeArgs::Regular(vec![]), diff --git a/sway-core/src/type_system/info.rs b/sway-core/src/type_system/info.rs index fc96e9a82e6..6239ee70d16 100644 --- a/sway-core/src/type_system/info.rs +++ b/sway-core/src/type_system/info.rs @@ -342,8 +342,8 @@ impl PartialEqWithEngines for TypeInfo { let l_decl = ctx.engines().de().get_enum(l_decl_ref); let r_decl = ctx.engines().de().get_enum(r_decl_ref); assert!( - matches!(l_decl.call_path.callpath_type, CallPathType::Resolved) && - matches!(r_decl.call_path.callpath_type, CallPathType::Resolved), + matches!(l_decl.call_path.callpath_type, CallPathType::Full) && + matches!(r_decl.call_path.callpath_type, CallPathType::Full), "The call paths of the enum declarations must always be resolved." ); l_decl.call_path == r_decl.call_path @@ -354,8 +354,8 @@ impl PartialEqWithEngines for TypeInfo { let l_decl = ctx.engines().de().get_struct(l_decl_ref); let r_decl = ctx.engines().de().get_struct(r_decl_ref); assert!( - matches!(l_decl.call_path.callpath_type, CallPathType::Resolved) && - matches!(r_decl.call_path.callpath_type, CallPathType::Resolved), + matches!(l_decl.call_path.callpath_type, CallPathType::Full) && + matches!(r_decl.call_path.callpath_type, CallPathType::Full), "The call paths of the struct declarations must always be resolved." ); l_decl.call_path == r_decl.call_path diff --git a/sway-core/src/type_system/unify/unify_check.rs b/sway-core/src/type_system/unify/unify_check.rs index 6f22088ae06..3fabf35a4b6 100644 --- a/sway-core/src/type_system/unify/unify_check.rs +++ b/sway-core/src/type_system/unify/unify_check.rs @@ -708,8 +708,8 @@ impl<'a> UnifyCheck<'a> { pub(crate) fn check_enums(&self, left: &TyEnumDecl, right: &TyEnumDecl) -> bool { assert!( - matches!(left.call_path.callpath_type, CallPathType::Resolved) && - matches!(right.call_path.callpath_type, CallPathType::Resolved), + matches!(left.call_path.callpath_type, CallPathType::Full) && + matches!(right.call_path.callpath_type, CallPathType::Full), "The call paths of the enum declarations must always be resolved." ); @@ -769,8 +769,8 @@ impl<'a> UnifyCheck<'a> { pub(crate) fn check_structs(&self, left: &TyStructDecl, right: &TyStructDecl) -> bool { assert!( - matches!(left.call_path.callpath_type, CallPathType::Resolved) && - matches!(right.call_path.callpath_type, CallPathType::Resolved), + matches!(left.call_path.callpath_type, CallPathType::Full) && + matches!(right.call_path.callpath_type, CallPathType::Full), "The call paths of the enum declarations must always be resolved." );