@@ -357,17 +357,22 @@ final class ProperGadtConstraint private(
357
357
tp.derivedAndOrType(loop(tp1), loop(tp2))
358
358
case tp @ OrType (tp1, tp2) if isUpper =>
359
359
tp.derivedOrType(loop(tp1), loop(tp2))
360
- case tp @ TypeRef (prefix, des ) if prefix eq path =>
360
+ case tp @ TypeRef (prefix, _ ) if prefix eq path =>
361
361
typeMemberSymbols indexOf tp.symbol match
362
362
case - 1 => tp
363
363
case idx => pt.paramRefs(idx)
364
- case tp @ TypeRef (_ : RecThis , des ) =>
364
+ case tp @ TypeRef (_ : RecThis , _ ) =>
365
365
typeMemberSymbols indexOf tp.symbol match
366
366
case - 1 => tp
367
367
case idx => pt.paramRefs(idx)
368
368
case tp : TypeRef =>
369
369
tvarOf(tp) match {
370
- case tv : TypeVar => tv.origin
370
+ case tv : TypeVar =>
371
+ val tp = stripInternalTypeVar(tv)
372
+ tp.match {
373
+ case tv1 : TypeVar => stripTypeVarWhenDependent(tv1)
374
+ case tp => tp
375
+ }
371
376
case null => tp
372
377
}
373
378
case tp => tp
@@ -450,7 +455,12 @@ final class ProperGadtConstraint private(
450
455
params.indexOf(tp.symbol) match {
451
456
case - 1 =>
452
457
mapping(tp.symbol) match {
453
- case tv : TypeVar => tv.origin
458
+ case tv : TypeVar =>
459
+ val tp = stripInternalTypeVar(tv)
460
+ tp.match {
461
+ case tv1 : TypeVar => stripTypeVarWhenDependent(tv1)
462
+ case tp => tp
463
+ }
454
464
case null => tp
455
465
}
456
466
case i => pt.paramRefs(i)
@@ -480,13 +490,22 @@ final class ProperGadtConstraint private(
480
490
.showing(i " added to constraint: [ $poly1] $params%, % \n $debugBoundsDescription" , gadts)
481
491
}
482
492
493
+ @ annotation.tailrec private def stripInternalTypeVar (tp : Type ): Type = tp match {
494
+ case tv : TypeVar =>
495
+ val inst = constraint.instType(tv)
496
+ if (inst.exists) stripInternalTypeVar(inst) else tv
497
+ case _ => tp
498
+ }
499
+
500
+ private def stripTypeVarWhenDependent (tv : TypeVar ): TypeParamRef | TypeVar =
501
+ val tpr = tv.origin
502
+ if constraint.contains(tpr) then
503
+ tpr
504
+ else
505
+ tv
506
+ end stripTypeVarWhenDependent
507
+
483
508
private def addBoundForTvar (tvar : TypeVar , bound : Type , isUpper : Boolean , typeRepr : String )(using Context ): Boolean = {
484
- @ annotation.tailrec def stripInternalTypeVar (tp : Type ): Type = tp match {
485
- case tv : TypeVar =>
486
- val inst = constraint.instType(tv)
487
- if (inst.exists) stripInternalTypeVar(inst) else tv
488
- case _ => tp
489
- }
490
509
491
510
val symTvar : TypeVar = stripInternalTypeVar(tvar) match {
492
511
case tv : TypeVar => tv
0 commit comments