-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Add support for abstract classes #4005
Conversation
1fe99da
to
a7b961d
Compare
Thanks for putting up the PR! We are discussing this, but it might be a while. Not only is it a pretty large change which will take a while to review, but we also need to be careful whenever we add new features to the language. One concern is that if we merge this, and then a future ES spec includes abstract classes that are slightly different, we will have to unify them somehow. This sort of thing needs to be carefully considered. |
ACK |
I've been |
I just noticed that ES6 has dropped the reservation on |
I just noticed that there's a TypeScript proposal with some relevant commentary: microsoft/TypeScript#3578. |
That's good context, thanks. Some of that mirrors the things we have been discussing. Like I said, the main concern is that if someday the ES standard includes abstract classes, we will have to reconcile with that. However, the consensus seems to be that abstract classes are mainly a type system feature, so it seems unlikely that they will make it into the standard in the near future. One possibility for such a feature would be to check, at class construction time, that if the current class is concrete and the parent class is abstract, that the current class provides implementations for all the abstract methods of the parent class (and its parents). Of course, I haven't thought this through and it may in fact be a bad idea, but it is conceivable that abstract classes could be implemented without a static type checker. However, they certainly make more sense as a type system feature. Anyway, the consensus is that the potential risk is small enough that we are willing to add abstract classes. Could you write a summary of abstract classes, as implemented by this PR? I first want to make sure that we are all on the same page. I noticed in your tests that there is a new Unfortunately I don't feel qualified to review this PR but I can certainly act as point of contact, and at least give it a once-over before handing it off to someone else. Thanks again for your work on this! |
Sweet! Give me a few days. |
This PR introduces abstract instance methods (like Java's
class A {
abstract m(): string;
abstract static n(): void;
}
function ext(s: string): AbstractClass<A> {
//Class<A> is a ng return type because Ext has an abstract static `n`.
return class Ext extends A {
m(): string { return s; }
};
}
let E1 = ext("asdf");
// An extension of E1 must provide an `m` and a static `n` to obtain a non-abtract class. I was thinking a syntax like
I just realized that I've been saying "non-abstract" instead of "concrete." Within the code I used variations on "non-abstract" instead of "concrete" to avoid conceptual overloading on other uses of "concrete." Apologies if I sound like a bigger idiot than usual. |
a7b961d
to
eb49746
Compare
e9b9678
to
1a95134
Compare
It looks like abstractness handling of |
Hey, I'm just tidying up old PRs. This hasn't seen any recent activity, and would probably be a huge pain to rebase at this point. I also had trouble getting someone to sign up to review a diff of this scope. If you'd like to take another stab at this problem we are certainly open to it but before you put more time into the implementation it might be worth discussing in an issue and getting a commitment from someone to review. I really appreciate your willingness to step up and implement something like this, even if this time it didn't make it across the finish line. |
This adds support for abstract methods and abstract static methods, e.g.
Setting of class fields like
k
are admitted, but gets are rejected:I didn't bother with digging into class initializers, but I expect that they won't work properly with abstracts because the
this
that they use doesn't bother with abstractness checking.