aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-10-13 16:51:05 +0200
committerMartin Odersky <odersky@gmail.com>2016-10-13 16:51:18 +0200
commita45a3e5f573fc5b768fcd0d6be507a0af8fd53cc (patch)
tree4ca6be161907fa2d19d1289c5ee0956c02302a81
parentdac5b931bcf8757070c8aa74571e52f3b4c6e5eb (diff)
downloaddotty-a45a3e5f573fc5b768fcd0d6be507a0af8fd53cc.tar.gz
dotty-a45a3e5f573fc5b768fcd0d6be507a0af8fd53cc.tar.bz2
dotty-a45a3e5f573fc5b768fcd0d6be507a0af8fd53cc.zip
Fix #1590: Eliminate wildcards when approximating a type
Fixes #1590. Type variables should never be instantiated to types containing wildcards.
-rw-r--r--src/dotty/tools/dotc/core/ConstraintHandling.scala6
-rw-r--r--tests/pos/i1590.scala1
2 files changed, 6 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/core/ConstraintHandling.scala b/src/dotty/tools/dotc/core/ConstraintHandling.scala
index 3835d553c..95fa40704 100644
--- a/src/dotty/tools/dotc/core/ConstraintHandling.scala
+++ b/src/dotty/tools/dotc/core/ConstraintHandling.scala
@@ -162,7 +162,8 @@ trait ConstraintHandling {
/** Solve constraint set for given type parameter `param`.
* If `fromBelow` is true the parameter is approximated by its lower bound,
* otherwise it is approximated by its upper bound. However, any occurrences
- * of the parameter in a refinement somewhere in the bound are removed.
+ * of the parameter in a refinement somewhere in the bound are removed. Also
+ * wildcard types in bounds are approximated by their upper or lower bounds.
* (Such occurrences can arise for F-bounded types).
* The constraint is left unchanged.
* @return the instantiating type
@@ -174,6 +175,9 @@ trait ConstraintHandling {
def apply(tp: Type) = mapOver {
tp match {
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
case _ => tp
}
}
diff --git a/tests/pos/i1590.scala b/tests/pos/i1590.scala
new file mode 100644
index 000000000..a8f36de45
--- /dev/null
+++ b/tests/pos/i1590.scala
@@ -0,0 +1 @@
+case class W[T](seq: Option[Option[T]] = Option.empty)