winglang / winglang/wing

inconsistent class values when using inflight closure

Open
#4,902 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

🐛 bug 🐶 dogfood 🛠️ compiler
Dominant language
TypeScript
Stars
5.4k
Forks
215
Avg merge
2h 9m
Merged PRs (30d)
27

Description

I tried this:

running this code this.a.x has a different value before this.log() and inside that method

bring cloud;
bring util;

let queue = new cloud.Queue();

class A {
  pub inflight x: str;
  inflight init() {
    this.x = util.nanoid();
  }
}

class B {
  a: A;
  init() {
    this.a = new A();
    queue.setConsumer(inflight () => {
      log("${this.a.x}");
      this.log();
    });
  }

  pub inflight log() {
    log("${this.a.x}");
  }
}

let b = new B();

test "" {
  queue.push("123");
  util.sleep(1s);
}

This happened:
pass ┌ x.main.wsim » root/env0/test:
     │ JdgfhMKph7QHeHaNwg-nh
     └ wABo8Lbels0iZlgQv3Hkx
I expected this:

getting the same value twice

Is there a workaround?

No response

Component

Compiler

Wing Version

No response

Node.js Version

No response

Platform(s)

No response

Anything else?

No response

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the Wing program in the issue and compare the two logged values. Then trace the compiler handling for inflight closures and class state, using the reported mismatch as the regression condition; done means both logs consistently show the same value.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.