diff --git a/crates/aiken-lang/src/ast.rs b/crates/aiken-lang/src/ast.rs index 31202a4f..f3b0782d 100644 --- a/crates/aiken-lang/src/ast.rs +++ b/crates/aiken-lang/src/ast.rs @@ -1833,7 +1833,7 @@ impl TypedClause { pub struct UntypedClauseGuard {} -pub type TypedIfBranch = IfBranch; +pub type TypedIfBranch = IfBranch)>; pub type UntypedIfBranch = IfBranch; #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] diff --git a/crates/aiken-lang/src/gen_uplc.rs b/crates/aiken-lang/src/gen_uplc.rs index 0d2c2e1f..0aa75267 100644 --- a/crates/aiken-lang/src/gen_uplc.rs +++ b/crates/aiken-lang/src/gen_uplc.rs @@ -637,24 +637,26 @@ impl<'a> CodeGenerator<'a> { let body = self.build(&branch.body, module_build_name, &[]); match &branch.is { - Some(pattern) => AirTree::let_assignment( - "acc_var", - // use anon function as a delay to avoid evaluating the acc - AirTree::anon_func(vec![], acc, true), - self.assignment( - pattern, - condition, - body, - &pattern.tipo(&branch.condition).unwrap(), - AssignmentProperties { - value_type: branch.condition.tipo(), - kind: AssignmentKind::Expect { backpassing: () }, - remove_unused: false, - full_check: true, - otherwise: AirTree::local_var("acc_var", void()), - }, - ), - ), + 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), + self.assignment( + pattern, + condition, + body, + tipo, + AssignmentProperties { + value_type: branch.condition.tipo(), + kind: AssignmentKind::Expect { backpassing: () }, + remove_unused: false, + full_check: true, + otherwise: AirTree::local_var("acc_var", void()), + }, + ), + ) + } None => AirTree::if_branch(tipo.clone(), condition, body, acc), } }, diff --git a/crates/aiken-lang/src/tipo/expr.rs b/crates/aiken-lang/src/tipo/expr.rs index f6ceb1a1..1950d75e 100644 --- a/crates/aiken-lang/src/tipo/expr.rs +++ b/crates/aiken-lang/src/tipo/expr.rs @@ -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())?;