-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #6190: eta-expand companion object if functions are expected #7207
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
I believe this is good migration story for dropping the automatic function type parent. However, I'd like this to only be a migration story, and not encourage new code to use that "feature" for any kind of The reason is that
So I would recommend: do it only for |
@sjrd The insertion only happens for the companion object of a case class. And a warning is issued as suggested. |
1b04fb6
to
e629143
Compare
While we are at it, should we drop the auto-generated |
It's a nice idea. The only concern is migration. From the experience with community build, there is a significant amount of code using companion objects as function values for |
Looking at the extensive changes this needs in the community build I am a bit nervous to do this now. The breakage might be too extensive, in particular in connection with |
I think rewriting is possible to be implemented in scalafix. Meanwhile, I think it would be better to postpone changes in this PR until 3.1, so that it will not create more hassles in the migration. |
Put on hold until after 3.0. |
Closing for now; to be revived when we get started on 3.1 |
I am re-opening the PR since it affects the binary API. So according to our versioning policy we won't be able to do it in a minor version post 3.0. A question: Are I also agree with @sjrd that ideally we should warn when inserting an So, @liufengyun Can you find out how many manual fixes we need in the current community build, and how many new eta expansion warnings we get? That should give us a better basis to decide what to do. |
The implementation follows this rule.
The implementation follows this rule.
Here are the number of warnings by community projects:
lazy val typeEntry: EntryParser[Type] = oneOf(
11 -^ NoType,
12 -^ NoPrefixType,
13 -~ symbolRef ^^ ThisType,
14 -~ typeRef ~ symbolRef ^~^ SingleType,
...
case 30 => noBox.map(_root_.scalapb.descriptors.PBoolean).getOrElse(_root_.scalapb.descriptors.PEmpty) |
@liufengyun One more question: If we want to avoid the warnings in |
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.
LGTM
It is changed in the following PR for statistics: scala#7207
This test no longer makes sense after #7207 because we never generate synthetic companions with Function parents anymore.
Hi @odersky , this is the data:
For ScalaPB, the function parent has to be made explicit for the following companion objects (13 in total):
For scalap, the function parent has to be made explicit for the following companion objects (38 in total):
|
Fix #6190: eta-expand companion object if functions are expected
As suggested by @odersky in #6190, we stop generating function types as parents for companion objects of case class. To compensate, we insert
C.apply
and eta-expand if the expected type is a function type.Clarification:
In the following code,
.tupled
cannot be omitted --- auto tupling does not work here.