From f2caf3687b5f562656e1f15df3a3ad132acb61e5 Mon Sep 17 00:00:00 2001 From: Yann Hamdaoui Date: Wed, 20 Nov 2024 11:12:55 +0100 Subject: [PATCH] Add missing implementation of from_ast for Record (#2100) --- core/src/bytecode/ast/compat.rs | 29 ++++++++++++++++++++++++++++- core/src/bytecode/ast/record.rs | 18 +----------------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/core/src/bytecode/ast/compat.rs b/core/src/bytecode/ast/compat.rs index 83ebcd79cf..caa2319587 100644 --- a/core/src/bytecode/ast/compat.rs +++ b/core/src/bytecode/ast/compat.rs @@ -1136,7 +1136,34 @@ impl<'ast> FromAst> for term::Term { Term::Enum(*tag) } } - Node::Record(_) => todo!(), + Node::Record(Record { + stat_fields, + dyn_fields, + open, + }) => { + let fields = stat_fields + .iter() + .map(|(id, field)| (*id, field.to_mainline())) + .collect(); + + let dyn_fields = dyn_fields + .iter() + .map(|(dyn_name, field)| (dyn_name.to_mainline(), field.to_mainline())) + .collect(); + + Term::RecRecord( + term::record::RecordData { + fields, + attrs: term::record::RecordAttrs { + open: *open, + ..Default::default() + }, + sealed_tail: None, + }, + dyn_fields, + None, + ) + } Node::IfThenElse { cond, then_branch, diff --git a/core/src/bytecode/ast/record.rs b/core/src/bytecode/ast/record.rs index c4bdebc178..ae99b79622 100644 --- a/core/src/bytecode/ast/record.rs +++ b/core/src/bytecode/ast/record.rs @@ -1,27 +1,11 @@ use super::{Annotation, Ast}; -use crate::{combine::Combine, identifier::LocIdent}; +use crate::identifier::LocIdent; pub use crate::term::MergePriority; use std::rc::Rc; -/// Additional attributes for record. -#[derive(Debug, Default, Eq, PartialEq, Copy, Clone)] -pub struct RecordAttrs { - /// If the record is an open record, ie ending with `..`. Open records have a different - /// behavior when used as a record contract: they allow additional fields to be present. - pub open: bool, -} - -impl Combine for RecordAttrs { - fn combine(left: Self, right: Self) -> Self { - RecordAttrs { - open: left.open || right.open, - } - } -} - /// The metadata attached to record fields. #[derive(Debug, PartialEq, Clone, Default)] pub struct FieldMetadata<'ast> {