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

Variadic parameter error persists after type is inferred #3849

Open
Chriscbr opened this issue Aug 16, 2023 · 4 comments
Open

Variadic parameter error persists after type is inferred #3849

Chriscbr opened this issue Aug 16, 2023 · 4 comments
Labels
🐛 bug Something isn't working 🛠️ compiler Compiler

Comments

@Chriscbr
Copy link
Contributor

Chriscbr commented Aug 16, 2023

I tried this:

let g = (x: Array<num>): num => {
  return x.at(0);
};

let f = (...y) => {
  return g(y);
};

When I hover over y in my IDE, it tells me that y has type Array<num>

This happened:

error: Variadic parameters must be type Array or MutArray.
  --> inference.w:5:13
  |
5 | let f = (...y) => {
  |             ^ Variadic parameters must be type Array or MutArray.

I expected this:

I expected the example to compile, or to get an error that I need a type annotation for ...y

Is there a workaround?

No response

Component

Compiler

Wing Version

0.25.14

Node.js Version

18.14.1

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.
@Chriscbr Chriscbr added 🐛 bug Something isn't working 🛠️ compiler Compiler labels Aug 16, 2023
@Chriscbr Chriscbr changed the title Variadic parameter error appears after type is inferred Variadic parameter error persists after type is inferred Aug 16, 2023
@monadabot monadabot added this to Wing Aug 16, 2023
@github-project-automation github-project-automation bot moved this to 🆕 New - not properly defined in Wing Aug 16, 2023
@staycoolcall911 staycoolcall911 moved this from 🆕 New - not properly defined to 🤝 Backlog - handoff to owners in Wing Aug 17, 2023
@MarkMcCulloh
Copy link
Contributor

MarkMcCulloh commented Aug 18, 2023

I think there are two options here, assuming we keep the current inference mechanism:

  1. When encountering (...y), the type checker will infer y as Array<inference(0)> instead of just inference(0). This will ensure that it will be valid for variadic purposes and that any further inferencing must match that shape
  2. Simply require type annotations on variadic args

While I enjoy the ergonomics of (1), it will likely be surprising when this does not work (note mutarray):

let g = (x: MutArray<num>): num => {
  return x.at(0);
};

let f = (...y) => {
  return g(y);
         //^ Expected type to be "MutArray<num>", but got "Array<unknown>" instead
};

With the current inferencing algorithm, it can't apply a constraint that has more than one type (e.g. both Array and MutArray), so we would have to pick one.

@github-actions
Copy link

Hi,

This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days.
Feel free to re-open this issue when there's an update or relevant information to be added.
Thanks!

Copy link

github-actions bot commented Mar 3, 2024

Hi,

This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days.
Feel free to re-open this issue when there's an update or relevant information to be added.
Thanks!

Copy link

github-actions bot commented Jun 4, 2024

Hi,

This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days.
Feel free to re-open this issue when there's an update or relevant information to be added.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working 🛠️ compiler Compiler
Projects
Status: 🤝 Backlog - handoff to owners
Development

No branches or pull requests

3 participants