wing
wing copied to clipboard
inflight init not called when accessing nested preflight fields
I tried this:
bring cloud;
class Foo {
pub b: cloud.Bucket;
new() {
this.b = new cloud.Bucket();
}
inflight new() {
this.b.put("hello.txt", "world");
}
}
let foo = new Foo();
test "test" {
log(foo.b.get("hello.txt"));
}
This happened:
fail ┌ bla.wsim » root/env0/test:test
│ Error: Object does not exist (key=hello.txt): Error: ENOENT: no such file or directory, open '/tmp/wing-sim-mzY1NR/acec329f80cc50edbab0dfbc2283d427ac673f84e6d8b949101791867b9b7771a53d2ffb1f8386189227beed4395b9a78171a1349700e2885c70ae14358d72ff'
│ at Object.activity (/home/yoav/wing2/libs/wingsdk/lib/target-sim/bucket.inflight.js:104:27)
│ at async Object.withTrace (/home/yoav/wing2/libs/wingsdk/lib/testing/simulator.js:256:34)
│ at async $Closure1.handle (/tmp/wing-bundles-sJpWpl/index.js:18:25)
│ at async exports.handler (/tmp/wing-bundles-sJpWpl/index.js:29:10)
│ at async Object.withTrace (/home/yoav/wing2/libs/wingsdk/lib/testing/simulator.js:256:34)
│ at async TestRunnerClient.runTest (/home/yoav/wing2/libs/wingsdk/lib/target-sim/test-runner.inflight.js:31:13)
│ at async testSimulator (/home/yoav/wing2/apps/wing/dist/commands/test.js:214:22)
│ at async testOne (/home/yoav/wing2/apps/wing/dist/commands/test.js:125:20)
│ at async testFile (/home/yoav/wing2/apps/wing/dist/commands/test.js:55:39)
│ at async Promise.all (index 0)
│ at async Object.test (/home/yoav/wing2/apps/wing/dist/commands/test.js:66:5)
└ at async Command.<anonymous> (/home/yoav/wing2/apps/wing/dist/cli.js:46:30)
Tests 1 failed (1)
Test Files 1 failed (1)
Duration 0m0.26s
I expected this:
to print "world"
Is there a workaround?
move the initialization logic to some other inflight method and call it before using the class:
test "test" {
foo.do_init();
log(foo.b.get("hello.txt"));
}
Component
Compiler
Wing Version
No response
Node.js Version
No response
Platform(s)
No response
Anything else?
This is a result of of the lifting logic. Since we explicitly lift the preflight foo.b
expression and we never actually just lift foo
, foo
's inflight init is never called.
Community Notes
- Please vote by adding a 👍 reaction to the issue to help us prioritize.
- If you are interested to work on this issue, please leave a comment.