@@ -914,12 +914,10 @@ 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+ val overridingRefinement =
918+ tp.isPrecise || pdenot.symbol.is(Tracked )
919+ if overridingRefinement then
920+ pdenot.asSingleDenotation.derivedSingleDenotation(pdenot.symbol, rinfo)
923921 else
924922 val isRefinedMethod = rinfo.isInstanceOf [MethodOrPoly ]
925923 val joint = CCState .withCollapsedFresh:
@@ -3259,6 +3257,12 @@ object Types extends TypeUtils {
32593257 else assert(refinedInfo.isInstanceOf [TypeType ], this )
32603258 assert(! refinedName.is(NameKinds .ExpandedName ), this )
32613259
3260+ /** If true we know that refinedInfo is always more precise than the info for
3261+ * field `refinedName` in parent, so no type intersection needs to be computed
3262+ * for the type of this field.
3263+ */
3264+ def isPrecise : Boolean = false
3265+
32623266 override def underlying (using Context ): Type = parent
32633267
32643268 private def badInst =
@@ -3270,6 +3274,7 @@ object Types extends TypeUtils {
32703274 (parent : Type = this .parent, refinedName : Name = this .refinedName, refinedInfo : Type = this .refinedInfo)
32713275 (using Context ): Type =
32723276 if ((parent eq this .parent) && (refinedName eq this .refinedName) && (refinedInfo eq this .refinedInfo)) this
3277+ else if isPrecise then RefinedType .precise(parent, refinedName, refinedInfo)
32733278 else RefinedType (parent, refinedName, refinedInfo)
32743279
32753280 /** Add this refinement to `parent`, provided `refinedName` is a member of `parent`. */
@@ -3302,6 +3307,10 @@ object Types extends TypeUtils {
33023307 class CachedRefinedType (parent : Type , refinedName : Name , refinedInfo : Type )
33033308 extends RefinedType (parent, refinedName, refinedInfo)
33043309
3310+ class PreciseRefinedType (parent : Type , refinedName : Name , refinedInfo : Type )
3311+ extends RefinedType (parent, refinedName, refinedInfo):
3312+ override def isPrecise = true
3313+
33053314 object RefinedType {
33063315 @ tailrec def make (parent : Type , names : List [Name ], infos : List [Type ])(using Context ): Type =
33073316 if (names.isEmpty) parent
@@ -3311,6 +3320,10 @@ object Types extends TypeUtils {
33113320 assert(! ctx.erasedTypes)
33123321 unique(new CachedRefinedType (parent, name, info)).checkInst
33133322 }
3323+
3324+ def precise (parent : Type , name : Name , info : Type )(using Context ): RefinedType =
3325+ assert(! ctx.erasedTypes)
3326+ unique(new PreciseRefinedType (parent, name, info)).checkInst
33143327 }
33153328
33163329 /** A recursive type. Instances should be constructed via the companion object.
0 commit comments