Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use default self type more often #21373

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/cc/CaptureOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,11 @@ extension (cls: ClassSymbol)
// and err on the side of impure.
&& selfType.exists && selfType.captureSet.isAlwaysEmpty

def baseClassHasExplicitSelfType(using Context): Boolean =
def baseClassHasExplicitNonUniversalSelfType(using Context): Boolean =
cls.baseClasses.exists: bc =>
bc.is(CaptureChecked) && bc.givenSelfType.exists
bc.is(CaptureChecked)
&& bc.givenSelfType.exists
&& !bc.givenSelfType.captureSet.isUniversal

def matchesExplicitRefsInBaseClass(refs: CaptureSet)(using Context): Boolean =
cls.baseClasses.tail.exists: bc =>
Expand Down
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
Loading