Skip to content

Commit

Permalink
Add missing implementation of from_ast for Record (#2100)
Browse files Browse the repository at this point in the history
  • Loading branch information
yannham authored Nov 20, 2024
1 parent 10d96a7 commit f2caf36
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
29 changes: 28 additions & 1 deletion core/src/bytecode/ast/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,34 @@ impl<'ast> FromAst<Node<'ast>> 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,
Expand Down
18 changes: 1 addition & 17 deletions core/src/bytecode/ast/record.rs
Original file line number Diff line number Diff line change
@@ -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> {
Expand Down

0 comments on commit f2caf36

Please sign in to comment.