From 836e853827e41cc30f9cfb5481c75199c2b68f9f Mon Sep 17 00:00:00 2001 From: rvcas Date: Thu, 7 Mar 2024 14:27:53 -0500 Subject: [PATCH] fix: bring back vec1 --- crates/aiken-lang/src/expr.rs | 15 +++++++++++++-- crates/aiken-lang/src/tipo/expr.rs | 4 ++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/crates/aiken-lang/src/expr.rs b/crates/aiken-lang/src/expr.rs index 33bac7aa..28db5a8a 100644 --- a/crates/aiken-lang/src/expr.rs +++ b/crates/aiken-lang/src/expr.rs @@ -125,7 +125,8 @@ pub enum TypedExpr { If { location: Span, - branches: Vec>, + #[serde(with = "Vec1Ref")] + branches: Vec1>, final_else: Box, tipo: Rc, }, @@ -180,6 +181,16 @@ pub enum TypedExpr { }, } +#[derive(serde::Serialize, serde::Deserialize)] +#[serde(remote = "Vec1")] +struct Vec1Ref(#[serde(getter = "Vec1::as_vec")] Vec); + +impl From> for Vec1 { + fn from(v: Vec1Ref) -> Self { + Vec1::try_from_vec(v.0).unwrap() + } +} + impl TypedExpr { pub fn tipo(&self) -> Rc { match self { @@ -289,7 +300,7 @@ impl TypedExpr { | Self::RecordUpdate { location, .. } | Self::CurvePoint { location, .. } => *location, - Self::If { branches, .. } => branches.first().unwrap().body.type_defining_location(), + Self::If { branches, .. } => branches.first().body.type_defining_location(), Self::Sequence { expressions, diff --git a/crates/aiken-lang/src/tipo/expr.rs b/crates/aiken-lang/src/tipo/expr.rs index b5fd2c78..a528a625 100644 --- a/crates/aiken-lang/src/tipo/expr.rs +++ b/crates/aiken-lang/src/tipo/expr.rs @@ -453,7 +453,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> { TraceLevel::Silent => Ok(typed_value), TraceLevel::Verbose | TraceLevel::Compact => Ok(TypedExpr::If { location, - branches: vec![IfBranch { + branches: vec1::vec1![IfBranch { condition: typed_value, body: var_true, location, @@ -1428,7 +1428,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> { let tipo = body.tipo(); - let mut typed_branches = vec![TypedIfBranch { + let mut typed_branches = vec1::vec1![TypedIfBranch { body, condition, location: first.location,