winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
5.05k stars 196 forks source link

Statics are not inherited and can be overridden #3853

Open staycoolcall911 opened 1 year ago

github-actions[bot] commented 1 year 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!

github-actions[bot] commented 8 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!

github-actions[bot] commented 5 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 5 months ago

@yoav-steinberg @staycoolcall911 Do you know if this issue is about static methods or static fields?

I think for static methods it looks like inheritance-like behavior is working as expected (or is at least consistent with behavior from TypeScript):

class Foo {
  pub static foo() {
    log("foo");
  }
}

class Foo2 extends Foo {}

class Foo3 extends Foo {
  pub static foo() {
    log("bar");
  }
}

Foo.foo(); // "foo"
Foo2.foo(); // "foo"
Foo3.foo(); // "bar"
staycoolcall911 commented 5 months ago

Yeah... I could have been more explicit about what I meant :) I was actually bulk creating issues based on requirements specified in the Winglang language reference. This specific requirement came from here (look for the phrase "statics are not inherited").

Chriscbr commented 5 months ago

We had an offline discussion about this with @yoav-steinberg and some other maintainers - it shouldn't be hard to honor the spec here and add a type check error if you're accessing a static method that wasn't defined on that particular class. That would mean in the code above, Foo2.foo() should raise an error like No symbol "foo" found on Foo2. If there are strong use cases for supporting static method inheritance, we can always reverse this in the future without needing a breaking change.