wing icon indicating copy to clipboard operation
wing copied to clipboard

Nested array mutability is not inferred

Open Chriscbr opened this issue 2 years ago • 2 comments

I tried this:

let x = MutArray<MutArray<num>>[[1, 2, 3]];

This happened:

It raises the following error:

error: Expected type to be "MutArray<num>", but got "Array<num>" instead
  --> main.w:1:33
  |
1 | let x = MutArray<MutArray<num>>[[1, 2, 3]];
  |                                 ^^^^^^^^^ Expected type to be "MutArray<num>", but got "Array<num>" instead

I expected this:

It should allow the code to compile since the full types are specified on the left hand side

Is there a workaround?

Fully specify the types:

let x = MutArray<MutArray<num>>[MutArray<num>[1, 2, 3]];

For 3D arrays this is quite laborious

let x = MutArray<MutArray<MutArray<num>>>[
  MutArray<MutArray<num>>[MutArray<num>[1, 2, 3]]
];

Anything else?

No response

Wing Version

0.70.6

Node.js Version

20.11.1

Platform(s)

MacOS

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 avatar Apr 15 '24 23:04 Chriscbr

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!

github-actions[bot] avatar Jul 15 '24 06:07 github-actions[bot]

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!

github-actions[bot] avatar Oct 14 '24 06:10 github-actions[bot]