@@ -83,13 +83,28 @@ 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.
91
+ // Therefore we first approximate the base type, then use `baseArgInfos`
92
+ // to get correct refinements for the approximated base type, then
93
+ // recursively approximate the resulting type.
94
+ val base = tp.unrefine
95
+ if (toAvoid(base)) {
96
+ val base1 = apply(base)
97
+ apply(base1.appliedTo(tp.baseArgInfos(base1.typeSymbol)))
98
+ } else {
99
+ val parent1 = apply(tp.parent)
100
+ val refinedInfo1 = apply(tp.refinedInfo)
101
+ if (toAvoid(refinedInfo1)) {
102
+ typr.println(s " dropping refinement from $tp" )
103
+ parent1
104
+ } else {
105
+ tp.derivedRefinedType(parent1, name, refinedInfo1)
106
+ }
91
107
}
92
- else tp1
93
108
case tp : TypeVar if ctx.typerState.constraint.contains(tp) =>
94
109
val lo = ctx.typerState.constraint.fullLowerBound(tp.origin)
95
110
val lo1 = avoid(lo, symsToAvoid)
0 commit comments