@@ -83,13 +83,26 @@ trait TypeAssigner {
83
83
case _ =>
84
84
mapOver(tp)
85
85
}
86
- case tp : RefinedType =>
87
- val tp1 @ RefinedType (parent1, _) = mapOver(tp)
88
- if (toAvoid(tp1.refinedInfo) && variance > 0 ) {
89
- typr.println(s " dropping refinement from $tp1" )
90
- parent1
86
+ case tp @ RefinedType (parent, name) if variance > 0 =>
87
+ // The naive approach here would be to first approximate the parent,
88
+ // but if the base type of the approximated parent is different from
89
+ // the current base type, then the current refinement won't be valid
90
+ // if it's a type parameter refinement. Therefore, we first approximate
91
+ // the base type if needed, then recursively approximate the refinements.
92
+ val base = tp.unrefine
93
+ if (toAvoid(base)) {
94
+ val base1 = apply(base)
95
+ apply(base1.appliedTo(tp.baseArgInfos(base1.typeSymbol)))
96
+ } else {
97
+ val parent1 = apply(tp.parent)
98
+ val refinedInfo1 = apply(tp.refinedInfo)
99
+ if (toAvoid(refinedInfo1)) {
100
+ typr.println(s " dropping refinement from $tp" )
101
+ parent1
102
+ } else {
103
+ tp.derivedRefinedType(parent1, name, refinedInfo1)
104
+ }
91
105
}
92
- else tp1
93
106
case tp : TypeVar if ctx.typerState.constraint.contains(tp) =>
94
107
val lo = ctx.typerState.constraint.fullLowerBound(tp.origin)
95
108
val lo1 = avoid(lo, symsToAvoid)
0 commit comments