Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

could support static extension? #3921

Closed
Silentdoer opened this issue Jun 19, 2024 · 2 comments
Closed

could support static extension? #3921

Silentdoer opened this issue Jun 19, 2024 · 2 comments
Labels
feature Proposed language feature that solves one or more problems state-duplicate This issue or pull request already exists

Comments

@Silentdoer
Copy link

class Foo {
  String name = "aa";
  static String prop = "bbb";
}

static extension FooExt on Foo {
  void aaa() {
    print(prop)
  }

  static bbb() {
    print("sss")
  }
}

main() {
  Foo.aaa(); // prints bbb
  FooExt.bbb();  // prints sss
}
@Silentdoer Silentdoer added the feature Proposed language feature that solves one or more problems label Jun 19, 2024
@Wdestroier
Copy link

Wdestroier commented Jun 19, 2024

It's similar to #723, which is already in the language funnel!* It looks like what you want, but now I remember seeing a slightly different issue. The static modifier before the extension keyword would mean all members are static, I guess. Can we remove it or would it mean extension on Type<T>?

extension FooExt on Foo {
  aaa() => print(prop)
  static bbb() => print("sss")
}

@lrhn
Copy link
Member

lrhn commented Jun 19, 2024

I'm closing this as a duplicate of #723. The syntax suggested here isn't better, I'd rather have static extension ... be a normal extension where static members are also available on the target type (which must be a type that can have statics).

@lrhn lrhn closed this as completed Jun 19, 2024
@lrhn lrhn added the state-duplicate This issue or pull request already exists label Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Proposed language feature that solves one or more problems state-duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants