@@ -302,14 +302,19 @@ trait ConstraintHandling {
302
302
false
303
303
else
304
304
val bound = legalBound(param, rawBound, isUpper)
305
+
306
+ // If the narrowed bounds are equal and not recursive,
307
+ // we can remove `param` from the constraint.
308
+ def replaceIfEqualBounds : Boolean =
309
+ val TypeBounds (lo, hi) = constraint.nonParamBounds(param)
310
+ val equalBounds = (if isUpper then lo else hi) eq bound
311
+ if equalBounds && ! bound.existsPart(_ eq param, StopAt .Static ) then
312
+ constraint = constraint.replace(param, bound)
313
+ true
314
+ else false
315
+
305
316
val oldBounds @ TypeBounds (lo, hi) = constraint.nonParamBounds(param)
306
- val equalBounds = (if isUpper then lo else hi) eq bound
307
- if equalBounds && ! bound.existsPart(_ eq param, StopAt .Static ) then
308
- // The narrowed bounds are equal and not recursive,
309
- // so we can remove `param` from the constraint.
310
- constraint = constraint.replace(param, bound)
311
- true
312
- else
317
+ replaceIfEqualBounds || {
313
318
// Narrow one of the bounds of type parameter `param`
314
319
// If `isUpper` is true, ensure that `param <: `bound`, otherwise ensure
315
320
// that `param >: bound`.
@@ -328,8 +333,13 @@ trait ConstraintHandling {
328
333
|| {
329
334
constraint = c1
330
335
val TypeBounds (lo, hi) = constraint.entry(param): @ unchecked
331
- isSub(lo, hi)
336
+ isSub(lo, hi) && {
337
+ // isSub may have introduced new constraints
338
+ replaceIfEqualBounds
339
+ true
340
+ }
332
341
}
342
+ }
333
343
end addOneBound
334
344
335
345
protected def addBoundTransitively (param : TypeParamRef , rawBound : Type , isUpper : Boolean )(using Context ): Boolean =
0 commit comments