-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Allow two type parameter sections in extension methods. #10950
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
Conversation
5210c8c
to
5885ecf
Compare
5885ecf
to
f3827dd
Compare
@nicolasstucki I need your help to push this over the finish line. The root problem is the asExprOf definition in quotes. Its type parameter [X] needs to go from the extension to the method itself. I did that in 11122ed with non-bootstrapped and bootstrapped versions of Quotes.scala and QuotesImpl.scala. This works, except that macro tests are still failing because they see the non-bootstrapped version of Quotes.scala. Likewise, the community build is failing for the same reason. Can you try to sort these things out and get everything to green? I believe this is the most important thing to do for 3.0RC1. I see now what a mess the previous restriction on type parameters of extension methods created. If the current state makes it into RC-1, it would be super-hard to change it later. I disabled the macro tests in 17e693b, so maybe start by reverting that commit and observe what fails. |
Here's the root problem of all the failing tests:
It clearly gets the wrong version of |
Actually, I might have found a workaround in b4dd60b. So if it's just that we might be able to go ahead anyway. But it's still an issue that we seem to do some build steps on the wrong classpath. EDIT: No, that fix is not sufficient. Now we get failures for sacalatest with |
034d033
to
e30a6fa
Compare
Rebased to latest master |
test performance please |
performance test scheduled: 1 job(s) in queue, 0 running. |
Performance test finished successfully: Visit http://dotty-bench.epfl.ch/10950/ to see the changes. Benchmarks is based on merging with master (141bf9e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great work! I have minor questions about the specification.
(x: X) // <-- extensionParam | ||
(using d: D) // <-- trailingUsing | ||
def +:: (y: Y)(using e: E)(z: Z) // <-- otherParams | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would such a method be called?
(y)(z) +:: x
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be (y +:: x)(z)
.
only if the method is referenced as a regular method: | ||
```scala | ||
map[Int](List(1, 2, 3))(_ + 1) | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we pass both type parameters? Int
and String
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, map[Int](List(1, 2, 3))[String](_ + 1)
.
Formulate newExpr without recourse to IntegratedTypeArgs. Since with scala#10950 extension methods no lonnger require IntegratedTypeArgs either it means we will be able to drop it altogether.
I added a commit with the fix and reenabled the tests. The issue is that there were two definitions of |
@nicolasstucki Doh! I should have seen that! Instead I tried lots of other things... |
060013a
to
b3bafdb
Compare
I don't know the internals, but IMO, it's at least worthy verifying that TASTy supports the data structure now. The functionality can be added much later. |
TASTy supports it already. |
@nicolasstucki I think this is ready for review now. |
03e5698
to
b93b40b
Compare
@odersky This PR will need to be rebased on #10998 once that PR is merged. That PR is there to make sure we do not lose the history of Rebasing should be simple, just keep all the changes from this branch in the files of |
I can do the rebasing |
Leading using clauses now scope over both left and right parameter.
This is a first step towards passing reference trees for all parameters together.
Using two different tags for empty parameter lists and parameter splits leads to a more straightforward encoding. Also: shift tags around to create more free slots for single element trees.
Macro tests seem to use the wrong version of Quotes (non-bootstrapped, where it should be bootstrapped).
To do this, get rid of all uses of `decomposeCall`.
Add tests with dependencies from second type parameter clause to first type parameter and extension parameter clauses.
Make overloading resulution work in the case where type parameters follow value parameters.
b93b40b
to
5cbe0ab
Compare
I think we should concentrate to get #10940 in, which subsumes this PR. |
Subsumed by #10940 |
We now allow extension methods to be written with type parameter clauses after
extension
and/or afterdef
. This allowsextension methods to be expressed more naturally, e.g.
This required quite a lot of changes to internal data structures. Notably,
DefDef
s take one combinedparamss
field thatcontains both type and value parameters.
For the moment only extension methods can have two type parameter lists. We will most likely lift soon the syntactic restriction that normal methods can only have one type parameter list which must come first. Technically, it would only require a small change in the parser. But we should sort out some questions first before we do this. E.g.
That's why I recommend that the change to extension methods goes in for RC-1, but the other changes should come after 3.0.
Todos: