Skip to content

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

Merged
merged 5 commits into from
Jun 6, 2018

Conversation

odersky
Copy link
Contributor

@odersky odersky commented May 20, 2018

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.

odersky added 3 commits May 20, 2018 15:21
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.
@odersky odersky changed the title Drop requirement that implicit/erased functions must be non-empty Drop requirement that implicit functions must be non-empty May 20, 2018
@odersky odersky requested a review from nicolasstucki May 21, 2018 17:16
@@ -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 =>
Copy link
Contributor

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)
Copy link
Contributor

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 and ErasedImplicitFuctionN at N = 1
  • Or allow them, as a function type that is equivalent to Funcion0 or ImplicitFunction0. We could even consider making them type aliases and warn the the erased keyword is useless.

Copy link
Contributor Author

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!

@odersky odersky assigned nicolasstucki and unassigned odersky May 28, 2018
@nicolasstucki nicolasstucki force-pushed the change-inline-untpd branch from 0068147 to c85cee0 Compare May 29, 2018 15:45
@nicolasstucki nicolasstucki dismissed their stale review May 29, 2018 15:46

I made the changes

@nicolasstucki
Copy link
Contributor

@odersky I added the requested changes. Appart from my part, the code LGTM. Can you have a look at the last commits.

Copy link
Contributor Author

@odersky odersky left a 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

@odersky odersky merged commit d0f1e60 into scala:master Jun 6, 2018
@allanrenucci allanrenucci deleted the change-inline-untpd branch June 6, 2018 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants