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

Can't push more than one element to an array in a single call to MutArray.push() method #4836

Closed
ainvoner opened this issue Nov 8, 2023 · 5 comments · Fixed by #5114 or #5169
Closed
Assignees
Labels
🐛 bug Something isn't working 🐶 dogfood Discovered while dogfooding Winglang good first issue Good for newcomers

Comments

@ainvoner
Copy link
Contributor

ainvoner commented Nov 8, 2023

I tried this:

let myList: MutArray<str> = MutArray<str> ["element1"];
myList.push("element2", "element3");

This happened:

push method supports only one value.

I expected this:

both "element2" and "element3" to be added to the end of my array in the order of their appearance in the push method arguments list.

Is there a workaround?

let myList: MutArray<str> = MutArray<str> ["element1"];
myList.push("element2");
myList.push("element3");

Component

Language Design

Wing Version

latest

Node.js Version

No response

Platform(s)

MacOS

Anything else?

No response

Community Notes

  • Please vote by adding a 👍 reaction to the issue to help us prioritize.
  • If you are interested to work on this issue, please leave a comment.
@ainvoner ainvoner added the 🐛 bug Something isn't working label Nov 8, 2023
@monadabot monadabot added this to Wing Nov 8, 2023
@github-project-automation github-project-automation bot moved this to 🆕 New - not properly defined in Wing Nov 8, 2023
@staycoolcall911 staycoolcall911 added the 🐶 dogfood Discovered while dogfooding Winglang label Nov 8, 2023
@staycoolcall911 staycoolcall911 moved this from 🆕 New - not properly defined to 🤝 Backlog - handoff to owners in Wing Nov 8, 2023
@Chriscbr Chriscbr added the good first issue Good for newcomers label Nov 8, 2023
@Chriscbr
Copy link
Contributor

Chriscbr commented Nov 8, 2023

Marking this as a good first issue - I think might just require changing the signature of push on MutArray to accept a variadic argument.

Before:

push(value: T): void;

After:

push(values: ...Array<T>): void;

@mergify mergify bot closed this as completed in #5114 Dec 5, 2023
mergify bot pushed a commit that referenced this issue Dec 5, 2023
#5114)

Closes #4836 

For the MutArray container type, the .push() method should take a variadic type. This is implemented in the type_check.rs file, by substituting a generic variadic argument type (T1) with the container's element type when typechecking the function arguments.

## Checklist

- [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted)
- [x] Description explains motivation and solution
- [ ] ~~Tests added (always)~~ Snapshots for MutArray.push() were updated, not sure if new test cases need to be added for this
- [ ] Docs updated (only required for features)
- [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
@github-project-automation github-project-automation bot moved this from 🤝 Backlog - handoff to owners to ✅ Done in Wing Dec 5, 2023
@monadabot
Copy link
Contributor

Congrats! 🚀 This was released in Wing 0.51.11.

@staycoolcall911
Copy link
Contributor

Looks like this wasn't fixed by #5114

@github-project-automation github-project-automation bot moved this from ✅ Done to 🤝 Backlog - handoff to owners in Wing Dec 10, 2023
@graylime
Copy link
Contributor

Thanks for the heads up and sorry for the confusion @staycoolcall911 , I forgot to attach the updated array.ts file definition + the updated snapshots. Those are now linked in this new PR: #5169

@mergify mergify bot closed this as completed in #5169 Dec 11, 2023
mergify bot pushed a commit that referenced this issue Dec 11, 2023
Fixes issue in #5114 and closes #4836 

Attach updated array.ts file (has updated definition for .push() on MutArray to support variadic arguments) and update snapshots

Example Input:
let myList: MutArray<str> = MutArray<str> ["element1"];
myList.push("element2", "element3");

Example Output:
const myList = ["element1"];
((obj, args) => { obj.push(...args); })(myList, ["element2", "element3"]);

## Checklist

- [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted)
- [x] Description explains motivation and solution
- [x] Tests added (always)
- [ ] Docs updated (only required for features)
- [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
@github-project-automation github-project-automation bot moved this from 🤝 Backlog - handoff to owners to ✅ Done in Wing Dec 11, 2023
@monadabot
Copy link
Contributor

Congrats! 🚀 This was released in Wing 0.51.17.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working 🐶 dogfood Discovered while dogfooding Winglang good first issue Good for newcomers
Projects
Archived in project
5 participants