-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
An incremental way to add new class members #30811
Comments
If I understand this correctly, we want a way to mark an instance member declaration as "auto-implement" so that every class inheriting the member in its interface, but not having an implementation for it yet, would be considered a warning instead of an error (and the error-recovery would add a matching member that throws when used, e.g., an I can see the lure. It's not something you want to have around forever, but then, you should probably opt in to the feature to begin with (if you don't, it's still an error). It's an interesting transition strategy. It allows part of an Opt-in, Opt-out, Mandatory transition chain (where Opt-in means implementing the member, Opt-out is when you remove the annotation and means you do have to explicitly implement the member to throw, and Mandatory just means that everybody else thinks you're broken if you don't implement it). |
A The |
That assumed we want to add this annotation to hundreds of internal
libraries. I'm not convinced we do.
…On Tue, Nov 14, 2017, 9:57 AM Florian Loitsch ***@***.***> wrote:
A @NotImplemented annotation would definitely be an option, but it has to
hook much deeper into the language.
Either it is similar to default methods (like in Java interfaces), which
is a full-fledged language change, or it allows abstract methods to be
implemented (which is also a major language change wrt strong mode).
The willOverride annotation has the advantage that it is completely
language independent. The override check is something that is not enforced
by the language and only looked at by a linter. Modifying the linter is
much easier.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#30811 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAKQ7uQ8vWHgrGRqF__kbNfGWa-8XZdfks5s2dSJgaJpZM4PdS1N>
.
|
I was going to close this, but if implemented properly (and behind a flag, so its not part of the spec), it would make it much much easier for non-stable releases to add temporary stub APIs without doing giant refactors. |
I thought about this some more - what about a abstract class Base {
void a();
} OK, 6 weeks later, I want to add abstract class Base {
@stub
void b();
} This would basically generate: void b() => throw UnimplementedError(); ... it could even just call |
The problem here is that annotations do not change the language. It's still a language error to not implement the interface, and no amount of annotations should be able to change that. The proper solutions to this issue is either (or both of)
We could also get something like C#'s |
Closing in favor of #30416 then. |
One of the frustrating parts, at least I imagine, of changing the Dart core libraries is that in strong-mode not implementing all interfaces/abstract classes' instance members is considered a build error. Imagine that someone wanted to add the
whoop
method toList
:Now, every single class that either
implements
orextends
List
has a compile error.One strategy would be creating a transitional mix-in:
... and adding it to every
List
implementation, and once a code-base is entirely "whoop-ified" (and assuming no new implementations ofList
are added), you can then try to addwhoop
toList
. But wait, that's also an error in some build systems (i.e. Google's Bazel), because you omitted the@override
annotation.... so now you need to add
@override
toListWithWhoop
, and then cleanup and remove theListWithWhoop
class from the entire code base. I imagine for something likeList
orIterable
or anything else common with lots of pub packages/third party dependencies this will certainly take some time.Proposal
Add an optional,
@notImplemented
(name is terrible, but accepting suggestions) annotation todart:_internal
for the entire purpose of instructing the frontend(s) to ignore this method, and pretend it doesn't even exist. For example, this would be valid, warning/error-free code:An alternative could be to implement a default implementation, i.e. it would compile to:
Once all classes that implement
List
implementwhoop
, then@notImplemented
could be removed, and the implementation added to the base class (if it is abstract/meant to be extended or mixed in)The text was updated successfully, but these errors were encountered: