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.97k stars 196 forks source link

simulator fails when using a class that has unused methods that access a preflight object #5719

Closed yoav-steinberg closed 7 months ago

yoav-steinberg commented 7 months ago

I tried this:

Run test on sim:

bring cloud;
let b = new cloud.Bucket();

class Foo {
  inflight access_b() {
    b.list();
  }

  pub inflight m() {}
}

let f = new Foo();

test "Use class but not method that access lifted object" {
  f.m();
}

This happened:

fail ┌ main.wsim » root/env0/test:Use class but not method that access lifted object
     │ Error: Missing environment variable: BUCKET_HANDLE_ed7b9545
     │   --> ../../../tmp/wing-bundles-54j8Sq/index.js:1:9
     │ 1 | "use strict";
     │   |         ^
     │ at  /tmp/wing-bundles-54j8Sq/index.js:1:9
     └ at new Promise :undefined:undefined

I expected this:

to pass

Is there a workaround?

No response

Anything else?

The issue is that the simulator when creating a client for a class (Foo) creates clients for everything lifted by the class. It does so using the lift map. But since there's no reference to b in the code path from the test (the cloud.Function) then no one sets up the bucket and creating a client for no bucket fails. This can be fixed by fixing the lift map of $inflight_init to add free floating captures and not only fields.

Wing Version

No response

Node.js Version

No response

Platform(s)

No response

Community Notes

monadabot commented 7 months ago

Congrats! :rocket: This was released in Wing 0.58.15.