mirror of
				https://github.com/Dummi26/mers.git
				synced 2025-10-31 03:45:26 +01:00 
			
		
		
		
	fix bug when redeclaring a variable 3 times in the same scope
This commit is contained in:
		
							parent
							
								
									1384222b59
								
							
						
					
					
						commit
						6f36ded38c
					
				| @ -59,11 +59,13 @@ pub type Info = info::Info<Local>; | |||||||
| #[derive(Default, Clone, Debug)] | #[derive(Default, Clone, Debug)] | ||||||
| pub struct Local { | pub struct Local { | ||||||
|     vars: HashMap<String, (usize, usize)>, |     vars: HashMap<String, (usize, usize)>, | ||||||
|  |     vars_count: usize, | ||||||
| } | } | ||||||
| impl info::Local for Local { | impl info::Local for Local { | ||||||
|     type VariableIdentifier = String; |     type VariableIdentifier = String; | ||||||
|     type VariableData = (usize, usize); |     type VariableData = (usize, usize); | ||||||
|     fn init_var(&mut self, id: Self::VariableIdentifier, value: Self::VariableData) { |     fn init_var(&mut self, id: Self::VariableIdentifier, value: Self::VariableData) { | ||||||
|  |         self.vars_count += 1; | ||||||
|         self.vars.insert(id, value); |         self.vars.insert(id, value); | ||||||
|     } |     } | ||||||
|     fn get_var(&self, id: &Self::VariableIdentifier) -> Option<&Self::VariableData> { |     fn get_var(&self, id: &Self::VariableIdentifier) -> Option<&Self::VariableData> { | ||||||
|  | |||||||
| @ -26,7 +26,7 @@ impl MersStatement for Variable { | |||||||
|                 self.var.clone(), |                 self.var.clone(), | ||||||
|                 ( |                 ( | ||||||
|                     info.scopes.len() - 1, |                     info.scopes.len() - 1, | ||||||
|                     info.scopes.last().unwrap().vars.len(), |                     info.scopes.last().unwrap().vars_count, | ||||||
|                 ), |                 ), | ||||||
|             ) |             ) | ||||||
|         } |         } | ||||||
| @ -35,6 +35,7 @@ impl MersStatement for Variable { | |||||||
|             is_init: comp.is_init, |             is_init: comp.is_init, | ||||||
|             is_ref: comp.is_init || self.is_ref, |             is_ref: comp.is_init || self.is_ref, | ||||||
|             var: if let Some(v) = info.get_var(&self.var) { |             var: if let Some(v) = info.get_var(&self.var) { | ||||||
|  |                 eprintln!("Var '{}': {:?}", self.var, v); | ||||||
|                 *v |                 *v | ||||||
|             } else { |             } else { | ||||||
|                 return Err(format!("No variable named '{}' found!", self.var)); |                 return Err(format!("No variable named '{}' found!", self.var)); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Mark
						Mark