@@ -914,12 +914,8 @@ object Types extends TypeUtils {
914914 pdenot.asSingleDenotation.derivedSingleDenotation(pdenot.symbol, jointInfo)
915915 }
916916 else
917- val overridingRefinement = rinfo match
918- case AnnotatedType (rinfo1, ann) if ann.symbol == defn.RefineOverrideAnnot => rinfo1
919- case _ if pdenot.symbol.is(Tracked ) => rinfo
920- case _ => NoType
921- if overridingRefinement.exists then
922- pdenot.asSingleDenotation.derivedSingleDenotation(pdenot.symbol, overridingRefinement)
917+ if tp.isPrecise then
918+ pdenot.asSingleDenotation.derivedSingleDenotation(pdenot.symbol, rinfo)
923919 else
924920 val isRefinedMethod = rinfo.isInstanceOf [MethodOrPoly ]
925921 val joint = CCState .withCollapsedFresh:
@@ -3259,6 +3255,12 @@ object Types extends TypeUtils {
32593255 else assert(refinedInfo.isInstanceOf [TypeType ], this )
32603256 assert(! refinedName.is(NameKinds .ExpandedName ), this )
32613257
3258+ /** If true we know that refinedInfo is always more precise than the info for
3259+ * field `refinedName` in parent, so no type intersection needs to be computed
3260+ * for the type of this field.
3261+ */
3262+ def isPrecise : Boolean = false
3263+
32623264 override def underlying (using Context ): Type = parent
32633265
32643266 private def badInst =
@@ -3270,6 +3272,7 @@ object Types extends TypeUtils {
32703272 (parent : Type = this .parent, refinedName : Name = this .refinedName, refinedInfo : Type = this .refinedInfo)
32713273 (using Context ): Type =
32723274 if ((parent eq this .parent) && (refinedName eq this .refinedName) && (refinedInfo eq this .refinedInfo)) this
3275+ else if isPrecise then RefinedType .precise(parent, refinedName, refinedInfo)
32733276 else RefinedType (parent, refinedName, refinedInfo)
32743277
32753278 /** Add this refinement to `parent`, provided `refinedName` is a member of `parent`. */
@@ -3302,6 +3305,10 @@ object Types extends TypeUtils {
33023305 class CachedRefinedType (parent : Type , refinedName : Name , refinedInfo : Type )
33033306 extends RefinedType (parent, refinedName, refinedInfo)
33043307
3308+ class PreciseRefinedType (parent : Type , refinedName : Name , refinedInfo : Type )
3309+ extends RefinedType (parent, refinedName, refinedInfo):
3310+ override def isPrecise = true
3311+
33053312 object RefinedType {
33063313 @ tailrec def make (parent : Type , names : List [Name ], infos : List [Type ])(using Context ): Type =
33073314 if (names.isEmpty) parent
@@ -3311,6 +3318,10 @@ object Types extends TypeUtils {
33113318 assert(! ctx.erasedTypes)
33123319 unique(new CachedRefinedType (parent, name, info)).checkInst
33133320 }
3321+
3322+ def precise (parent : Type , name : Name , info : Type )(using Context ): RefinedType =
3323+ assert(! ctx.erasedTypes)
3324+ unique(new PreciseRefinedType (parent, name, info)).checkInst
33143325 }
33153326
33163327 /** A recursive type. Instances should be constructed via the companion object.
0 commit comments