diff options
author | Martin Odersky <odersky@gmail.com> | 2014-08-16 11:55:57 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-08-16 11:56:07 +0200 |
commit | 7d414eb69b28fa0f6855168aa7afe43a75b3f23e (patch) | |
tree | c6410e0331a0f43bde6876337db21415e0f81235 /src/dotty/tools/dotc/transform/Erasure.scala | |
parent | c54cd3e0503144f362ecb000109b75a0a53b3165 (diff) | |
download | dotty-7d414eb69b28fa0f6855168aa7afe43a75b3f23e.tar.gz dotty-7d414eb69b28fa0f6855168aa7afe43a75b3f23e.tar.bz2 dotty-7d414eb69b28fa0f6855168aa7afe43a75b3f23e.zip |
Roll Uncurry into Erasure
Making cpy recompute types uncovered errors in uncurry. In a nutshell,
the intermediate Apply nodes of a curried function were ill-typed, which
caused errors produced by TypeAssigner. These nodes were eliminated down the
road, but the errors are already issued.
I did not find a good way to treat uncurry as a treetransform. Since it is rather
trivial, it did not seem warranted to make it a full transformer either. So in
the end the uncurry functionality became part of erasure.
Diffstat (limited to 'src/dotty/tools/dotc/transform/Erasure.scala')
-rw-r--r-- | src/dotty/tools/dotc/transform/Erasure.scala | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/dotty/tools/dotc/transform/Erasure.scala b/src/dotty/tools/dotc/transform/Erasure.scala index 6b2a5a676..f02846735 100644 --- a/src/dotty/tools/dotc/transform/Erasure.scala +++ b/src/dotty/tools/dotc/transform/Erasure.scala @@ -264,13 +264,28 @@ object Erasure { override def typedApply(tree: untpd.Apply, pt: Type)(implicit ctx: Context): Tree = { val Apply(fun, args) = tree - val fun1 = typedExpr(fun, WildcardType) - fun1.tpe.widen match { - case mt: MethodType => - val args1 = args.zipWithConserve(mt.paramTypes)(typedExpr) - untpd.cpy.Apply(tree)(fun1, args1) withType mt.resultType + fun match { + case fun: Apply => + typedApply(fun, pt)(ctx.fresh.setTree(tree)) case _ => - throw new MatchError(i"tree $tree has uxpected type of function ${fun1.tpe.widen}, was ${fun.typeOpt.widen}") + def nextOuter(ctx: Context): Context = + if (ctx.outer.tree eq tree) nextOuter(ctx.outer) else ctx.outer + def contextArgs(tree: untpd.Apply)(implicit ctx: Context): List[untpd.Tree] = + ctx.tree match { + case enclApp @ Apply(enclFun, enclArgs) if enclFun eq tree => + enclArgs ++ contextArgs(enclApp)(nextOuter(ctx)) + case _ => + Nil + } + val allArgs = args ++ contextArgs(tree) + val fun1 = typedExpr(fun, WildcardType) + fun1.tpe.widen match { + case mt: MethodType => + val allArgs1 = allArgs.zipWithConserve(mt.paramTypes)(typedExpr) + untpd.cpy.Apply(tree)(fun1, allArgs1) withType mt.resultType + case _ => + throw new MatchError(i"tree $tree has unexpected type of function ${fun1.tpe.widen}, was ${fun.typeOpt.widen}") + } } } |