diff options
author | Martin Odersky <odersky@gmail.com> | 2013-12-26 13:30:34 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-12-26 13:38:33 +0100 |
commit | 1cf1ee2fbe2f56cf404d157825a956aa0956405f (patch) | |
tree | ebf65e1d644849afc3b8b1832e8f75129fc13d6a /src/dotty/tools | |
parent | 6c292cb1f633a429149fef227ccfe4c2af4035af (diff) | |
download | dotty-1cf1ee2fbe2f56cf404d157825a956aa0956405f.tar.gz dotty-1cf1ee2fbe2f56cf404d157825a956aa0956405f.tar.bz2 dotty-1cf1ee2fbe2f56cf404d157825a956aa0956405f.zip |
Fix to blockType for automatic widening.
Need to apply widening within types, not just at toplevel.
Diffstat (limited to 'src/dotty/tools')
-rw-r--r-- | src/dotty/tools/dotc/ast/tpd.scala | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/ast/tpd.scala b/src/dotty/tools/dotc/ast/tpd.scala index 3e2b0d7f9..70016c0a6 100644 --- a/src/dotty/tools/dotc/ast/tpd.scala +++ b/src/dotty/tools/dotc/ast/tpd.scala @@ -92,11 +92,29 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { untpd.Block(stats, expr).withType(blockType(stats, expr.tpe)).checked def blockType(stats: List[Tree], exprType: Type)(implicit ctx: Context): Type = { + val widenMap = new TypeMap { + lazy val locals = localSyms(stats).toSet + def apply(tp: Type) = tp match { + case tp: TermRef if tp.symbol.owner.isTerm && (locals contains tp.symbol) => + apply(tp.info) + case _ => + mapOver(tp) + } + } lazy val locals = localSyms(stats).toSet - def widen(tp: Type): Type = tp match { - case tp: TermRef if locals contains tp.symbol => + def containsLocals(tp: Type) = + tp.namedPartsWith(part => locals contains part.symbol).nonEmpty + def widen(tp: Type): Type = tp.stripTypeVar match { + case tp: TermRef if containsLocals(tp) => widen(tp.info) - case _ => tp + case tp: TypeRef if !tp.symbol.isClass && containsLocals(tp) => + widen(tp.info.bounds.hi) + case tp: ExprType => + tp.derivedExprType(widen(tp.resultType)) + case tp: AnnotatedType if containsLocals(tp) => + widen(tp.underlying) + case _ => + tp } widen(exprType) } |