Skip to content

Commit

Permalink
Refinement of interpolation direction
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Oct 13, 2016
1 parent a45a3e5 commit 5d531ec
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/dotty/tools/dotc/core/ConstraintHandling.scala
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,25 @@ trait ConstraintHandling {
case tp: RefinedType if param occursIn tp.refinedInfo => tp.parent
case tp: WildcardType =>
val bounds = tp.optBounds.orElse(TypeBounds.empty).bounds
if (fromBelow == (variance >= 0)) bounds.lo else bounds.hi
// Try to instantiate the wildcard to a type that is known to conform to it.
// This means:
// If fromBelow is true, we minimize the type overall
// Hence, if variance < 0, pick the maximal safe type: bounds.lo
// (i.e. the whole bounds range is over the type)
// if variance > 0, pick the minimal safe type: bounds.hi
// (i.e. the whole bounds range is under the type)
// if variance == 0, pick bounds.lo anyway (this is arbitrary but in line with
// the principle that we pick the smaller type when in doubt).
// If fromBelow is false, we maximize the type overall and reverse the bounds
// if variance != 0. For variance == 0, we still minimize.
// In summary we pick the bound given by this table:
//
// variance | -1 0 1
// ------------------------
// from below | lo lo hi
// from above | hi lo lo
//
if (variance == 0 || fromBelow == (variance < 0)) bounds.lo else bounds.hi
case _ => tp
}
}
Expand Down
9 changes: 9 additions & 0 deletions tests/pos/i1590.scala
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
case class W[T](seq: Option[Option[T]] = Option.empty)
object W {
def apply[T] = new W[T]()
}

case class V[T](vv: W[W[T]] = W.apply)
object Test {
W[Int]()
// V[Int]() fails in scalac and dotty: both instantiate the vv-default to W[Nothing]
}

0 comments on commit 5d531ec

Please sign in to comment.