Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing implementation of from_ast for Record #2100

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading