fix: incorrect 'unused::constructor'
`ExprTyper` was not incrementing the usage of a constructor when infering `RecordAccess`. closes #554
This commit is contained in:
		
							parent
							
								
									52dfc13f8f
								
							
						
					
					
						commit
						55f89a7ff4
					
				|  | @ -82,6 +82,37 @@ fn validator_illegal_arity() { | |||
|     )) | ||||
| } | ||||
| 
 | ||||
| #[test] | ||||
| fn mark_constructors_as_used_via_field_access() { | ||||
|     let source_code = r#" | ||||
|       type Datum { | ||||
|         D0(D0Params) | ||||
|         D1(D1Params) | ||||
|       } | ||||
| 
 | ||||
|       type D0Params { | ||||
|         foo: Int, | ||||
|       } | ||||
| 
 | ||||
|       type D1Params { | ||||
|         bar: Int, | ||||
|       } | ||||
| 
 | ||||
|       validator { | ||||
|         fn foo(d: Datum, _r, _c) { | ||||
|           when d is { | ||||
|             D0(params) -> params.foo == 1 | ||||
|             D1(_params) -> False | ||||
|           } | ||||
|         } | ||||
|       } | ||||
|     "#;
 | ||||
| 
 | ||||
|     let (warnings, _) = check_validator(parse(source_code)).unwrap(); | ||||
| 
 | ||||
|     assert_eq!(warnings.len(), 1) | ||||
| } | ||||
| 
 | ||||
| #[test] | ||||
| fn validator_correct_form() { | ||||
|     let source_code = r#" | ||||
|  |  | |||
|  | @ -782,18 +782,21 @@ impl<'a, 'b> ExprTyper<'a, 'b> { | |||
|         }; | ||||
| 
 | ||||
|         // Check to see if it's a Type that can have accessible fields
 | ||||
|         let accessors = match collapse_links(record.tipo()).as_ref() { | ||||
|         let (accessors, name) = match collapse_links(record.tipo()).as_ref() { | ||||
|             // A type in the current module which may have fields
 | ||||
|             Type::App { module, name, .. } if module == self.environment.current_module => { | ||||
|                 self.environment.accessors.get(name) | ||||
|             } | ||||
|             Type::App { module, name, .. } if module == self.environment.current_module => self | ||||
|                 .environment | ||||
|                 .accessors | ||||
|                 .get(name) | ||||
|                 .map(|t| (t, name.clone())), | ||||
| 
 | ||||
|             // A type in another module which may have fields
 | ||||
|             Type::App { module, name, .. } => self | ||||
|                 .environment | ||||
|                 .importable_modules | ||||
|                 .get(module) | ||||
|                 .and_then(|module| module.accessors.get(name)), | ||||
|                 .and_then(|module| module.accessors.get(name)) | ||||
|                 .map(|accessors| (accessors, name.clone())), | ||||
| 
 | ||||
|             _something_without_fields => return Err(unknown_field(vec![])), | ||||
|         } | ||||
|  | @ -826,6 +829,8 @@ impl<'a, 'b> ExprTyper<'a, 'b> { | |||
|             false, | ||||
|         )?; | ||||
| 
 | ||||
|         self.environment.increment_usage(&name); | ||||
| 
 | ||||
|         Ok(TypedExpr::RecordAccess { | ||||
|             record, | ||||
|             label, | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 rvcas
						rvcas