diff options
author | Martin Odersky <odersky@gmail.com> | 2014-01-02 16:04:04 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-01-02 16:04:17 +0100 |
commit | 09fdc8ee5705a80c361d3c07c49a5a660809a222 (patch) | |
tree | 19b1829d57455ddb53c80da6d7140c7fdc61749f /src/dotty/tools/dotc | |
parent | 502ad2204e0f286f3a1f7c343161613bd85dfb14 (diff) | |
download | dotty-09fdc8ee5705a80c361d3c07c49a5a660809a222.tar.gz dotty-09fdc8ee5705a80c361d3c07c49a5a660809a222.tar.bz2 dotty-09fdc8ee5705a80c361d3c07c49a5a660809a222.zip |
Taking a fully-defined result type into account when forming a closure.
Given
(params) => body
and an expected type
Ts => R
with R fully defined, we use R as the result type of the closure def into which the function is translated.
Note: It would be nice generalize this further to result types which are not fully defined, yet this would complicate things by entangling typing and desugaring.
Diffstat (limited to 'src/dotty/tools/dotc')
-rw-r--r-- | src/dotty/tools/dotc/ast/Desugar.scala | 4 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Typer.scala | 6 |
2 files changed, 5 insertions, 5 deletions
diff --git a/src/dotty/tools/dotc/ast/Desugar.scala b/src/dotty/tools/dotc/ast/Desugar.scala index 54ea96eed..7b483adb9 100644 --- a/src/dotty/tools/dotc/ast/Desugar.scala +++ b/src/dotty/tools/dotc/ast/Desugar.scala @@ -420,9 +420,9 @@ object desugar { * def $anonfun(params) = body * Closure($anonfun) */ - def makeClosure(params: List[ValDef], body: Tree) = + def makeClosure(params: List[ValDef], body: Tree, tpt: Tree = TypeTree()) = Block( - DefDef(Modifiers(Synthetic), nme.ANON_FUN, Nil, params :: Nil, TypeTree(), body), + DefDef(Modifiers(Synthetic), nme.ANON_FUN, Nil, params :: Nil, tpt, body), Closure(Nil, Ident(nme.ANON_FUN), EmptyTree)) /** Expand partial function diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 92ef0a266..c6c39f3e2 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -586,10 +586,10 @@ class Typer extends Namer with Applications with Implicits { cpy.ValDef(param, param.mods, param.name, paramTpt, param.rhs) } - /*val resultTpt = + val resultTpt = if (isFullyDefined(protoResult, ForceDegree.none)) untpd.TypeTree(protoResult) - else untpd.TypeTree()*/ - typed(desugar.makeClosure(inferredParams, fnBody/*, resultTpt*/), pt) + else untpd.TypeTree() + typed(desugar.makeClosure(inferredParams, fnBody, resultTpt), pt) } } |