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

Unable to call `.at()` with result of another function call #6662

Open MarkMcCulloh opened 3 weeks ago

MarkMcCulloh commented 3 weeks ago

I tried this:

bring math;

test "test" {
  let characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  let randomChar = characters.at(math.floor(math.random() * characters.length));
  log(randomChar);
}

This happened:

✘ [ERROR] "await" can only be used inside an "async" function

    target/test/main.wsim/.wing/inflight.$Closure1-1.cjs:12:43:
      12 │       const randomChar = ((args) => { if ((await $math_Util.floor(((await $math_Util.random()) * characters.length))) >= characters.length || (await $math_Util....
         ╵           

I expected this:

No response

Is there a workaround?

Move intermediate calculation out of the .at()

bring math;

test "test" {
  let characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  let randomNumber = math.floor(math.random() * characters.length);
  let randomChar = characters.at(randomNumber);
  log(randomChar);
}

Anything else?

This probably happens with all macros when called inflight with call expression arguments

Wing Version

No response

Node.js Version

No response

Platform(s)

No response

Community Notes