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

Cannot extend non-Wing constructs #3717

Closed eladb closed 3 months ago

eladb commented 1 year ago

I tried this:

bring "cdk8s" as cdk8s;

class MyChart extends cdk8s.Chart {
  init() {
    new cdk8s.ApiObject(kind: "Pod", apiVersion: "v1");
  }
}

let c = new MyChart();

This happened:

ERROR: this._addInflightOps is not a function

I expected this:

To work

Is there a workaround?

No response

Component

Compiler, SDK

Wing Version

No response

Node.js Version

No response

Platform(s)

No response

Anything else?

No response

Community Notes

Chriscbr commented 1 year ago

@eladb I'm curious if using composition is a workaround for your use case? (trying to understand priority of this)

github-actions[bot] commented 11 months ago

Hi,

This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!

staycoolcall911 commented 11 months ago

I believe this now works. CC: @eladb, @Chriscbr

Chriscbr commented 11 months ago

Thanks for the heads up @staycoolcall911. It looks like the immediate bug above was fixed (I think via https://github.com/winglang/wing/pull/4640), but if I extend the example a little further with some inflight code, we still get errors:

bring "cdk8s" as cdk8s;
bring cloud;

let global_b = new cloud.Bucket();

class MyChart extends cdk8s.Chart {
  local_b: cloud.Bucket;
  init() {
    new cdk8s.ApiObject(kind: "Pod", apiVersion: "v1");
    this.local_b = new cloud.Bucket();
  }

  pub inflight save() {
    global_b.put("data.txt", "Hello World!");
    this.local_b.put("data.txt", "Hello World!");
  }
}

let c = new MyChart();
new cloud.Function(inflight () => {
  c.save();
});

error:

ERROR: unable to serialize immutable data object of type MyChart

target/main.wsim.988477.tmp/.wing/preflight.js:79
         _registerOnLift(host, ops) {
           if (ops.includes("handle")) {
>>           $Closure1._registerOnLiftObject(c, host, ["save"]);
           }
           super._registerOnLift(host, ops);

I think the root cause is our lifting system is still assuming std.Resource is in the class's hierarchy. Refactoring the SDK to remove std.Resource feels like the cleanest solution IMO

github-actions[bot] commented 4 months ago

Hi,

This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!

Chriscbr commented 3 months ago

From my testing it looks like the previous example now works. I was able to uncover a separate issue but it's more minor: https://github.com/winglang/wing/issues/6629

Closing.