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

language: allow static members on interfaces, implemented by default class or factory provider #2975

Closed
rakudrama opened this issue May 9, 2012 · 8 comments
Assignees
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug
Milestone

Comments

@rakudrama
Copy link
Member

This is a request to allow any static member to be declared in the interface provided it is implemented via the class named in the interface's 'default' clause.

Interfaces currently permit one kind of static member: constructors, which may be implemented the default implementation class or a factory constructor in a factory provider class.

@rakudrama
Copy link
Member Author

In the html library we make extensive use of the factory provider pattern and some of the interfaces have static methods. Supporting interface static methods with the factory provider pattern would be most useful.

If the interface static method maps directly to the identically named default class method we may have more factory provider classes, since today we have some factory provider classes that service many client interfaces. Some of these 'kitchen sink' factory provider classes would have to be split to permit each client interface to have static methods with the same name. A more compact scheme would be for the single factory provider to name the interfaces, e.g.

interface I1 default _D { I1(); static foo(); }
interface I2 default _D { I2(); static foo(); }

class _D {
  factory I1() {...}
  factory I2() {...}
  static I1.foo() {...}
  static I2.foo() {...}
  // shared implementation code.
}

The call I2.foo() is compiled as _D.foo()

@munificent
Copy link
Member

Why would they need to be implemented in the default class and not in the interface itself? Static members are statically dispatched, and not called through an instance of the interface type. How would the default class come into play?

@gbracha
Copy link
Contributor

gbracha commented May 9, 2012

Set owner to @gbracha.
Added Accepted label.

@rakudrama
Copy link
Member Author

Bob: in dart:html the static methods have different implementations for dart2js vs dartium.

@munificent
Copy link
Member

Bob: in dart:html the static methods have different implementations for dart2js vs dartium.

That's fine. In cases like that you could implement it in the interface through forwarding:

interface Blah default _Blah {
  static foo() => _Blah.realFoo();
}

By not requiring this to go through default classes, it means you don't have to go through that indirection in the cases where it isn't needed.

@gbracha
Copy link
Contributor

gbracha commented May 29, 2012

We'll figure out what to do here in not too long.


Added this to the M1 milestone.

@gbracha
Copy link
Contributor

gbracha commented Jul 2, 2012

No need for this, as the interface elimination proposal solves this nicely. Abstract classes can contain static members while serving as interfaces.


Added WontFix label.

@gbracha
Copy link
Contributor

gbracha commented Jul 10, 2012

Marked this as blocking #679.

@rakudrama rakudrama added Type-Enhancement area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Jul 10, 2012
@rakudrama rakudrama added this to the M1 milestone Jul 10, 2012
@kevmoo kevmoo added closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug and removed resolution-wont_fix labels Mar 1, 2016
dart-bot pushed a commit that referenced this issue May 11, 2021
New commits include:
```
$ git log --format="%C(auto) %h %s" 0e657414a472e74ca5dd76ae0db50cc060251dec..00c00e8adf9706bebe8f94483b7663c5f36f59d2
 00c00e8a Vendor tar (#2987)
 291705ca Being gradual migration to null-safety (#2988)
 c5f52a37 Fix CI (#2989)
 74040a45 Update to analyzer 1.5.0, migrate from deprecated AnalysisSession.getParsedUnit() (#2975)
 ce951d70 Fix dry-run tests for publishing  by ensuring there is a server to reject requests (#2978)
 018c9650 Update LICENSE (#2944)
 2614f15c Revert "Vendor package:tar and package:chunked_stream (#2932)" (#2940)
 12d9f457 Handle package:tar cancellations
 255a3091 Vendor package:tar and package:chunked_stream (#2932)
 86bf8b20 Handle relative git-url-paths correctly when --directory (#2919)
 3716a681 Let `pub add` fail if extra arguments are passed (#2927)
 a03ac729 Minor cleanup to reduce risk of using path.current (#2924)
 e87b7b66 Added null check for name in UserInfo class (#2918)
 056a8c9a pub deps --json (#2896)
 53a69e27 Fix .packages entries of relative path deps when using --directory (#2916)
 d6308efc pub upgrade command shows count of discontinued packages (#2908)
 51744805 Upgrade to the null safe versions of all dependencies (#2913)
 e0d538c7 Introduce .pubignore (#2787)
 79f3a8b9 pub outdated: added clear message when no outdated packages. (#2898)
 22463872 `cache clean` (#2904)
 11e7b2ce `publish --dry-run` informs that the server might do more checks (#2883)
 b6977d50 Remove untrue assert (#2884)
 35841f8d Merge branch 'cherry_picks_for_2_12'
 0db3255b Don't fail on failed status listing (#2877)
 53e8ecca Don't allow outdated taking arguments (#2872)
 e83a1dc1 Enable asserts when testing pub (#2754)
 178f2edb Add --directory option (#2876)
 5aadb70e Don't fail on failed status listing (#2877)
 4bf8a927 Remove unused field (#2878)
 73ad5426 Don't allow outdated taking arguments (#2872)
 9a70949e Use Dart library to read and write tar files (#2817)
 2f74230c Do not recommend decativating packages (#2871)
 b1697a27 Use full error message string in CommandResolutionFailedException (#2870)
 16a6210d Upgrade `downgrade --help`: `downgrade` actually updates `pubspec.lock` (#2859)
 6e240ea9 Use cached version listings as heuristic when prefetching (#2851)
 58152f7c Allow trailing slash in PUB_HOSTED_URL (#2856)
 b1bf9a33 Handle poor package-listing responses robustly. (#2847)
 d941bd24 Fix request metadata when overriding dependencyType (#2848)
```

Change-Id: Id7cc4c09e74c02a92bcafe1a9d9bab9431900540
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/199040
Reviewed-by: Alexander Thomas <[email protected]>
Commit-Queue: Jonas Jensen <[email protected]>
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants