Skip to content

Commit a45a3e5

Browse files
committed
Fix #1590: Eliminate wildcards when approximating a type
Fixes #1590. Type variables should never be instantiated to types containing wildcards.
1 parent dac5b93 commit a45a3e5

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/dotty/tools/dotc/core/ConstraintHandling.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ trait ConstraintHandling {
162162
/** Solve constraint set for given type parameter `param`.
163163
* If `fromBelow` is true the parameter is approximated by its lower bound,
164164
* otherwise it is approximated by its upper bound. However, any occurrences
165-
* of the parameter in a refinement somewhere in the bound are removed.
165+
* of the parameter in a refinement somewhere in the bound are removed. Also
166+
* wildcard types in bounds are approximated by their upper or lower bounds.
166167
* (Such occurrences can arise for F-bounded types).
167168
* The constraint is left unchanged.
168169
* @return the instantiating type
@@ -174,6 +175,9 @@ trait ConstraintHandling {
174175
def apply(tp: Type) = mapOver {
175176
tp match {
176177
case tp: RefinedType if param occursIn tp.refinedInfo => tp.parent
178+
case tp: WildcardType =>
179+
val bounds = tp.optBounds.orElse(TypeBounds.empty).bounds
180+
if (fromBelow == (variance >= 0)) bounds.lo else bounds.hi
177181
case _ => tp
178182
}
179183
}

tests/pos/i1590.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
case class W[T](seq: Option[Option[T]] = Option.empty)

0 commit comments

Comments
 (0)