Skip to content

Commit

Permalink
Fix enum variant contract unwrapping argument (#1833)
Browse files Browse the repository at this point in the history
Fix a bug introduced with enum variant contracts, which would cause a
contract such as `[| 'Foo Number |]` to unwrap the numeric argument of a
matching value, that is `'Foo 5 | [| 'Foo Number |]` would evaluate to
`5` instead of `'Foo 5`.
  • Loading branch information
yannham authored Mar 5, 2024
1 parent 72f4a37 commit 3d29f0e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions core/src/typ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ impl Subcontract for EnumRows {
// x |> match {
// 'foo => x,
// 'bar => x,
// 'Baz variant_arg => %apply_contract% T label_arg variant_arg,
// 'Baz variant_arg => 'Baz (%apply_contract% T label_arg variant_arg),
// _ => $enum_fail l
// }
// ```
Expand All @@ -992,15 +992,22 @@ impl Subcontract for EnumRows {
});

let body = if let Some(ty) = row.typ.as_ref() {
// %apply_contract% T label_arg variant_arg
mk_app!(
// 'Tag (%apply_contract% T label_arg variant_arg)
let arg = mk_app!(
mk_term::op2(
BinaryOp::ApplyContract(),
ty.subcontract(vars.clone(), pol, sy)?,
mk_term::var(label_arg)
),
mk_term::var(variant_arg)
)
);

Term::EnumVariant {
tag: row.id,
arg,
attrs: Default::default(),
}
.into()
} else {
mk_term::var(value_arg)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
#
# [test.metadata]
# error = 'EvalError::BlameError'
'Foo 5 | [| 'Foo String, 'Bar Number, 'Barg |]
%force% ('Foo 5 | [| 'Foo String, 'Bar Number, 'Barg |])

0 comments on commit 3d29f0e

Please sign in to comment.