Make eval primitive object test pass

This commit is contained in:
Greg Shuflin 2021-10-25 19:57:06 -07:00
parent 59956903f2
commit 856e74cb5e
2 changed files with 8 additions and 5 deletions

View File

@ -136,9 +136,9 @@ enum Primitive {
impl Primitive { impl Primitive {
fn to_repl(&self) -> String { fn to_repl(&self) -> String {
match self { match self {
Primitive::Object { type_id, items, .. } => { Primitive::Object { type_id, items, .. } if items.len() == 0 => format!("{}", type_id.local_name()),
format!("{}{}", type_id.local_name(), paren_wrapped(items.iter().map(|item| item.to_repl()))) Primitive::Object { type_id, items, .. } =>
}, format!("{}{}", type_id.local_name(), paren_wrapped(items.iter().map(|item| item.to_repl()))),
Primitive::Literal(lit) => match lit { Primitive::Literal(lit) => match lit {
Literal::Nat(n) => format!("{}", n), Literal::Nat(n) => format!("{}", n),
Literal::Int(i) => format!("{}", i), Literal::Int(i) => format!("{}", i),
@ -258,6 +258,9 @@ impl<'a> State<'a> {
Primitive::unit() Primitive::unit()
}, },
Expression::Call { box f, args } => self.call_expression(f, args)?, Expression::Call { box f, args } => self.call_expression(f, args)?,
Expression::Callable(Callable::DataConstructor { type_id, arity, tag }) if arity == 0 => Primitive::Object {
type_id, tag, items: vec![]
},
Expression::Callable(func) => Primitive::Callable(func), Expression::Callable(func) => Primitive::Callable(func),
Expression::ReductionError(e) => return Err(e.into()), Expression::ReductionError(e) => return Err(e.into()),
}) })

View File

@ -70,9 +70,9 @@ fn adt_output_1() {
type Option<T> = Some(T) | None type Option<T> = Some(T) | None
let a = Option::None let a = Option::None
let b = Option::Some(10) let b = Option::Some(10)
(a, b) (b, a)
"#; "#;
eval_assert(source, "(Option::None, Option::Some(10))"); eval_assert(source, "(Some(10), None)");
} }
/* /*