-
Notifications
You must be signed in to change notification settings - Fork 3.1k
SI-7187 deprecate eta-expansion of zero-arg method values #5327
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
For backwards compatiblity with 2.11, we already don't adapt a zero-arg method value to a SAM. In 2.13, we won't do any eta-expansion for zero-arg method values, but we should deprecate first.
|
Thanks, @lrytz! 🍻 |
|
LGTM -- let's come back in 2.12.x and disable 0-ary eta expansion under -Xsource:2.13 |
|
is this release-notable, or a bit too obscure for that? |
|
i think we could add it. it's not that adding this one causes the release notes to overflow, it's more that they are already so long that it doesn't matter anymore :) |
|
I ran into this when upgrading play-twirl in the community build. The warning asks me, "Did you intend to write foo()?" But that's the wrong suggestion; what I want in my case is |
|
also, should this PR have included a spec update (to 6.26.2)? |
|
What should we update about the spec? We don't usually include notes on deprecation there, but maybe we should? Regarding the error message, the assumption in swapping the order of eta-expansion and empty-arg-list-application is that the latter is far more common than the former. Thus, the message shouldn't have to mention the former (if it's relevant enough to mention, maybe we shouldn't change the behavior?) |
|
6.26.2 says eta expansion comes before empty application. it's a chain of "Otherwise," clauses, and empty application is last in the chain. I have not followed this whole thing in detail, but I thought the whole point of SI-7187 was to change the order in 6.26.2. |
|
You understand correctly, except that the actual change is deferred until
|
|
ah. so SI-7187 shouldn't have been closed in JIRA, then? |
|
Yep, reopened. |
|
Given this, shouldn't I be getting a deprecation warning for the following code on Scala 2.12.0? package object mypackage {
def render() = {}
val handler: Function0[Any] = render _
}I see with I arrived here by way of #4822 (comment) in trying to understand why the code above is fine but using eta-expansion with other SAM-convertible types gives a compiler error due to type mismatch (scala-js/scala-js#2656). I see the release note
However, I would think that irrespective of this item and the note:
|
|
No, |
|
To elaborate a bit, because this is pretty confusing in the spec. The intent of the warning is to act only on implicit eta-expansion, not the explicit kind that is triggered by method value syntax. Method values are specified here: http://www.scala-lang.org/files/archive/spec/2.12/06-expressions.html#method-values:
Note that this means that On eta-expansion:
|
|
Personally, I would prefer to deprecate method value syntax in favor of writing out the function literal. Underscore already means too many things. |
that's now scala/scala-dev#273 |
In scala#5327, a change was made to typedEta to accept an original (ie, pre-typechecked) tree to be used in a fallback path. However, the caller provided an original tree larger than the actual tree being typechecked. This commit just passes the part of the orig tree that corresponds to the tree we're eta expanding, rather than the entire `Typed(methodValue, functionPt)` tree. That avoids an infinite loop in typechecking the erroneous code in the test case.
In scala#5327, a change was made to typedEta to accept an original (ie, pre-typechecked) tree to be used in a fallback path. However, the caller provided an original tree larger than the actual tree being typechecked. This commit just passes the part of the orig tree that corresponds to the tree we're eta expanding, rather than the entire `Typed(methodValue, functionPt)` tree. That avoids an infinite loop in typechecking the erroneous code in the test case.
In scala#5327, a change was made to typedEta to accept an original (ie, pre-typechecked) tree to be used in a fallback path. However, the caller provided an original tree larger than the actual tree being typechecked. This commit just passes the part of the orig tree that corresponds to the tree we're eta expanding, rather than the entire `Typed(methodValue, functionPt)` tree. That avoids an infinite loop in typechecking the erroneous code in the test case.
Fixes scala/bug#7187 scala#5327 deprecates eta-expansion of zero-arg method values. This removes it in 2.13.
For backwards compatiblity with 2.11, we already
don't adapt a zero-arg method value to a SAM.
In 2.13, we won't do any eta-expansion for zero-arg method values,
but we should deprecate first.
Re-submission of #5309
JIRA: https://issues.scala-lang.org/browse/SI-7187