Skip to content

Commit bd7d4da

Browse files
committed
Rename This types in library and tests
1 parent dad1dda commit bd7d4da

29 files changed

+214
-214
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1328,7 +1328,7 @@ object SymDenotations {
13281328
/** The type parameters of a class symbol, Nil for all other symbols */
13291329
def typeParams(implicit ctx: Context): List[TypeSymbol] = Nil
13301330

1331-
/** The type This(cls), where cls is this class, NoPrefix for all other symbols */
1331+
/** The type ThisType(cls), where cls is this class, NoPrefix for all other symbols */
13321332
def thisType(implicit ctx: Context): Type = NoPrefix
13331333

13341334
def typeRef(implicit ctx: Context): TypeRef =

compiler/src/dotty/tools/dotc/util/WeakHashSet.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ final class WeakHashSet[A <: AnyRef](initialCapacity: Int, loadFactor: Double) e
2323

2424
def this() = this(initialCapacity = WeakHashSet.defaultInitialCapacity, loadFactor = WeakHashSet.defaultLoadFactor)
2525

26-
type This = WeakHashSet[A]
26+
type ThisType = WeakHashSet[A]
2727

2828
/**
2929
* queue of Entries that hold elements scheduled for GC
@@ -252,7 +252,7 @@ final class WeakHashSet[A <: AnyRef](initialCapacity: Int, loadFactor: Double) e
252252
}
253253

254254
// true if this set is empty
255-
override def empty: This = new WeakHashSet[A](initialCapacity, loadFactor)
255+
override def empty: ThisType = new WeakHashSet[A](initialCapacity, loadFactor)
256256

257257
// the number of elements in this set
258258
override def size: Int = {

compiler/test/dotty/tools/dotc/parsing/parsePackage.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ object parsePackage extends ParserTest {
1919
tree match {
2020
case Ident(name) =>
2121
Ident(name)
22-
case This(name) =>
23-
This(name)
22+
case ThisRef(name) =>
23+
ThisRef(name)
2424
case TypedSplice(t) =>
2525
TypedSplice(t)
2626
case SymbolLit(str) =>

library/src-bootstrapped/scala/tasty/reflect/TreeUtils.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ trait TreeUtils
2121
x
2222
case Select(qualifier, _) =>
2323
foldTree(x, qualifier)
24-
case This(qual) =>
24+
case ThisRef(qual) =>
2525
x
2626
case Super(qual, _) =>
2727
foldTree(x, qual)
@@ -163,7 +163,7 @@ trait TreeUtils
163163
tree
164164
case Select(qualifier, name) =>
165165
Select.copy(tree)(transformTerm(qualifier), name)
166-
case This(qual) =>
166+
case ThisRef(qual) =>
167167
tree
168168
case Super(qual, mix) =>
169169
Super.copy(tree)(transformTerm(qual), mix)

library/src/scala/Tuple.scala

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ sealed trait Tuple extends Any {
2020
/** Return a new tuple by prepending the element to `this` tuple.
2121
* This opteration is O(this.size)
2222
*/
23-
inline def *: [H, This >: this.type <: Tuple] (x: H): H *: This =
24-
DynamicTuple.dynamicCons[H, This](x, this)
23+
inline def *: [H, Self >: this.type <: Tuple] (x: H): H *: Self =
24+
DynamicTuple.dynamicCons[H, Self](x, this)
2525

2626
/** Return a new tuple by concatenating `this` tuple with `that` tuple.
2727
* This opteration is O(this.size + that.size)
2828
*/
29-
inline def ++ [This >: this.type <: Tuple](that: Tuple): Concat[This, that.type] =
30-
DynamicTuple.dynamicConcat[This, that.type](this, that)
29+
inline def ++ [Self >: this.type <: Tuple](that: Tuple): Concat[Self, that.type] =
30+
DynamicTuple.dynamicConcat[Self, that.type](this, that)
3131

3232
/** Return the size (or arity) of the tuple */
33-
inline def size[This >: this.type <: Tuple]: Size[This] =
33+
inline def size[Self >: this.type <: Tuple]: Size[Self] =
3434
DynamicTuple.dynamicSize(this)
3535

3636
/** Given two tuples, `(a1, ..., an)` and `(a1, ..., an)`, returns a tuple
@@ -40,7 +40,7 @@ sealed trait Tuple extends Any {
4040
* tuple types has a `Unit` tail. Otherwise the result type is
4141
* `(A1, B1) *: ... *: (Ai, Bi) *: Tuple`
4242
*/
43-
inline def zip[This >: this.type <: Tuple, T2 <: Tuple](t2: T2): Zip[This, T2] =
43+
inline def zip[Self >: this.type <: Tuple, T2 <: Tuple](t2: T2): Zip[Self, T2] =
4444
DynamicTuple.dynamicZip(this, t2)
4545

4646
/** Called on a tuple `(a1, ..., an)`, returns a new tuple `(f(a1), ..., f(an))`.
@@ -151,18 +151,18 @@ sealed trait NonEmptyTuple extends Tuple {
151151
/** Get the i-th element of this tuple.
152152
* Equivalent to productElement but with a precise return type.
153153
*/
154-
inline def apply[This >: this.type <: NonEmptyTuple](n: Int): Elem[This, n.type] =
155-
DynamicTuple.dynamicApply[This, n.type](this, n)
154+
inline def apply[Self >: this.type <: NonEmptyTuple](n: Int): Elem[Self, n.type] =
155+
DynamicTuple.dynamicApply[Self, n.type](this, n)
156156

157157
/** Get the head of this tuple */
158-
inline def head[This >: this.type <: NonEmptyTuple]: Head[This] =
159-
DynamicTuple.dynamicApply[This, 0](this, 0)
158+
inline def head[Self >: this.type <: NonEmptyTuple]: Head[Self] =
159+
DynamicTuple.dynamicApply[Self, 0](this, 0)
160160

161161
/** Get the tail of this tuple.
162162
* This opteration is O(this.size)
163163
*/
164-
inline def tail[This >: this.type <: NonEmptyTuple]: Tail[This] =
165-
DynamicTuple.dynamicTail[This](this)
164+
inline def tail[Self >: this.type <: NonEmptyTuple]: Tail[Self] =
165+
DynamicTuple.dynamicTail[Self](this)
166166

167167
}
168168

library/src/scala/runtime/DynamicTuple.scala

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ object DynamicTuple {
192192
arr
193193
}
194194

195-
def dynamicCons[H, This <: Tuple](x: H, self: Tuple): H *: This = {
196-
type Result = H *: This
195+
def dynamicCons[H, Self <: Tuple](x: H, self: Tuple): H *: Self = {
196+
type Result = H *: Self
197197
(self: Any) match {
198198
case () =>
199199
Tuple1(x).asInstanceOf[Result]
@@ -210,8 +210,8 @@ object DynamicTuple {
210210
}
211211
}
212212

213-
def dynamicConcat[This <: Tuple, That <: Tuple](self: This, that: That): Concat[This, That] = {
214-
type Result = Concat[This, That]
213+
def dynamicConcat[Self <: Tuple, That <: Tuple](self: Self, that: That): Concat[Self, That] = {
214+
type Result = Concat[Self, That]
215215
(this: Any) match {
216216
case self: Unit => return self.asInstanceOf[Result]
217217
case _ =>
@@ -223,13 +223,13 @@ object DynamicTuple {
223223
dynamicFromArray[Result](dynamicToArray(self) ++ dynamicToArray(that))
224224
}
225225

226-
def dynamicSize[This <: Tuple](self: This): Size[This] = (self: Any) match {
227-
case self: Unit => 0.asInstanceOf[Size[This]]
228-
case self: Product => self.productArity.asInstanceOf[Size[This]]
226+
def dynamicSize[Self <: Tuple](self: Self): Size[Self] = (self: Any) match {
227+
case self: Unit => 0.asInstanceOf[Size[Self]]
228+
case self: Product => self.productArity.asInstanceOf[Size[Self]]
229229
}
230230

231-
def dynamicTail[This <: NonEmptyTuple] (self: This): Tail[This] = {
232-
type Result = Tail[This]
231+
def dynamicTail[Self <: NonEmptyTuple] (self: Self): Tail[Self] = {
232+
type Result = Tail[Self]
233233
val res = (self: Any) match {
234234
case self: Tuple1[_] => ()
235235
case self: Tuple2[_, _] => Tuple1(self._2)
@@ -240,26 +240,26 @@ object DynamicTuple {
240240
res.asInstanceOf[Result]
241241
}
242242

243-
def dynamicApply[This <: NonEmptyTuple, N <: Int] (self: This, n: Int): Elem[This, N] = {
244-
type Result = Elem[This, N]
243+
def dynamicApply[Self <: NonEmptyTuple, N <: Int] (self: Self, n: Int): Elem[Self, N] = {
244+
type Result = Elem[Self, N]
245245
val res = (self: Any) match {
246246
case self: Unit => throw new IndexOutOfBoundsException(n.toString)
247247
case self: Product => self.productElement(n)
248248
}
249249
res.asInstanceOf[Result]
250250
}
251251

252-
def dynamicZip[This <: Tuple, T2 <: Tuple](t1: This, t2: T2): Zip[This, T2] = {
253-
if (t1.size == 0 || t2.size == 0) ().asInstanceOf[Zip[This, T2]]
252+
def dynamicZip[Self <: Tuple, T2 <: Tuple](t1: Self, t2: T2): Zip[Self, T2] = {
253+
if (t1.size == 0 || t2.size == 0) ().asInstanceOf[Zip[Self, T2]]
254254
else Tuple.fromArray(
255255
t1.asInstanceOf[Product].productIterator.zip(
256256
t2.asInstanceOf[Product].productIterator).toArray // TODO use toIArray of Object to avoid double/triple array copy
257-
).asInstanceOf[Zip[This, T2]]
257+
).asInstanceOf[Zip[Self, T2]]
258258
}
259259

260-
def dynamicMap[This <: Tuple, F[_]](self: This, f: [t] => t => F[t]): Map[This, F] =
260+
def dynamicMap[Self <: Tuple, F[_]](self: Self, f: [t] => t => F[t]): Map[Self, F] =
261261
Tuple.fromArray(self.asInstanceOf[Product].productIterator.map(f(_)).toArray) // TODO use toIArray of Object to avoid double/triple array copy
262-
.asInstanceOf[Map[This, F]]
262+
.asInstanceOf[Map[Self, F]]
263263

264264
def consIterator(head: Any, tail: Tuple): Iterator[Any] =
265265
Iterator.single(head) ++ tail.asInstanceOf[Product].productIterator

tests/disabled/partest/run/existentials-in-compiler.check

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ abstract trait Bippy[A <: AnyRef, B] extends AnyRef
44
abstract trait BippyBud[A <: AnyRef, B, C <: List[A]] extends AnyRef
55
extest.BippyBud[A,B,C] forSome { A <: AnyRef; B; C <: List[A] }
66

7-
abstract trait BippyLike[A <: AnyRef, B <: List[A], This <: extest.BippyLike[A,B,This] with extest.Bippy[A,B]] extends AnyRef
8-
extest.BippyLike[A,B,This] forSome { A <: AnyRef; B <: List[A]; This <: extest.BippyLike[A,B,This] with extest.Bippy[A,B] }
7+
abstract trait BippyLike[A <: AnyRef, B <: List[A], Self <: extest.BippyLike[A,B,Self] with extest.Bippy[A,B]] extends AnyRef
8+
extest.BippyLike[A,B,Self] forSome { A <: AnyRef; B <: List[A]; Self <: extest.BippyLike[A,B,Self] with extest.Bippy[A,B] }
99

1010
abstract trait Contra[-A >: AnyRef, -B] extends AnyRef
1111
extest.Contra[AnyRef, _]
@@ -151,6 +151,6 @@ abstract trait Cov49[-A >: Null, -B] extends AnyRef
151151
abstract trait Covariant[+A <: AnyRef, +B] extends AnyRef
152152
extest.Covariant[AnyRef,Any]
153153

154-
abstract trait CovariantLike[+A <: AnyRef, +B <: List[A], +This <: extest.CovariantLike[A,B,This] with extest.Covariant[A,B]] extends AnyRef
155-
extest.CovariantLike[A,B,This] forSome { +A <: AnyRef; +B <: List[A]; +This <: extest.CovariantLike[A,B,This] with extest.Covariant[A,B] }
154+
abstract trait CovariantLike[+A <: AnyRef, +B <: List[A], +Self <: extest.CovariantLike[A,B,Self] with extest.Covariant[A,B]] extends AnyRef
155+
extest.CovariantLike[A,B,Self] forSome { +A <: AnyRef; +B <: List[A]; +Self <: extest.CovariantLike[A,B,Self] with extest.Covariant[A,B] }
156156

tests/disabled/partest/run/existentials-in-compiler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ object Test extends CompilerTest {
1313
override def code = """
1414
package extest {
1515
trait Bippy[A <: AnyRef, B] { } // wildcards
16-
trait BippyLike[A <: AnyRef, B <: List[A], This <: BippyLike[A, B, This] with Bippy[A, B]] // no wildcards
16+
trait BippyLike[A <: AnyRef, B <: List[A], Self <: BippyLike[A, B, Self] with Bippy[A, B]] // no wildcards
1717
trait BippyBud[A <: AnyRef, B, C <: List[A]]
1818
1919
trait Cov01[+A <: AnyRef, +B] { }
@@ -67,7 +67,7 @@ package extest {
6767
trait Cov49[-A >: Null, -B] { }
6868
6969
trait Covariant[+A <: AnyRef, +B] { }
70-
trait CovariantLike[+A <: AnyRef, +B <: List[A], +This <: CovariantLike[A, B, This] with Covariant[A, B]]
70+
trait CovariantLike[+A <: AnyRef, +B <: List[A], +Self <: CovariantLike[A, B, Self] with Covariant[A, B]]
7171
7272
trait Contra[-A >: AnyRef, -B] { }
7373
trait ContraLike[-A >: AnyRef, -B >: List[A]]

tests/invalid/pos/IterableSelfRec.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,27 @@ package immutable
55
import annotation.unchecked.uncheckedVariance
66

77
trait Collection[T] { self =>
8-
type This <: Collection { type This <: self.This }
9-
def companion: CollectionCompanion[This]
8+
type ThisCollection <: Collection { type ThisCollection <: self.ThisCollection }
9+
def companion: CollectionCompanion[ThisCollection]
1010
}
1111

1212
trait Iterable[T] extends Collection[T] { self =>
13-
type This <: Iterable { type This <: self.This }
14-
override def companion: IterableCompanion[This] = Iterable.asInstanceOf
13+
type ThisCollection <: Iterable { type ThisCollection <: self.ThisCollection }
14+
override def companion: IterableCompanion[ThisCollection] = Iterable.asInstanceOf
1515

1616
def iterator: Iterator[T]
1717
}
1818

1919
trait Seq[T] extends Iterable[T] { self =>
20-
type This <: Seq { type This <: self.This }
21-
override def companion: IterableCompanion[This] = Seq.asInstanceOf
20+
type ThisCollection <: Seq { type ThisCollection <: self.ThisCollection }
21+
override def companion: IterableCompanion[ThisCollection] = Seq.asInstanceOf
2222

2323
def apply(x: Int): T
2424
}
2525

26-
abstract class CollectionCompanion[+CC[X] <: Collection[X] { type This <: CC }]
26+
abstract class CollectionCompanion[+CC[X] <: Collection[X] { type ThisCollection <: CC }]
2727

28-
abstract class IterableCompanion[+CC[X] <: Iterable[X] { type This <: CC }] extends CollectionCompanion[CC] {
28+
abstract class IterableCompanion[+CC[X] <: Iterable[X] { type ThisCollection <: CC }] extends CollectionCompanion[CC] {
2929
def fromIterator[T](it: Iterator[T]): CC[T]
3030
def map[T, U](xs: Iterable[T], f: T => U): CC[U] =
3131
fromIterator(xs.iterator.map(f))
@@ -37,7 +37,7 @@ abstract class IterableCompanion[+CC[X] <: Iterable[X] { type This <: CC }] exte
3737
implicit def transformOps[T](xs: CC[T] @uncheckedVariance): TransformOps[CC, T] = ??? // new TransformOps[CC, T](xs)
3838
}
3939

40-
class TransformOps[+CC[X] <: Iterable[X] { type This <: CC }, T] (val xs: CC[T]) extends AnyVal {
40+
class TransformOps[+CC[X] <: Iterable[X] { type ThisCollection <: CC }, T] (val xs: CC[T]) extends AnyVal {
4141
def companion[T](xs: CC[T] @uncheckedVariance): IterableCompanion[CC] = xs.companion
4242
def map[U](f: T => U): CC[U] = companion(xs).map(xs, f)
4343
def filter(p: T => Boolean): CC[T] = companion(xs).filter(xs, p)

tests/neg/typeclass-encoding2.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ object runtime1 {
66

77
trait TypeClass1[A] {
88
val common: TypeClassCommon1
9-
type This[X] = common.This[X]
9+
type ThisClass[X] = common.ThisClass[X]
1010
}
1111

1212
trait TypeClassCommon1 { self =>
13-
type This[X]
13+
type ThisClass[X]
1414
type Instance[X] <: TypeClass1[X]
15-
def inject[A](x: This[A]): Instance[A]// { val common: self.type }
15+
def inject[A](x: ThisClass[A]): Instance[A]// { val common: self.type }
1616
}
1717

1818
trait Extension1[From[_], To[X] <: TypeClass1[X]] extends TypeClassCommon1 {
19-
type This[X] = From[X]
19+
type ThisClass[X] = From[X]
2020
type Instance[X] = To[X]
2121
}
2222

2323
implicit def inject[A, From[_]](x: From[A])
24-
(implicit ev: Extension1[From, _]): ev.Instance[A] { type This[X] = From[X] } =
25-
ev.inject(x) // error: found: ev.To[A], required: ev.To[A]{This = From}
24+
(implicit ev: Extension1[From, _]): ev.Instance[A] { type ThisClass[X] = From[X] } =
25+
ev.inject(x) // error: found: ev.To[A], required: ev.To[A]{ThisClass = From}
2626
}

tests/pending/pos/depmet_implicit_oopsla_session.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
object Sessions {
2-
trait Session[This] {
2+
trait Session[Self] {
33
type Dual
4-
type HasDual[D] = Session[This]{type Dual=D}
5-
def run(p: This, dp: Dual): Unit
4+
type HasDual[D] = Session[Self]{type Dual=D}
5+
def run(p: Self, dp: Dual): Unit
66
}
77

88
implicit object StopSession extends Session[Stop] {

tests/pos-with-compiler/tasty/definitions.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ object definitions {
6868
case Ident(name: String, override val tpe: Type)
6969
case Select(prefix: Term, name: String, signature: Option[Signature])
7070
case Literal(value: Constant)
71-
case This(id: Option[Id])
71+
case Self(id: Option[Id])
7272
case New(tpt: TypeTree)
7373
case Throw(expr: Term)
7474
case NamedArg(name: String, arg: Term)
@@ -163,8 +163,8 @@ object definitions {
163163
}
164164
}
165165

166-
abstract class LambdaType[ParamInfo, This <: LambdaType[ParamInfo, This]](
167-
val companion: LambdaTypeCompanion[ParamInfo, This]
166+
abstract class LambdaType[ParamInfo, Self <: LambdaType[ParamInfo, Self]](
167+
val companion: LambdaTypeCompanion[ParamInfo, Self]
168168
) extends Type {
169169
private[Type] var _pinfos: List[ParamInfo]
170170
private[Type] var _restpe: Type
@@ -174,10 +174,10 @@ object definitions {
174174
def resultType: Type = _restpe
175175
}
176176

177-
abstract class LambdaTypeCompanion[ParamInfo, This <: LambdaType[ParamInfo, This]] {
178-
def apply(pnames: List[String], ptypes: List[ParamInfo], restpe: Type): This
177+
abstract class LambdaTypeCompanion[ParamInfo, Self <: LambdaType[ParamInfo, Self]] {
178+
def apply(pnames: List[String], ptypes: List[ParamInfo], restpe: Type): Self
179179

180-
def apply(pnames: List[String], ptypesExp: This => List[ParamInfo], restpeExp: This => Type): This = {
180+
def apply(pnames: List[String], ptypesExp: Self => List[ParamInfo], restpeExp: Self => Type): Self = {
181181
val lambda = apply(pnames, Nil, PlaceHolder)
182182
lambda._pinfos = ptypesExp(lambda)
183183
lambda._restpe = restpeExp(lambda)

tests/pos/extmethods-2.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package extMethods
22

33
trait That1[A]
4-
class T[A, This <: That1[A]](val x: Int) extends AnyVal {
5-
self: This =>
6-
final def loop(x: This, cnt: Int): Int = loop(x, cnt + 1)
4+
class T[A, Self <: That1[A]](val x: Int) extends AnyVal {
5+
self: Self =>
6+
final def loop(x: Self, cnt: Int): Int = loop(x, cnt + 1)
77
}

tests/pos/extmethods.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
trait That1[A]
2-
class T[A, This <: That1[A]](val x: Int) extends AnyVal {
3-
self: This =>
4-
final def loop(x: This, cnt: Int): Int = loop(x, cnt + 1)
2+
class T[A, Self <: That1[A]](val x: Int) extends AnyVal {
3+
self: Self =>
4+
final def loop(x: Self, cnt: Int): Int = loop(x, cnt + 1)
55
def const[B](): Boolean = return true
66
}
77

tests/pos/i1401.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ trait Subtractable[AS, +Repr <: Subtractable[AS, Repr]] {
44
def -(elem: AS): Repr
55
}
66

7-
trait BufferLike[BA, +This <: BufferLike[BA, This] with Buffer[BA]]
8-
extends Subtractable[BA, This]
9-
{ self : This =>
7+
trait BufferLike[BA, +Self <: BufferLike[BA, Self] with Buffer[BA]]
8+
extends Subtractable[BA, Self]
9+
{ self : Self =>
1010

1111
/* Without fix-#1401:
1212
*
13-
error: overriding method - in trait Subtractable of type (elem: A)This & i1401.Buffer[A];
14-
method - of type (elem: BA)This has incompatible type
15-
def -(elem: BA): This
13+
error: overriding method - in trait Subtractable of type (elem: A)Self & i1401.Buffer[A];
14+
method - of type (elem: BA)Self has incompatible type
15+
def -(elem: BA): Self
1616
^
1717
one error found
1818
*/
19-
def -(elem: BA): This
19+
def -(elem: BA): Self
2020
}
2121

2222
trait Buffer[A] extends BufferLike[A, Buffer[A]]

0 commit comments

Comments
 (0)