-
Notifications
You must be signed in to change notification settings - Fork 202
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
base
class modifier loophole
#2451
Comments
Note: it's tempting to fix this proposal by instead saying that if a class |
Prohibition against implementation would need to be inherited, otherwise it doesn't work. Which means it's not a property of a class, it's a property of an inheritance tree, so the "base class" name doesn't really match. That can be implemented either by implicitly inheriting the |
That's not sufficient, because we allow you to violate the prohibition within the same library. Which means that if we did it by requiring the subclass to declare itself as // lib1.dart
abstract base class A {
_foo() {}
} // lib2.dart
import 'lib1.dart';
abstract base class B extends A {} // allowed because also "base"
class C implements B {} // allowed because same library as B |
We could disallow the We'd probably have to do, at least, that. An So, it's not that subclasses are implicitly |
Thinking about this more, the goal of the Primitively, it could be something like:
Likely well have the usual caveats of allowing subclasses in the same library to break that requirement. However, if those classes are public, we must decide on whether extending those is sufficient to satisfy extending C. Then the rules become:
Together these rules transitively guarantee that any object implementing D has inherited code from some class or mixin declared in the same library as D. The We may want to restrict the requirement to concrete classes, so you can define A more direct version:
The restriction on mixins (which are inherently abstract) was there to help you not create a mixin which won't work when applied. We can retain that restriction. |
@lrhn I'm fine with any of these variations |
I'm going to go ahead and close this out because the newer proposal that supersedes the old |
Regarding the
base
class modifier defined here, it seems to me that the purpose of marking classA
as a "base" class is to ensure that any instance of a class that subclassesA
in the program is guaranteed to haveA
in its superclass chain. (This, for example, makes it safe to put private members inA
, and access them via a target other thanthis
).But as I understand the current spec proposal, there's a loophole. If my library contains:
Then what's to stop some other library from doing this?
To close this loophole I think we should say that if a class
A
in libraryL
has thebase
class modifier, then any subclass ofA
outside ofL
must haveA
somewhere in its supertype chain.The text was updated successfully, but these errors were encountered: