Skip to content

Commit 82b0d5b

Browse files
committed
Change rules for tracked refinments and tighten intersections
Intersections used the heuristic mightAccountFor instead of the precise accountsFor. Thsi can lead to a loss of precision and (if unchecked afterwards) also soundness. The fix caused some tests to fail, which involved tracked parameters. We now deal with tracked parameters in the same way as parameters that carry a @refineOverride annotation.
1 parent c1f44c4 commit 82b0d5b

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

compiler/src/dotty/tools/dotc/cc/CaptureSet.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ object CaptureSet:
935935
end Intersection
936936

937937
def elemIntersection(cs1: CaptureSet, cs2: CaptureSet)(using Context): Refs =
938-
cs1.elems.filter(cs2.mightAccountFor) ++ cs2.elems.filter(cs1.mightAccountFor)
938+
cs1.elems.filter(cs2.accountsFor) ++ cs2.elems.filter(cs1.accountsFor)
939939

940940
/** A capture set variable used to record the references hidden by a Fresh instance,
941941
* The elems and deps members are repurposed as follows:

compiler/src/dotty/tools/dotc/core/Types.scala

+8-4
Original file line numberDiff line numberDiff line change
@@ -860,10 +860,14 @@ object Types extends TypeUtils {
860860
pinfo recoverable_& rinfo
861861
pdenot.asSingleDenotation.derivedSingleDenotation(pdenot.symbol, jointInfo)
862862
}
863-
else rinfo match
864-
case AnnotatedType(rinfo1, ann) if ann.symbol == defn.RefineOverrideAnnot =>
865-
pdenot.asSingleDenotation.derivedSingleDenotation(pdenot.symbol, rinfo1)
866-
case _ =>
863+
else
864+
val overridingRefinement = rinfo match
865+
case AnnotatedType(rinfo1, ann) if ann.symbol == defn.RefineOverrideAnnot => rinfo1
866+
case _ if pdenot.symbol.is(Tracked) => rinfo
867+
case _ => NoType
868+
if overridingRefinement.exists then
869+
pdenot.asSingleDenotation.derivedSingleDenotation(pdenot.symbol, overridingRefinement)
870+
else
867871
val isRefinedMethod = rinfo.isInstanceOf[MethodOrPoly]
868872
val joint = pdenot.meet(
869873
new JointRefDenotation(NoSymbol, rinfo, Period.allInRun(ctx.runId), pre, isRefinedMethod),

0 commit comments

Comments
 (0)