diff options
author | Martin Odersky <odersky@gmail.com> | 2013-08-01 18:21:23 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-08-01 18:21:23 +0200 |
commit | dbb4b3f7923427af4ba6e04f258309421d5ee1ab (patch) | |
tree | c8d47cbae32a0778d0bff3a22117d9d4a7c5ff7f /src/dotty/tools/dotc/ast/TypedTrees.scala | |
parent | 413f364887d5bde7610adbbc08020e23470b4c8c (diff) | |
download | dotty-dbb4b3f7923427af4ba6e04f258309421d5ee1ab.tar.gz dotty-dbb4b3f7923427af4ba6e04f258309421d5ee1ab.tar.bz2 dotty-dbb4b3f7923427af4ba6e04f258309421d5ee1ab.zip |
Handling typevars in inference.
Fleshed out handling of typevars for type inference. Also added some more methods to typer, for blocks, ifs and assignments. (Closures are still wip).
Diffstat (limited to 'src/dotty/tools/dotc/ast/TypedTrees.scala')
-rw-r--r-- | src/dotty/tools/dotc/ast/TypedTrees.scala | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/dotty/tools/dotc/ast/TypedTrees.scala b/src/dotty/tools/dotc/ast/TypedTrees.scala index cea799116..037180161 100644 --- a/src/dotty/tools/dotc/ast/TypedTrees.scala +++ b/src/dotty/tools/dotc/ast/TypedTrees.scala @@ -85,15 +85,17 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { def Assign(lhs: Tree, rhs: Tree)(implicit ctx: Context): Assign = untpd.Assign(lhs, rhs).withType(defn.UnitType).checked - def Block(stats: List[Tree], expr: Tree)(implicit ctx: Context): Block = { + def Block(stats: List[Tree], expr: Tree)(implicit ctx: Context): Block = + untpd.Block(stats, expr).withType(blockType(stats, expr.tpe)).checked + + def blockType(stats: List[Tree], exprType: Type)(implicit ctx: Context): Type = { lazy val locals = localSyms(stats).toSet - val blk = untpd.Block(stats, expr) def widen(tp: Type): Type = tp match { case tp: TermRef if locals contains tp.symbol => widen(tp.info) case _ => tp } - blk.withType(widen(expr.tpe)) + widen(exprType) } def maybeBlock(stats: List[Tree], expr: Tree)(implicit ctx: Context): Tree = @@ -102,14 +104,14 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { def If(cond: Tree, thenp: Tree, elsep: Tree)(implicit ctx: Context): If = untpd.If(cond, thenp, elsep).withType(thenp.tpe | elsep.tpe).checked - def Closure(env: List[Tree], meth: RefTree)(implicit ctx: Context): Closure = { - val ownType = meth.tpe.widen match { - case mt @ MethodType(_, formals) => - assert(!mt.isDependent) - val formals1 = formals mapConserve (_.underlyingIfRepeated) - defn.FunctionType(formals1, mt.resultType) - } - untpd.Closure(env, meth).withType(ownType).checked + def Closure(env: List[Tree], meth: RefTree)(implicit ctx: Context): Closure = + untpd.Closure(env, meth).withType(closureType(meth.tpe.widen)).checked + + def closureType(tp: Type)(implicit ctx: Context) = tp match { + case mt @ MethodType(_, formals) => + assert(!mt.isDependent) + val formals1 = formals mapConserve (_.underlyingIfRepeated) + defn.FunctionType(formals1, mt.resultType) } /** A function def |