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:
KtorZ 2024-07-25 16:36:09 +02:00 committed by Kasey
parent c4abf2e8f4
commit a6c5dbb5ad
3 changed files with 28 additions and 22 deletions

View File

@ -1833,7 +1833,7 @@ impl TypedClause {
pub struct UntypedClauseGuard {} pub struct UntypedClauseGuard {}
pub type TypedIfBranch = IfBranch<TypedExpr, TypedPattern>; pub type TypedIfBranch = IfBranch<TypedExpr, (TypedPattern, Rc<Type>)>;
pub type UntypedIfBranch = IfBranch<UntypedExpr, AssignmentPattern>; pub type UntypedIfBranch = IfBranch<UntypedExpr, AssignmentPattern>;
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]

View File

@ -637,24 +637,26 @@ impl<'a> CodeGenerator<'a> {
let body = self.build(&branch.body, module_build_name, &[]); let body = self.build(&branch.body, module_build_name, &[]);
match &branch.is { match &branch.is {
Some(pattern) => AirTree::let_assignment( Some((pattern, tipo)) => {
"acc_var", AirTree::let_assignment(
// use anon function as a delay to avoid evaluating the acc "acc_var",
AirTree::anon_func(vec![], acc, true), // use anon function as a delay to avoid evaluating the acc
self.assignment( AirTree::anon_func(vec![], acc, true),
pattern, self.assignment(
condition, pattern,
body, condition,
&pattern.tipo(&branch.condition).unwrap(), body,
AssignmentProperties { tipo,
value_type: branch.condition.tipo(), AssignmentProperties {
kind: AssignmentKind::Expect { backpassing: () }, value_type: branch.condition.tipo(),
remove_unused: false, kind: AssignmentKind::Expect { backpassing: () },
full_check: true, remove_unused: false,
otherwise: AirTree::local_var("acc_var", void()), full_check: true,
}, otherwise: AirTree::local_var("acc_var", void()),
), },
), ),
)
}
None => AirTree::if_branch(tipo.clone(), condition, body, acc), None => AirTree::if_branch(tipo.clone(), condition, body, acc),
} }
}, },

View File

@ -1548,7 +1548,12 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
location, location,
} = is; } = is;
let TypedExpr::Assignment { value, pattern, .. } = typer.infer_assignment( let TypedExpr::Assignment {
value,
pattern,
tipo,
..
} = typer.infer_assignment(
pattern, pattern,
branch.condition.clone(), branch.condition.clone(),
AssignmentKind::is(), AssignmentKind::is(),
@ -1564,11 +1569,10 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
location: branch.condition.location().union(location), location: branch.condition.location().union(location),
}) })
} }
assert_no_assignment(&branch.body)?; assert_no_assignment(&branch.body)?;
let body = typer.infer(branch.body.clone())?; let body = typer.infer(branch.body.clone())?;
Ok((*value, body, Some(pattern))) Ok((*value, body, Some((pattern, tipo))))
})?, })?,
None => { None => {
let condition = self.infer(branch.condition.clone())?; let condition = self.infer(branch.condition.clone())?;