Fix incoherent 'UnknownVariable' being returned in type-check
I initially removed the 'UnkownTypeConstructor' since it wasn't used anywhere and was in fact dead-code. On second thoughts however, it is nicer to provide a slightly better error message when a constructor is missing as well as some valid suggestion. Prior to that commit, we would simply return a 'UnknownVariable' and the hint might suggest lowercase identifiers; which is wrong.
This commit is contained in:
		
							parent
							
								
									5986163ba7
								
							
						
					
					
						commit
						f6eff7ec58
					
				|  | @ -309,11 +309,14 @@ impl<'a> Environment<'a> { | |||
|         location: Span, | ||||
|     ) -> Result<&ValueConstructor, Error> { | ||||
|         match module { | ||||
|             None => self.scope.get(name).ok_or_else(|| Error::UnknownVariable { | ||||
|                 location, | ||||
|                 name: name.to_string(), | ||||
|                 variables: self.local_value_names(), | ||||
|             }), | ||||
|             None => self | ||||
|                 .scope | ||||
|                 .get(name) | ||||
|                 .ok_or_else(|| Error::UnknownTypeConstructor { | ||||
|                     location, | ||||
|                     name: name.to_string(), | ||||
|                     constructors: self.local_constructor_names(), | ||||
|                 }), | ||||
| 
 | ||||
|             Some(m) => { | ||||
|                 let (_, module) = | ||||
|  | @ -577,6 +580,14 @@ impl<'a> Environment<'a> { | |||
|             .collect() | ||||
|     } | ||||
| 
 | ||||
|     pub fn local_constructor_names(&self) -> Vec<String> { | ||||
|         self.scope | ||||
|             .keys() | ||||
|             .filter(|&t| t.chars().next().unwrap_or_default().is_uppercase()) | ||||
|             .map(|t| t.to_string()) | ||||
|             .collect() | ||||
|     } | ||||
| 
 | ||||
|     fn make_type_vars( | ||||
|         &mut self, | ||||
|         args: &[String], | ||||
|  |  | |||
|  | @ -799,7 +799,7 @@ Perhaps, try the following: | |||
|         suggest_neighbor(name, constructors.iter(), "Did you forget to import it?") | ||||
|     ))] | ||||
|     UnknownTypeConstructor { | ||||
|         #[label] | ||||
|         #[label("unknown constructor")] | ||||
|         location: Span, | ||||
|         name: String, | ||||
|         constructors: Vec<String>, | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 KtorZ
						KtorZ