Merge pull request #605 from HigherOrderCO/468-patterns-in-fun-rules-shouldnt-accept-unscoped-variables

#468 Patterns in "fun" rules should accept unscoped variables
This commit is contained in:
Nicolas Abril 2024-06-26 09:58:10 +00:00 committed by GitHub
commit 8440fad2a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 26 additions and 3 deletions

View File

@ -18,6 +18,7 @@ and this project does not currently adhere to a particular versioning scheme.
- Fix readback of numeric operations. ([#467][gh-467])
- Propagate the "builtin" attribute of definitions when extracting functions from `bend` and `fold` syntax.
- Panic while using unscoped variables on definition patterns. ([#468][gh-468])
### Added
@ -339,6 +340,7 @@ and this project does not currently adhere to a particular versioning scheme.
[gh-465]: https://github.com/HigherOrderCO/Bend/issues/465
[gh-466]: https://github.com/HigherOrderCO/Bend/issues/466
[gh-467]: https://github.com/HigherOrderCO/Bend/issues/467
[gh-468]: https://github.com/HigherOrderCO/Bend/issues/468
[gh-470]: https://github.com/HigherOrderCO/Bend/issues/470
[gh-475]: https://github.com/HigherOrderCO/Bend/issues/475
[gh-478]: https://github.com/HigherOrderCO/Bend/issues/478

View File

@ -127,9 +127,19 @@ fn simplify_rule_match(
fn irrefutable_fst_row_rule(args: Vec<Name>, rule: Rule) -> Term {
let mut term = rule.body;
for (arg, pat) in args.into_iter().zip(rule.pats.into_iter()) {
let Pattern::Var(var) = pat else { unreachable!() };
if let Some(var) = var {
term = Term::Use { nam: Some(var), val: Box::new(Term::Var { nam: arg }), nxt: Box::new(term) };
match pat {
Pattern::Var(None) => {}
Pattern::Var(Some(var)) => {
term = Term::Use { nam: Some(var), val: Box::new(Term::Var { nam: arg }), nxt: Box::new(term) };
}
Pattern::Chn(var) => {
term = Term::Let {
pat: Box::new(Pattern::Chn(var)),
val: Box::new(Term::Var { nam: arg }),
nxt: Box::new(term),
};
}
_ => unreachable!(),
}
}
term

View File

@ -0,0 +1,3 @@
add $a b = (+ $a b)
main = (add 9 4)

View File

@ -0,0 +1,8 @@
---
source: tests/golden_tests.rs
input_file: tests/golden_tests/compile_file/def_pat_unscoped.bend
---
@add = ($([+] $(a b)) (a b))
@main = a
& @add ~ (9 (4 a))