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

Feature/funargs destructuring #567

Merged
merged 11 commits into from
Jan 13, 2022
Merged

Conversation

francois-caddet
Copy link
Contributor

Implement destructuring for functions arguments as described in the last point of #81:

let f = fun {x; y; z;} => x + y + z in foo
/* bind x, y and z to the corresponding fields of the argument in the body of f */

@github-actions github-actions bot temporarily deployed to pull request January 11, 2022 16:43 Inactive
Copy link
Member

@yannham yannham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Left a few suggestions, and we could also have a bit more tests (for failing patterns and stuff), although since function patterns simply desugar to let patterns, it's maybe a bit redundant.

src/transform/desugar_destructuring.rs Outdated Show resolved Hide resolved
src/transform/desugar_destructuring.rs Outdated Show resolved Hide resolved
src/transform/desugar_destructuring.rs Outdated Show resolved Hide resolved
src/transform/desugar_destructuring.rs Outdated Show resolved Hide resolved
src/transform/desugar_destructuring.rs Outdated Show resolved Hide resolved
RichTerm::new(
Term::Fun(
x.clone(),
Term::LetPattern(None, pat, Term::Var(x).into(), t_).into(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are losing quite a few positions here. It can be a problem for error reporting. I guess we can't have a meaningful position for Var(x), but maybe the LetPattern show have the same position as the function body, I imagine this is what we do in the share_normal_form pass

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure. because, exept for the actual body of the function, for a multiparams function, the pos is same as the main function. So should we not preferably put the rt.pos than the t_.pos?

tests/destructuring/fun.ncl Outdated Show resolved Hide resolved
tests/destructuring/fun.ncl Outdated Show resolved Hide resolved
src/typecheck/mod.rs Outdated Show resolved Hide resolved
francois-caddet and others added 5 commits January 12, 2022 17:50
fix comments typo and nickel syntax cleaning

Co-authored-by: Yann Hamdaoui <yann.hamdaoui@gmail.com>
also add a todo to remember to check if the herited position is the good one.
@github-actions github-actions bot temporarily deployed to pull request January 13, 2022 13:58 Inactive
@francois-caddet francois-caddet merged commit ec1a1ae into master Jan 13, 2022
@francois-caddet francois-caddet deleted the feature/funargs_destructuring branch January 13, 2022 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants