@@ -247,13 +247,7 @@ final class ProperGadtConstraint private(
247247 override protected def isSame (tp1 : Type , tp2 : Type )(using Context ): Boolean = TypeComparer .isSameType(tp1, tp2)
248248
249249 override def nonParamBounds (param : TypeParamRef )(using Context ): TypeBounds =
250- val externalizeMap = new TypeMap {
251- def apply (tp : Type ): Type = tp match {
252- case tpr : TypeParamRef => externalize(tpr)
253- case tp => mapOver(tp)
254- }
255- }
256- externalizeMap(constraint.nonParamBounds(param)).bounds
250+ externalize(constraint.nonParamBounds(param)).bounds
257251
258252 override def fullLowerBound (param : TypeParamRef )(using Context ): Type =
259253 constraint.minLower(param).foldLeft(nonParamBounds(param).lo) {
@@ -270,27 +264,27 @@ final class ProperGadtConstraint private(
270264
271265 // ---- Private ----------------------------------------------------------
272266
273- private def externalize (param : TypeParamRef )(using Context ): Type =
274- reverseMapping(param) match {
267+ private def externalize (tp : Type , theMap : TypeMap | Null = null )(using Context ): Type = tp match
268+ case param : TypeParamRef => reverseMapping(param) match
275269 case sym : Symbol => sym.typeRef
276- case null => param
277- }
270+ case null => param
271+ case tp => (if theMap == null then ExternalizeMap () else theMap).mapOver(tp)
272+
273+ private class ExternalizeMap (using Context ) extends TypeMap :
274+ def apply (tp : Type ): Type = externalize(tp, this )(using mapCtx)
278275
279276 private def tvarOrError (sym : Symbol )(using Context ): TypeVar =
280277 mapping(sym).ensuring(_ != null , i " not a constrainable symbol: $sym" ).uncheckedNN
281278
282- private def containsNoInternalTypes (
283- tp : Type ,
284- acc : TypeAccumulator [Boolean ] | Null = null
285- )(using Context ): Boolean = tp match {
279+ private def containsNoInternalTypes (tp : Type , theAcc : TypeAccumulator [Boolean ] | Null = null )(using Context ): Boolean = tp match {
286280 case tpr : TypeParamRef => ! reverseMapping.contains(tpr)
287281 case tv : TypeVar => ! reverseMapping.contains(tv.origin)
288282 case tp =>
289- (if (acc != null ) acc else new ContainsNoInternalTypesAccumulator ()).foldOver(true , tp)
283+ (if (theAcc != null ) theAcc else new ContainsNoInternalTypesAccumulator ()).foldOver(true , tp)
290284 }
291285
292286 private class ContainsNoInternalTypesAccumulator (using Context ) extends TypeAccumulator [Boolean ] {
293- override def apply (x : Boolean , tp : Type ): Boolean = x && containsNoInternalTypes(tp)
287+ override def apply (x : Boolean , tp : Type ): Boolean = x && containsNoInternalTypes(tp, this )
294288 }
295289
296290 // ---- Debug ------------------------------------------------------------
0 commit comments