aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc/typer/Typer.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2017-03-11 20:56:02 +0100
committerMartin Odersky <odersky@gmail.com>2017-03-12 12:11:49 +0100
commitfac74a618ae4666490cd8c7fd3f9604d877562d9 (patch)
tree6ceb2db2beb93a0faec2d46933362d9470ff4209 /compiler/src/dotty/tools/dotc/typer/Typer.scala
parentb2d3b8938391516e81f18962e67f5bacf0aa2440 (diff)
downloaddotty-fac74a618ae4666490cd8c7fd3f9604d877562d9.tar.gz
dotty-fac74a618ae4666490cd8c7fd3f9604d877562d9.tar.bz2
dotty-fac74a618ae4666490cd8c7fd3f9604d877562d9.zip
Fix #1569: Improve avoidance algorithm
The essential change is that we do not throw away more precise info of the avoided type if the expected type is fully defined.
Diffstat (limited to 'compiler/src/dotty/tools/dotc/typer/Typer.scala')
-rw-r--r--compiler/src/dotty/tools/dotc/typer/Typer.scala14
1 files changed, 10 insertions, 4 deletions
diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala
index ba14b7498..c43a8adcd 100644
--- a/compiler/src/dotty/tools/dotc/typer/Typer.scala
+++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala
@@ -642,12 +642,18 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
}
val leaks = escapingRefs(tree, localSyms)
if (leaks.isEmpty) tree
- else if (isFullyDefined(pt, ForceDegree.none)) ascribeType(tree, pt)
else if (!forcedDefined) {
fullyDefinedType(tree.tpe, "block", tree.pos)
- val tree1 = ascribeType(tree, avoid(tree.tpe, localSyms))
- ensureNoLocalRefs(tree1, pt, localSyms, forcedDefined = true)
- } else
+ val avoidingType = avoid(tree.tpe, localSyms)
+ if (isFullyDefined(pt, ForceDegree.none) && !(avoidingType <:< pt))
+ ascribeType(tree, pt)
+ else {
+ val tree1 = ascribeType(tree, avoidingType)
+ ensureNoLocalRefs(tree1, pt, localSyms, forcedDefined = true)
+ }
+ } else if (isFullyDefined(pt, ForceDegree.none))
+ ascribeType(tree, pt)
+ else
errorTree(tree,
em"local definition of ${leaks.head.name} escapes as part of expression's type ${tree.tpe}"/*; full type: ${result.tpe.toString}"*/)
}