winglang / wing

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

Unclear error message when an immutable object is being lifted to inflight #6566

Open staycoolcall911 opened 1 month ago

staycoolcall911 commented 1 month ago

I tried this:

let a = MutArray<num> [1,2];
a.push(3); //succeeds because a is mutable

test "mutability disabled on inflight error message should be improved" { // test syntax currently implies inflight, so referenced preflight expressions are lifted by the compiler 
  a.push(4); //fails because during lifting a was implicitly converted to immutable
}

This happened:

Compiler error within the test block:

error: Member "push" doesn't exist in "Array"
  --> wing/main.w:5:5
  |
5 |   a.push(4);
  |     ^^^^

I expected this:

In #6258 we added the compiler behavior to convert mutable preflight expressions to immutable when lifting them to inflight. So, I was expecting calling a.push() inflight to fail, but it is unclear from the error message that a is not mutable anymore or what should I do.

I would expect an error message in the spirit of: Preflight "MutArray" object was implicitly converted to "Array" when lifting to inflight - for additional information please see https://www.winglang.io/docs/concepts/inflights#using-preflight-data-from-inflight

Important to note that if I would use a non existing method name (e.g. a.pushhhh()), I would still expect to get the current error message: error: Member "pushhhh" doesn't exist in "Array".

Is there a workaround?

No response

Anything else?

No response

Wing Version

0.74.14

Node.js Version

No response

Platform(s)

No response

Community Notes