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