Skip to content

Commit 97bbc24

Browse files
committed
Use default self type more often
We now also use cap as the default for the self type's capture set if a base class has an explicit self type, but that type's capture set is universal. This requires fewer self type annotations.
1 parent c09154a commit 97bbc24

File tree

4 files changed

+6
-9
lines changed

4 files changed

+6
-9
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,9 +528,11 @@ extension (cls: ClassSymbol)
528528
// and err on the side of impure.
529529
&& selfType.exists && selfType.captureSet.isAlwaysEmpty
530530

531-
def baseClassHasExplicitSelfType(using Context): Boolean =
531+
def baseClassHasExplicitNonUniversalSelfType(using Context): Boolean =
532532
cls.baseClasses.exists: bc =>
533-
bc.is(CaptureChecked) && bc.givenSelfType.exists
533+
bc.is(CaptureChecked)
534+
&& bc.givenSelfType.exists
535+
&& !bc.givenSelfType.captureSet.isUniversal
534536

535537
def matchesExplicitRefsInBaseClass(refs: CaptureSet)(using Context): Boolean =
536538
cls.baseClasses.tail.exists: bc =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
572572
else if cls.isPureClass then
573573
// is cls is known to be pure, nothing needs to be added to self type
574574
selfInfo
575-
else if !cls.isEffectivelySealed && !cls.baseClassHasExplicitSelfType then
575+
else if !cls.isEffectivelySealed && !cls.baseClassHasExplicitNonUniversalSelfType then
576576
// assume {cap} for completely unconstrained self types of publicly extensible classes
577577
CapturingType(cinfo.selfType, CaptureSet.universal)
578578
else

scala2-library-cc/src/scala/collection/IndexedSeqView.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@ package collection
1616
import scala.annotation.nowarn
1717
import language.experimental.captureChecking
1818

19-
trait IndexedSeqViewOps[+A, +CC[_], +C] extends Any with SeqViewOps[A, CC, C] {
20-
self: IndexedSeqViewOps[A, CC, C]^ =>
21-
}
19+
trait IndexedSeqViewOps[+A, +CC[_], +C] extends Any with SeqViewOps[A, CC, C]
2220

2321
/** View defined in terms of indexing a range */
2422
trait IndexedSeqView[+A] extends IndexedSeqViewOps[A, View, View[A]] with SeqView[A] {
25-
self: IndexedSeqView[A]^ =>
2623

2724
override def view: IndexedSeqView[A]^{this} = this
2825

scala2-library-cc/src/scala/collection/SeqView.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import scala.annotation.unchecked.uncheckedCaptures
2525
* mapping a SeqView with an impure function gives an impure view).
2626
*/
2727
trait SeqViewOps[+A, +CC[_], +C] extends Any with IterableOps[A, CC, C] {
28-
self: SeqViewOps[A, CC, C]^ =>
2928

3029
def length: Int
3130
def apply(x: Int): A
@@ -75,7 +74,6 @@ trait SeqViewOps[+A, +CC[_], +C] extends Any with IterableOps[A, CC, C] {
7574
}
7675

7776
trait SeqView[+A] extends SeqViewOps[A, View, View[A]] with View[A] {
78-
self: SeqView[A]^ =>
7977

8078
override def view: SeqView[A]^{this} = this
8179

0 commit comments

Comments
 (0)