Skip to content

Commit

Permalink
Use default self type more often
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
odersky committed Aug 12, 2024
1 parent c09154a commit 429703a
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 7 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/cc/Setup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
else if cls.isPureClass then
// is cls is known to be pure, nothing needs to be added to self type
selfInfo
else if !cls.isEffectivelySealed && !cls.baseClassHasExplicitSelfType then
else if !cls.isEffectivelySealed && !cls.baseClassHasExplicitNonUniversalSelfType then
// assume {cap} for completely unconstrained self types of publicly extensible classes
CapturingType(cinfo.selfType, CaptureSet.universal)
else
Expand Down
5 changes: 1 addition & 4 deletions scala2-library-cc/src/scala/collection/IndexedSeqView.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@ package collection
import scala.annotation.nowarn
import language.experimental.captureChecking

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

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

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

Expand Down
2 changes: 0 additions & 2 deletions scala2-library-cc/src/scala/collection/SeqView.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import scala.annotation.unchecked.uncheckedCaptures
* mapping a SeqView with an impure function gives an impure view).
*/
trait SeqViewOps[+A, +CC[_], +C] extends Any with IterableOps[A, CC, C] {
self: SeqViewOps[A, CC, C]^ =>

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

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

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

Expand Down

0 comments on commit 429703a

Please sign in to comment.