@@ -95,12 +95,13 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
9595 def apply (x : Boolean , tp : Type ): Boolean =
9696 if x then true
9797 else if tp.derivesFromCapability && variance >= 0 then true
98- else tp match
98+ else tp.dealiasKeepAnnots match
9999 case AnnotatedType (_, ann) if ann.symbol.isRetains && variance >= 0 => true
100100 case t : TypeRef if t.symbol.isAbstractOrParamType && ! seen.contains(t.symbol) =>
101101 seen += t.symbol
102102 apply(x, t.info.bounds.hi)
103- case _ => foldOver(x, tp)
103+ case tp1 =>
104+ foldOver(x, tp1)
104105 def apply (tp : Type ): Boolean = apply(false , tp)
105106
106107 if symd.symbol.isRefiningParamAccessor
@@ -270,6 +271,8 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
270271 def mapInferred (refine : Boolean ): TypeMap = new TypeMap with SetupTypeMap :
271272 override def toString = " map inferred"
272273
274+ var refiningNames : Set [Name ] = Set ()
275+
273276 /** Refine a possibly applied class type C where the class has tracked parameters
274277 * x_1: T_1, ..., x_n: T_n to C { val x_1: T_1^{CV_1}, ..., val x_n: T_n^{CV_n} }
275278 * where CV_1, ..., CV_n are fresh capture set variables.
@@ -282,7 +285,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
282285 cls.paramGetters.foldLeft(tp) { (core, getter) =>
283286 if atPhase(thisPhase.next)(getter.hasTrackedParts)
284287 && getter.isRefiningParamAccessor
285- && ! getter.is( Tracked )
288+ && ! refiningNames.contains(getter.name) // Don't add a refinement if we have already an explicit one for the same name
286289 then
287290 val getterType =
288291 mapInferred(refine = false )(tp.memberInfo(getter)).strippedDealias
@@ -306,6 +309,11 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
306309 tp.derivedLambdaType(
307310 paramInfos = tp.paramInfos.mapConserve(_.dropAllRetains.bounds),
308311 resType = this (tp.resType))
312+ case tp @ RefinedType (parent, rname, rinfo) =>
313+ val saved = refiningNames
314+ refiningNames += rname
315+ val parent1 = try this (parent) finally refiningNames = saved
316+ tp.derivedRefinedType(parent1, rname, this (rinfo))
309317 case _ =>
310318 mapFollowingAliases(tp)
311319 addVar(
0 commit comments