Skip to content

Commit f0fe97f

Browse files
committed
Don't let wildcards enter constraints when adding type lambdas
1 parent ee939f1 commit f0fe97f

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,11 @@ trait ConstraintHandling {
9191
// so we shouldn't allow them as constraints either.
9292
false
9393
else
94-
val dropWildcards = new ApproximatingTypeMap:
94+
val dropWildcards = new AvoidWildcardsMap:
9595
if !isUpper then variance = -1
96-
def apply(t: Type): Type = t match
97-
case t: WildcardType =>
98-
if approximateWildcards then
99-
val bounds = t.effectiveBounds
100-
range(bounds.lo, bounds.hi)
101-
else
102-
newTypeVar(apply(t.effectiveBounds).toBounds)
103-
case _ =>
104-
mapOver(t)
96+
override def mapWild(t: WildcardType) =
97+
if approximateWildcards then super.mapWild(t)
98+
else newTypeVar(apply(t.effectiveBounds).toBounds)
10599
val bound = dropWildcards(rawBound)
106100
val oldBounds @ TypeBounds(lo, hi) = constraint.nonParamBounds(param)
107101
val equalBounds = (if isUpper then lo else hi) eq bound

compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,11 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
280280
var current = this
281281
val todos = new mutable.ListBuffer[(OrderingConstraint, TypeParamRef) => OrderingConstraint]
282282
var i = 0
283+
val dropWildcards = AvoidWildcardsMap()
283284
while (i < poly.paramNames.length) {
284285
val param = poly.paramRefs(i)
285-
val stripped = stripParams(nonParamBounds(param), todos, isUpper = true)
286+
val bounds = dropWildcards(nonParamBounds(param))
287+
val stripped = stripParams(bounds, todos, isUpper = true)
286288
current = updateEntry(current, param, stripped)
287289
while todos.nonEmpty do
288290
current = todos.head(current, param)

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5701,6 +5701,15 @@ object Types {
57015701
lo.toText(printer) ~ ".." ~ hi.toText(printer)
57025702
}
57035703

5704+
/** Approximate wildcards by their bounds */
5705+
class AvoidWildcardsMap(using Context) extends ApproximatingTypeMap:
5706+
protected def mapWild(t: WildcardType) =
5707+
val bounds = t.effectiveBounds
5708+
range(atVariance(-variance)(apply(bounds.lo)), apply(bounds.hi))
5709+
def apply(t: Type): Type = t match
5710+
case t: WildcardType => mapWild(t)
5711+
case _ => mapOver(t)
5712+
57045713
// ----- TypeAccumulators ----------------------------------------------------
57055714

57065715
abstract class TypeAccumulator[T](implicit protected val accCtx: Context)

0 commit comments

Comments
 (0)