-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Drop requirement that implicit functions must be non-empty #4549
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
It's the kind of trivial requirement we should not do. In the case of implicit function types, it turns out that it even blocks something that would be useful! Also, rename NonEmptyFunction to FunctionWithMods.
On the other hand, empty erased function types are again disabled, since they will be compatible with no closures at all. Note: I did not re-instantiate the tests for disallowing empty erased functions. As is so often the case, the most trivial properties get the most tests, precisely because they are easiest to test. But in the end, that just contributes to noise and friction if one wants to change things. neg/i2642.scala does test the relevant bits, that should be enough.
@@ -32,9 +34,12 @@ class ExpandSAMs extends MiniPhase { | |||
ctx.platform.isSam(cls) | |||
|
|||
override def transformBlock(tree: Block)(implicit ctx: Context): Tree = tree match { | |||
case Block(stats @ (fn: DefDef) :: Nil, Closure(_, fnRef, tpt)) if fnRef.symbol == fn.symbol => | |||
case Block(stats @ (fn: DefDef) :: Nil, cl @ Closure(_, fnRef, tpt)) if fnRef.symbol == fn.symbol => |
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.
cl
is never used
case _ => (false, false) | ||
} | ||
if (isErased && args.isEmpty) ctx.error(em"empty function cannot not be erased", tree.pos) |
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 looks inconsistent. We do provide names for ErasedFunction0
and ErasedImplicitFunction0
and add them in scope, but we do not allow them to be used in function types.
- We could remove the start
ErasedFuctionN
andErasedImplicitFuctionN
atN = 1
- Or allow them, as a function type that is equivalent to
Funcion0
orImplicitFunction0
. We could even consider making them type aliases and warn the theerased
keyword is useless.
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.
@nicolasstucki Agree we should start ErasedFunctionN at 1. Can you do the change and push it on top of this PR? Thanks!
0068147
to
c85cee0
Compare
@odersky I added the requested changes. Appart from my part, the code LGTM. Can you have a look at the last commits. |
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 for the latest changes by @nicolasstucki
This removes an arbitrary restriction and is a first step towards unifying by-name types and implicit function types.
It's been trickier than anticipated since we needed a new mechanism to mark nullary implicit closures. Without parameters we cannot look at the parameter modifiers. Instead we produce an implicit function type as closure target type.