@@ -98,7 +98,7 @@ object Inferencing {
98
98
inst
99
99
}
100
100
101
- private var toMaximize : Boolean = false
101
+ private var toMaximize : List [ TypeVar ] = Nil
102
102
103
103
def apply (x : Boolean , tp : Type ): Boolean = tp.dealias match {
104
104
case _ : WildcardType | _ : ProtoType =>
@@ -113,29 +113,24 @@ object Inferencing {
113
113
|| variance >= 0 && (force.allowBottom || tvar.hasLowerBound)
114
114
if (direction != 0 ) instantiate(tvar, direction < 0 )
115
115
else if (preferMin) instantiate(tvar, fromBelow = true )
116
- else toMaximize = true
116
+ else toMaximize = tvar :: toMaximize
117
117
foldOver(x, tvar)
118
118
}
119
119
case tp =>
120
120
foldOver(x, tp)
121
121
}
122
122
123
- private class UpperInstantiator (implicit ctx : Context ) extends TypeAccumulator [Unit ] {
124
- def apply (x : Unit , tp : Type ): Unit = {
125
- tp match {
126
- case tvar : TypeVar if ! tvar.isInstantiated =>
123
+ def process (tp : Type ): Boolean =
124
+ // Maximize type vars in the order they were visited before */
125
+ def maximize (tvars : List [TypeVar ]): Unit = tvars match
126
+ case tvar :: tvars1 =>
127
+ maximize(tvars1)
128
+ if ! tvar.isInstantiated then
127
129
instantiate(tvar, fromBelow = false )
128
- case _ =>
129
- }
130
- foldOver(x, tp)
131
- }
132
- }
133
-
134
- def process (tp : Type ): Boolean = {
130
+ case nil =>
135
131
val res = apply(true , tp)
136
- if ( res && toMaximize) new UpperInstantiator ().apply((), tp )
132
+ if res then maximize(toMaximize )
137
133
res
138
- }
139
134
}
140
135
141
136
/** For all type parameters occurring in `tp`:
0 commit comments