fix: bring back vec1

This commit is contained in:
rvcas 2024-03-07 14:27:53 -05:00 committed by Lucas
parent 9d99b509b2
commit 836e853827
2 changed files with 15 additions and 4 deletions

View File

@ -125,7 +125,8 @@ pub enum TypedExpr {
If { If {
location: Span, location: Span,
branches: Vec<IfBranch<Self>>, #[serde(with = "Vec1Ref")]
branches: Vec1<IfBranch<Self>>,
final_else: Box<Self>, final_else: Box<Self>,
tipo: Rc<Type>, tipo: Rc<Type>,
}, },
@ -180,6 +181,16 @@ pub enum TypedExpr {
}, },
} }
#[derive(serde::Serialize, serde::Deserialize)]
#[serde(remote = "Vec1")]
struct Vec1Ref<T>(#[serde(getter = "Vec1::as_vec")] Vec<T>);
impl<T> From<Vec1Ref<T>> for Vec1<T> {
fn from(v: Vec1Ref<T>) -> Self {
Vec1::try_from_vec(v.0).unwrap()
}
}
impl TypedExpr { impl TypedExpr {
pub fn tipo(&self) -> Rc<Type> { pub fn tipo(&self) -> Rc<Type> {
match self { match self {
@ -289,7 +300,7 @@ impl TypedExpr {
| Self::RecordUpdate { location, .. } | Self::RecordUpdate { location, .. }
| Self::CurvePoint { location, .. } => *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 { Self::Sequence {
expressions, expressions,

View File

@ -453,7 +453,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
TraceLevel::Silent => Ok(typed_value), TraceLevel::Silent => Ok(typed_value),
TraceLevel::Verbose | TraceLevel::Compact => Ok(TypedExpr::If { TraceLevel::Verbose | TraceLevel::Compact => Ok(TypedExpr::If {
location, location,
branches: vec![IfBranch { branches: vec1::vec1![IfBranch {
condition: typed_value, condition: typed_value,
body: var_true, body: var_true,
location, location,
@ -1428,7 +1428,7 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
let tipo = body.tipo(); let tipo = body.tipo();
let mut typed_branches = vec![TypedIfBranch { let mut typed_branches = vec1::vec1![TypedIfBranch {
body, body,
condition, condition,
location: first.location, location: first.location,