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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Start ErasedFunctionN and ErasedImplicitFunctionN at N=1
  • Loading branch information
nicolasstucki committed May 29, 2018
commit c85cee08642755a55fa1b0b9cb768b52e04fec4c
21 changes: 9 additions & 12 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -894,26 +894,23 @@ class Definitions {
def isBottomType(tp: Type) =
tp.derivesFrom(NothingClass) || tp.derivesFrom(NullClass)

/** Is a function class, i.e. on of
* - FunctionN
* - ImplicitFunctionN
* - ErasedFunctionN
* - ErasedImplicitFunctionN
* for N >= 0
/** Is a function class.
* - FunctionN for N >= 0
* - ImplicitFunctionN for N >= 0
* - ErasedFunctionN for N > 0
* - ErasedImplicitFunctionN for N > 0
*/
def isFunctionClass(cls: Symbol) = scalaClassName(cls).isFunction

/** Is an implicit function class.
* - ImplicitFunctionN
* - ErasedImplicitFunctionN
* for N >= 0
* - ImplicitFunctionN for N >= 0
* - ErasedImplicitFunctionN for N > 0
*/
def isImplicitFunctionClass(cls: Symbol) = scalaClassName(cls).isImplicitFunction

/** Is an erased function class.
* - ErasedFunctionN
* - ErasedImplicitFunctionN
* for N >= 0
* - ErasedFunctionN for N > 0
* - ErasedImplicitFunctionN for N > 0
*/
def isErasedFunctionClass(cls: Symbol) = scalaClassName(cls).isErasedFunction

Expand Down
25 changes: 14 additions & 11 deletions compiler/src/dotty/tools/dotc/core/NameOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -169,33 +169,36 @@ object NameOps {

def functionArity: Int =
functionArityFor(str.Function) max
functionArityFor(str.ImplicitFunction) max
functionArityFor(str.ErasedFunction) max
functionArityFor(str.ErasedImplicitFunction)
functionArityFor(str.ImplicitFunction) max {
val n =
functionArityFor(str.ErasedFunction) max
functionArityFor(str.ErasedImplicitFunction)
if (n == 0) -1 else n
}

/** Is a function name, i.e one of FunctionN, ImplicitFunctionN, ErasedFunctionN, ErasedImplicitFunctionN for N >= 0
/** Is a function name, i.e one of FunctionN, ImplicitFunctionN for N >= 0 or ErasedFunctionN, ErasedImplicitFunctionN for N > 0
*/
def isFunction: Boolean = functionArity >= 0

/** Is an implicit function name, i.e one of ImplicitFunctionN, ErasedImplicitFunctionN for N >= 0
/** Is an implicit function name, i.e one of ImplicitFunctionN for N >= 0 or ErasedImplicitFunctionN for N > 0
*/
def isImplicitFunction: Boolean = {
functionArityFor(str.ImplicitFunction) >= 0 ||
functionArityFor(str.ErasedImplicitFunction) >= 0
functionArityFor(str.ErasedImplicitFunction) > 0
}

/** Is an erased function name, i.e. one of ErasedFunctionN, ErasedImplicitFunctionN for N >= 0
/** Is an erased function name, i.e. one of ErasedFunctionN, ErasedImplicitFunctionN for N > 0
*/
def isErasedFunction: Boolean = {
functionArityFor(str.ErasedFunction) >= 0 ||
functionArityFor(str.ErasedImplicitFunction) >= 0
functionArityFor(str.ErasedFunction) > 0 ||
functionArityFor(str.ErasedImplicitFunction) > 0
}

/** Is a synthetic function name, i.e. one of
* - FunctionN for N > 22
* - ImplicitFunctionN for N >= 0
* - ErasedFunctionN for N >= 0
* - ErasedImplicitFunctionN for N >= 0
* - ErasedFunctionN for N > 0
* - ErasedImplicitFunctionN for N > 0
*/
def isSyntheticFunction: Boolean = {
functionArityFor(str.Function) > MaxImplementedFunctionArity ||
Expand Down
11 changes: 9 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -761,10 +761,17 @@ class Typer extends Namer
def typedFunctionType(tree: untpd.Function, pt: Type)(implicit ctx: Context) = {
val untpd.Function(args, body) = tree
val (isImplicit, isErased) = tree match {
case tree: untpd.FunctionWithMods => (tree.mods.is(Implicit), tree.mods.is(Erased))
case tree: untpd.FunctionWithMods =>
val isImplicit = tree.mods.is(Implicit)
var isErased = tree.mods.is(Erased)
if (isErased && args.isEmpty) {
ctx.error("An empty function cannot not be erased", tree.pos)
isErased = false
}
(isImplicit, isErased)
case _ => (false, false)
}
if (isErased && args.isEmpty) ctx.error(em"empty function cannot not be erased", tree.pos)

val funCls = defn.FunctionClass(args.length, isImplicit, isErased)

/** Typechecks dependent function type with given parameters `params` */
Expand Down