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

Cannot initialize collections with variable type annotation #7113

Open Chriscbr opened 2 months ago

Chriscbr commented 2 months ago

I tried this:

Wing lets you initialize many kinds of values by defining their initial value on the right-hand side of an =, and their type on the left hand side of the =:

struct Foo {
  name: str?;
}

let x: Foo = {};

I expect this to also work for MutArray, Set, and MutSet values:

let x: MutArray<str> = [];
let y: Set<str> = [];
let z: MutSet<str> = [];

This happened:

error: Expected type to be "MutArray<str>", but got "Array<unknown>" instead
  --> wing/main.w:1:24
  |
1 | let x: MutArray<str> = [];
  |                        ^^

I expected this:

No error

Is there a workaround?

let x = MutArray<str>[];

Anything else?

No response

Wing Version

0.84.7

Node.js Version

20.12.2

Platform(s)

MacOS

Community Notes