Skip to content

Commit ac5a733

Browse files
committed
Fix type parameter handling on option constructors
We were forgetting to take into account the type parameters in the binary interpreter and the implementation of some of the primitives.
1 parent 03d258c commit ac5a733

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

fathom/src/core/binary.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,8 @@ impl<'arena, 'data> Context<'arena, 'data> {
440440
(Prim::FormatSucceed, [_, FunApp(_, elem)]) => Ok(elem.clone()),
441441
(Prim::FormatFail, []) => Err(ReadError::ReadFailFormat(span)),
442442
(Prim::FormatUnwrap, [_, FunApp(_, option)]) => match option.match_prim_spine() {
443-
Some((Prim::OptionSome, [FunApp(_, elem)])) => Ok(elem.clone()),
444-
Some((Prim::OptionNone, [])) => Err(ReadError::UnwrappedNone(span)),
443+
Some((Prim::OptionSome, [_, FunApp(_, elem)])) => Ok(elem.clone()),
444+
Some((Prim::OptionNone, [_])) => Err(ReadError::UnwrappedNone(span)),
445445
_ => Err(ReadError::InvalidValue(span)),
446446
},
447447
_ => Err(ReadError::InvalidFormat(span)),

fathom/src/core/prim.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -782,30 +782,36 @@ pub fn step(prim: Prim) -> Step {
782782

783783
Prim::OptionFold => step!(env, [_, _, on_none, on_some, option] => {
784784
match option.match_prim_spine()? {
785-
(Prim::OptionSome, [Elim::FunApp(Plicity::Explicit, value)]) => env.fun_app(
786-
Plicity::Explicit,
787-
on_some.clone(), value.clone()),
788-
(Prim::OptionNone, []) => on_none.clone(),
785+
(Prim::OptionSome, [_, Elim::FunApp(Plicity::Explicit, value)]) => {
786+
env.fun_app(Plicity::Explicit, on_some.clone(), value.clone())
787+
},
788+
(Prim::OptionNone, [_]) => on_none.clone(),
789789
_ => return None,
790790
}
791791
}),
792792

793793
Prim::Array8Find | Prim::Array16Find | Prim::Array32Find | Prim::Array64Find => {
794-
step!(env, [_, _, pred, array] => match array.as_ref() {
794+
step!(env, [_, elem_type, pred, array] => match array.as_ref() {
795795
Value::ArrayLit(elems) => {
796796
for elem in elems {
797797
match env.fun_app(
798-
Plicity::Explicit,
799-
pred.clone(), elem.clone()).as_ref() {
798+
Plicity::Explicit,
799+
pred.clone(), elem.clone()).as_ref() {
800800
Value::ConstLit(Const::Bool(true)) => {
801801
// TODO: Is elem.span right here?
802-
return Some(Spanned::new(elem.span(), Arc::new(Value::prim(Prim::OptionSome, [elem.clone()]))))
802+
return Some(Spanned::new(
803+
elem.span(),
804+
Arc::new(Value::prim(Prim::OptionSome, [
805+
elem_type.clone(),
806+
elem.clone(),
807+
])),
808+
));
803809
},
804810
Value::ConstLit(Const::Bool(false)) => {}
805811
_ => return None,
806812
}
807813
}
808-
Spanned::empty(Arc::new(Value::prim(Prim::OptionNone, [])))
814+
Spanned::empty(Arc::new(Value::prim(Prim::OptionNone, [elem_type.clone()])))
809815
}
810816
_ => return None,
811817
})

0 commit comments

Comments
 (0)