-
Notifications
You must be signed in to change notification settings - Fork 26
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
Implemented support for requiring methods #281
Implemented support for requiring methods #281
Conversation
Rebased and ready for review! |
Rebased (again) and ready for review (again)! |
The insertion in Why keeping the commented code in The |
Fixed!
Not my intention, fixed now!
Good catch! Fixed! |
A trait can now require methods just as they can require fields. The syntax is like that of normal method definition but with `require` instead of `def`: ``` trait T require id(x : int) : int def foo(x : int) : int this.id(x) class C : T def id(x : int) : int x ``` Required methods are covariant in their return types (the actual method can have a return type that is more specific than the required method) and invariant in their parameter types, following Java interfaces. This commit also includes a refactoring to unify the concept of a function header. Functions, methods, stream methods and required methods all share the same kind of header containing their names, parameters and return types. This reduces a duplication but also has the effect of appearing as many changed lines.
Since you are modifying them, it's good to fix the indentation for The single commit contains style change (aligning |
Done!
I tried to only do aligning in places where I was already doing changes. The renaming is part of the real changes ( |
What's the intended use case for I think There's no doc for co/contra variance for required methods other than the description in this PR. |
I can't find anywhere it is used either (it's not new for this PR, but has been around for a long time). I have som vague recollection that it had something to do with the old implementation of closures. It seems like it is not strictly needed right now.
You were the one who started using I've never had a problem with
Ah, documentation, my Achilles heel! I'll add this now! |
I think it should be removed, then. This or some other PRs. Indeed, originally, it's using I think this PR is OK, if the author doesn't intend to address the previous points. Another note on the |
I found this:
Since it hasn't been handy for a year, I also think it can be removed (especially since it's saved in the Git history). I don't think this PR should remove it though.
This is mostly to make parsing simpler, but it also makes some kind of sense since Unless other bugs are uncovered I do not plan to change anything else in this PR. |
OK, merge in an hour, if no objections. |
Implemented support for requiring methods
A trait can now require methods just as they can require fields. The
syntax is like that of normal method definition but with
require
instead of
def
:Required methods are covariant in their return types (the actual method
can have a return type that is more specific than the required method)
and invariant in their parameter types, following Java interfaces.
This commit also includes a refactoring to unify the concept of a
function header. Functions, methods, stream methods and required methods
all share the same kind of header containing their names, parameters and
return types. This reduces a duplication but also has the effect of
appearing as many changed lines.