winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚑
https://winglang.io
Other
5.07k stars 198 forks source link

Nested array mutability is not inferred #6246

Open Chriscbr opened 7 months ago

Chriscbr commented 7 months ago

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

github-actions[bot] commented 4 months ago

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] commented 1 month ago

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!