-
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
Changes from 3 commits
d34b677
23afa6f
5f3c3e8
46c1ce4
c85cee0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -761,14 +761,10 @@ 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.NonEmptyFunction => | ||
if (args.nonEmpty) (tree.mods.is(Implicit), tree.mods.is(Erased)) | ||
else { | ||
ctx.error(FunctionTypeNeedsNonEmptyParameterList(tree.mods.is(Implicit), tree.mods.is(Erased)), tree.pos) | ||
(false, false) | ||
} | ||
case tree: untpd.FunctionWithMods => (tree.mods.is(Implicit), tree.mods.is(Erased)) | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. This looks inconsistent. We do provide names for
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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! |
||
val funCls = defn.FunctionClass(args.length, isImplicit, isErased) | ||
|
||
/** Typechecks dependent function type with given parameters `params` */ | ||
|
@@ -803,6 +799,11 @@ class Typer extends Namer | |
def typedFunctionValue(tree: untpd.Function, pt: Type)(implicit ctx: Context) = { | ||
val untpd.Function(params: List[untpd.ValDef] @unchecked, body) = tree | ||
|
||
val isImplicit = tree match { | ||
case tree: untpd.FunctionWithMods => tree.mods.is(Implicit) | ||
case _ => false | ||
} | ||
|
||
pt match { | ||
case pt: TypeVar if untpd.isFunctionWithUnknownParamType(tree) => | ||
// try to instantiate `pt` if this is possible. If it does not | ||
|
@@ -921,8 +922,8 @@ class Typer extends Namer | |
else cpy.ValDef(param)( | ||
tpt = untpd.TypeTree( | ||
inferredParamType(param, protoFormal(i)).underlyingIfRepeated(isJava = false))) | ||
val inlineable = pt.hasAnnotation(defn.InlineParamAnnot) | ||
desugar.makeClosure(inferredParams, fnBody, resultTpt, inlineable) | ||
val isInlineable = pt.hasAnnotation(defn.InlineParamAnnot) | ||
desugar.makeClosure(inferredParams, fnBody, resultTpt, isInlineable, isImplicit) | ||
} | ||
typed(desugared, pt) | ||
} | ||
|
@@ -947,7 +948,11 @@ class Typer extends Namer | |
|because it has internal parameter dependencies, | ||
|position = ${tree.pos}, raw type = ${mt.toString}""") // !!! DEBUG. Eventually, convert to an error? | ||
} | ||
else EmptyTree | ||
else if ((tree.tpt `eq` untpd.ImplicitEmptyTree) && mt.paramNames.isEmpty) | ||
// Note implicitness of function in target type sicne there are no method parameters that indicate it. | ||
TypeTree(defn.FunctionOf(Nil, mt.resType, isImplicit = true, isErased = false)) | ||
else | ||
EmptyTree | ||
} | ||
case tp => | ||
throw new java.lang.Error(i"internal error: closing over non-method $tp, pos = ${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.
cl
is never used