Skip to content

Commit 93f1169

Browse files
committed
More targeted handling of overriding checks against CapSet^
1 parent be6968e commit 93f1169

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,9 +1585,18 @@ class CheckCaptures extends Recheck, SymTransformer:
15851585
memberTp match
15861586
case TypeAlias(_) =>
15871587
otherTp match
1588-
case otherTp: RealTypeBounds
1589-
if otherTp.hi.isBoxedCapturing || otherTp.lo.isBoxedCapturing =>
1590-
Some((memberTp, otherTp.unboxed))
1588+
case otherTp: RealTypeBounds =>
1589+
if otherTp.hi.isBoxedCapturing || otherTp.lo.isBoxedCapturing then
1590+
Some((memberTp, otherTp.unboxed))
1591+
else otherTp.hi match
1592+
case hi @ CapturingType(parent: TypeRef, refs)
1593+
if parent.symbol == defn.Caps_CapSet && refs.isUniversal =>
1594+
Some((
1595+
memberTp,
1596+
otherTp.derivedTypeBounds(
1597+
otherTp.lo,
1598+
hi.derivedCapturingType(parent, root.Fresh().singletonCaptureSet))))
1599+
case _ => None
15911600
case _ => None
15921601
case _ => None
15931602
else memberTp match

compiler/src/dotty/tools/dotc/transform/OverridingPairs.scala

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,14 @@ object OverridingPairs:
214214
if member.isType then // intersection of bounds to refined types must be nonempty
215215
memberTp.bounds.hi.hasSameKindAs(otherTp.bounds.hi)
216216
&& (
217-
CCState.withCapAsRoot: // If upper bound is CapSet^ any capture set of lower bound is OK
218-
(memberTp frozen_<:< otherTp)
219-
|| !member.owner.derivesFrom(other.owner)
220-
&& {
221-
// if member and other come from independent classes or traits, their
222-
// bounds must have non-empty-intersection
223-
val jointBounds = (memberTp.bounds & otherTp.bounds).bounds
224-
jointBounds.lo frozen_<:< jointBounds.hi
225-
}
217+
(memberTp frozen_<:< otherTp)
218+
|| !member.owner.derivesFrom(other.owner)
219+
&& {
220+
// if member and other come from independent classes or traits, their
221+
// bounds must have non-empty-intersection
222+
val jointBounds = (memberTp.bounds & otherTp.bounds).bounds
223+
jointBounds.lo frozen_<:< jointBounds.hi
224+
}
226225
)
227226
else
228227
member.name.is(DefaultGetterName) // default getters are not checked for compatibility

0 commit comments

Comments
 (0)