@@ -6,7 +6,7 @@ import Types._, Contexts._, Symbols._
66import Decorators ._
77import config .Config
88import config .Printers .{constr , typr }
9- import TypeApplications .EtaExpansion
9+ import TypeApplications .{ EtaExpansion , TypeParamInfo }
1010import collection .mutable
1111
1212/** Methods for adding constraints and solving them.
@@ -194,9 +194,14 @@ trait ConstraintHandling {
194194 final def approximation (param : TypeParamRef , fromBelow : Boolean ): Type = {
195195 val avoidParam = new TypeMap {
196196 override def stopAtStatic = true
197+ def avoidInArg (arg : Type ): Type =
198+ if (param.occursIn(arg)) TypeBounds .empty else arg
197199 def apply (tp : Type ) = mapOver {
198200 tp match {
199- case tp : RefinedType if param occursIn tp.refinedInfo => tp.parent
201+ case tp @ AppliedType (tycon, args) =>
202+ tp.derivedAppliedType(tycon, args.mapConserve(avoidInArg))
203+ case tp : RefinedType if param occursIn tp.refinedInfo =>
204+ tp.parent
200205 case tp : WildcardType =>
201206 val bounds = tp.optBounds.orElse(TypeBounds .empty).bounds
202207 // Try to instantiate the wildcard to a type that is known to conform to it.
@@ -306,7 +311,12 @@ trait ConstraintHandling {
306311 /** The current bounds of type parameter `param` */
307312 final def bounds (param : TypeParamRef ): TypeBounds = {
308313 val e = constraint.entry(param)
309- if (e.exists) e.bounds else param.binder.paramInfos(param.paramNum)
314+ if (e.exists) e.bounds
315+ else {
316+ val pinfos = param.binder.paramInfos
317+ if (pinfos != null ) pinfos(param.paramNum) // pinfos == null happens in pos/i536.scala
318+ else TypeBounds .empty
319+ }
310320 }
311321
312322 /** Add type lambda `tl`, possibly with type variables `tvars`, to current constraint
@@ -318,7 +328,7 @@ trait ConstraintHandling {
318328 checkPropagated(i " initialized $tl" ) {
319329 constraint = constraint.add(tl, tvars)
320330 tl.paramNames.indices.forall { i =>
321- val param = TypeParamRef (tl, i)
331+ val param = tl.paramRefs( i)
322332 val bounds = constraint.nonParamBounds(param)
323333 val lower = constraint.lower(param)
324334 val upper = constraint.upper(param)
@@ -376,7 +386,12 @@ trait ConstraintHandling {
376386 else tp
377387
378388 def addParamBound (bound : TypeParamRef ) =
379- if (fromBelow) addLess(bound, param) else addLess(param, bound)
389+ constraint.entry(param) match {
390+ case _ : TypeBounds =>
391+ if (fromBelow) addLess(bound, param) else addLess(param, bound)
392+ case tp =>
393+ if (fromBelow) isSubType(bound, tp) else isSubType(tp, bound)
394+ }
380395
381396 /** Drop all constrained parameters that occur at the toplevel in `bound` and
382397 * handle them by `addLess` calls.
0 commit comments