Thread down if/is pattern assignment type down to code-generation.
This isn't sufficient however, as the 'assignment' helper handling code generation doesn't perform any check when patterns are vars. This is curious, and need to be investigated further.
This commit is contained in:
		
							parent
							
								
									c4abf2e8f4
								
							
						
					
					
						commit
						a6c5dbb5ad
					
				|  | @ -1833,7 +1833,7 @@ impl TypedClause { | |||
| 
 | ||||
| pub struct UntypedClauseGuard {} | ||||
| 
 | ||||
| pub type TypedIfBranch = IfBranch<TypedExpr, TypedPattern>; | ||||
| pub type TypedIfBranch = IfBranch<TypedExpr, (TypedPattern, Rc<Type>)>; | ||||
| pub type UntypedIfBranch = IfBranch<UntypedExpr, AssignmentPattern>; | ||||
| 
 | ||||
| #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] | ||||
|  |  | |||
|  | @ -637,7 +637,8 @@ impl<'a> CodeGenerator<'a> { | |||
|                         let body = self.build(&branch.body, module_build_name, &[]); | ||||
| 
 | ||||
|                         match &branch.is { | ||||
|                             Some(pattern) => AirTree::let_assignment( | ||||
|                             Some((pattern, tipo)) => { | ||||
|                                 AirTree::let_assignment( | ||||
|                                     "acc_var", | ||||
|                                     // use anon function as a delay to avoid evaluating the acc
 | ||||
|                                     AirTree::anon_func(vec![], acc, true), | ||||
|  | @ -645,7 +646,7 @@ impl<'a> CodeGenerator<'a> { | |||
|                                         pattern, | ||||
|                                         condition, | ||||
|                                         body, | ||||
|                                     &pattern.tipo(&branch.condition).unwrap(), | ||||
|                                         tipo, | ||||
|                                         AssignmentProperties { | ||||
|                                             value_type: branch.condition.tipo(), | ||||
|                                             kind: AssignmentKind::Expect { backpassing: () }, | ||||
|  | @ -654,7 +655,8 @@ impl<'a> CodeGenerator<'a> { | |||
|                                             otherwise: AirTree::local_var("acc_var", void()), | ||||
|                                         }, | ||||
|                                     ), | ||||
|                             ), | ||||
|                                 ) | ||||
|                             } | ||||
|                             None => AirTree::if_branch(tipo.clone(), condition, body, acc), | ||||
|                         } | ||||
|                     }, | ||||
|  |  | |||
|  | @ -1548,7 +1548,12 @@ impl<'a, 'b> ExprTyper<'a, 'b> { | |||
|                     location, | ||||
|                 } = is; | ||||
| 
 | ||||
|                 let TypedExpr::Assignment { value, pattern, .. } = typer.infer_assignment( | ||||
|                 let TypedExpr::Assignment { | ||||
|                     value, | ||||
|                     pattern, | ||||
|                     tipo, | ||||
|                     .. | ||||
|                 } = typer.infer_assignment( | ||||
|                     pattern, | ||||
|                     branch.condition.clone(), | ||||
|                     AssignmentKind::is(), | ||||
|  | @ -1564,11 +1569,10 @@ impl<'a, 'b> ExprTyper<'a, 'b> { | |||
|                         location: branch.condition.location().union(location), | ||||
|                     }) | ||||
|                 } | ||||
| 
 | ||||
|                 assert_no_assignment(&branch.body)?; | ||||
|                 let body = typer.infer(branch.body.clone())?; | ||||
| 
 | ||||
|                 Ok((*value, body, Some(pattern))) | ||||
|                 Ok((*value, body, Some((pattern, tipo)))) | ||||
|             })?, | ||||
|             None => { | ||||
|                 let condition = self.infer(branch.condition.clone())?; | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 KtorZ
						KtorZ