@@ -21,7 +21,8 @@ use super::odoo::SyncOdoo;
2121use super :: symbols:: symbol:: Symbol ;
2222
2323pub struct ImportResult {
24- pub name : OYarn ,
24+ pub name : OYarn , //the last imported element
25+ pub var_name : OYarn , // the effective symbol name (asname, or first part in a import A.B.C)
2526 pub found : bool ,
2627 pub symbol : Rc < RefCell < Symbol > > ,
2728 pub file_tree : Vec < OYarn > , //contains only the first part of a Tree
@@ -108,7 +109,8 @@ pub fn resolve_import_stmt(session: &mut SessionInfo, source_file_symbol: &Rc<Re
108109 let mut result = vec ! [ ] ;
109110 for alias in name_aliases {
110111 result. push ( ImportResult {
111- name : OYarn :: from ( alias. asname . as_ref ( ) . unwrap_or ( & alias. name ) . to_string ( ) ) ,
112+ name : OYarn :: from ( alias. name . as_ref ( ) . to_string ( ) ) ,
113+ var_name : OYarn :: from ( alias. asname . as_ref ( ) . unwrap_or ( & alias. name ) . to_string ( ) ) ,
112114 found : false ,
113115 symbol : fallback_sym. as_ref ( ) . unwrap ( ) . clone ( ) ,
114116 file_tree : file_tree. clone ( ) ,
@@ -163,8 +165,8 @@ pub fn resolve_import_stmt(session: &mut SessionInfo, source_file_symbol: &Rc<Re
163165 // In all "from X import A" case, it simply means search for A
164166 // But in "import A.B.C", it means search for A only, and import B.C
165167 // If user typed import A.B.C as D, we will search for A.B.C to link it to symbol D,
166- result[ name_index as usize ] . name = name. split ( "." ) . map ( |s| oyarn ! ( "{}" , s) ) . next ( ) . unwrap ( ) ;
167- result[ name_index as usize ] . found = true ;
168+ result[ name_index as usize ] . var_name = name. split ( "." ) . map ( |s| oyarn ! ( "{}" , s) ) . next ( ) . unwrap ( ) ;
169+ // result[name_index as usize].found = true; //even if found at this stage, we want to check everything anyway for diagnostics. But if found, we'll keep this symbol as imported
168170 result[ name_index as usize ] . symbol = next_symbol. as_ref ( ) . unwrap ( ) . clone ( ) ;
169171 }
170172 if !name_middle_part. is_empty ( ) {
@@ -197,15 +199,19 @@ pub fn resolve_import_stmt(session: &mut SessionInfo, source_file_symbol: &Rc<Re
197199 //TODO what if multiple values?
198200 let ns = next_symbol. as_ref ( ) . unwrap ( ) . borrow ( ) . get_symbol ( & ( vec ! [ ] , name_last_name) , u32:: MAX ) . get ( 0 ) . cloned ( ) ;
199201 last_symbol = ns;
200- if alias. asname . is_some ( ) && last_symbol. is_none ( ) {
201- result[ name_index as usize ] . symbol = fallback_sym. as_ref ( ) . unwrap_or ( & source_root) . clone ( ) ;
202+ if last_symbol. is_none ( ) {
203+ if alias. asname . is_some ( ) {
204+ result[ name_index as usize ] . symbol = fallback_sym. as_ref ( ) . unwrap_or ( & source_root) . clone ( ) ;
205+ }
202206 continue ;
203207 }
204208 }
205209 // we found it ! store the result if not already done
206- if alias . asname . is_some ( ) && result[ name_index as usize ] . found == false {
210+ if result[ name_index as usize ] . found == false {
207211 result[ name_index as usize ] . found = true ;
208- result[ name_index as usize ] . symbol = last_symbol. as_ref ( ) . unwrap ( ) . clone ( ) ;
212+ if alias. asname . is_some ( ) {
213+ result[ name_index as usize ] . symbol = last_symbol. as_ref ( ) . unwrap ( ) . clone ( ) ;
214+ }
209215 }
210216 } else {
211217 //everything is ok, let's store the result if not already done
0 commit comments