diff options
author | Martin Odersky <odersky@gmail.com> | 2016-12-05 10:34:58 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-12-17 18:34:27 +0100 |
commit | bcc80ad1343a3ed01bef55f494d9658cf02226c6 (patch) | |
tree | 5fb2feecdf0df524128c72d14a6402fd6c547291 /compiler/src/dotty/tools/dotc/ast/TreeInfo.scala | |
parent | 0336785a2280a4a1e51e739e9aac3d5015f7c16f (diff) | |
download | dotty-bcc80ad1343a3ed01bef55f494d9658cf02226c6.tar.gz dotty-bcc80ad1343a3ed01bef55f494d9658cf02226c6.tar.bz2 dotty-bcc80ad1343a3ed01bef55f494d9658cf02226c6.zip |
Create implicit closures to math expected implicit functions
When the expected type is an implicit function, create an
implicit closure to match it.
Diffstat (limited to 'compiler/src/dotty/tools/dotc/ast/TreeInfo.scala')
-rw-r--r-- | compiler/src/dotty/tools/dotc/ast/TreeInfo.scala | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala index ae7c93784..da83d0644 100644 --- a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala +++ b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala @@ -290,6 +290,16 @@ trait UntypedTreeInfo extends TreeInfo[Untyped] { self: Trees.Instance[Untyped] case _ => false } + /** Is `tree` an implicit function or closure, possibly nested in a block? */ + def isImplicitClosure(tree: Tree)(implicit ctx: Context): Boolean = unsplice(tree) match { + case Function((param: untpd.ValDef) :: _, _) => param.mods.is(Implicit) + case Closure(_, meth, _) => true + case Block(Nil, expr) => isImplicitClosure(expr) + case Block(DefDef(nme.ANON_FUN, _, (param :: _) :: _, _, _) :: Nil, _: Closure) => + param.mods.is(Implicit) + case _ => false + } + // todo: fill with other methods from TreeInfo that only apply to untpd.Tree's } @@ -507,8 +517,6 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] => } } - def isClosure(tree: Tree) = closure.unapply(tree).isDefined - /** If tree is a closure, its body, otherwise tree itself */ def closureBody(tree: Tree)(implicit ctx: Context): Tree = tree match { case Block((meth @ DefDef(nme.ANON_FUN, _, _, _, _)) :: Nil, Closure(_, _, _)) => meth.rhs |