diff --git a/compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala b/compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala index bf0f11efb216..c03c7fc5bb99 100644 --- a/compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala +++ b/compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala @@ -340,7 +340,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder { case ApplyDynamic(qual, args) => sys.error("No invokedynamic support yet.") - case This(qual) => + case ThisRef(qual) => val symIsModuleClass = tree.symbol.isModuleClass assert(tree.symbol == claszSymbol || symIsModuleClass, s"Trying to access the this of another class: tree.symbol = ${tree.symbol}, class symbol = $claszSymbol compilation unit: $cunit") @@ -409,7 +409,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder { genLoad(expr, expectedType) else genBlock(blck, expectedType) - case Typed(Super(_, _), _) => genLoad(This(claszSymbol), expectedType) + case Typed(Super(_, _), _) => genLoad(ThisRef(claszSymbol), expectedType) case Typed(expr, _) => genLoad(expr, expectedType) @@ -1027,7 +1027,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder { assert(args.length == params.length, s"Wrong number of arguments in call to label at: $gotoPos") def isTrivial(kv: (Tree, Symbol)) = kv match { - case (This(_), p) if p.name == nme_THIS => true + case (ThisRef(_), p) if p.name == nme_THIS => true case (arg @ Ident(_), p) if arg.symbol == p => true case _ => false } diff --git a/compiler/src/dotty/tools/backend/jvm/BackendInterface.scala b/compiler/src/dotty/tools/backend/jvm/BackendInterface.scala index a3202d419407..4e15af434f52 100644 --- a/compiler/src/dotty/tools/backend/jvm/BackendInterface.scala +++ b/compiler/src/dotty/tools/backend/jvm/BackendInterface.scala @@ -40,7 +40,7 @@ abstract class BackendInterface extends BackendInterfaceDefinitions { type Typed >: Null <: Tree type ArrayValue >: Null <: Tree type Match >: Null <: Tree - type This >: Null <: Tree + type ThisRef >: Null <: Tree type CaseDef >: Null <: Tree type Alternative >: Null <: Tree type DefDef >: Null <: Tree @@ -78,7 +78,7 @@ abstract class BackendInterface extends BackendInterfaceDefinitions { implicit val ArrayValueTag: ClassTag[ArrayValue] implicit val MatchTag: ClassTag[Match] implicit val CaseDefTag: ClassTag[CaseDef] - implicit val ThisTag: ClassTag[This] + implicit val ThisTag: ClassTag[ThisRef] implicit val AlternativeTag: ClassTag[Alternative] implicit val DefDefTag: ClassTag[DefDef] implicit val ModuleDefTag: ClassTag[ModuleDef] @@ -201,7 +201,7 @@ abstract class BackendInterface extends BackendInterfaceDefinitions { val Throw: ThrowDeconstructor val New: NewDeconstructor val ApplyDynamic: ApplyDynamicDeconstructor - val This: ThisDeconstructor + val ThisRef: ThisDeconstructor val Ident: IdentDeconstructor val Try: TryDeconstructor val Labeled: LabeledDeconstructor @@ -287,7 +287,7 @@ abstract class BackendInterface extends BackendInterfaceDefinitions { def _3: Symbol // functionalInterface } - abstract class ThisDeconstructor extends Deconstructor1Common[This, Name]{ + abstract class ThisDeconstructor extends Deconstructor1Common[ThisRef, Name]{ def apply(s: Symbol): Tree } diff --git a/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala b/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala index 98491884a06f..c6453545e8d2 100644 --- a/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala +++ b/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala @@ -60,7 +60,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma type Block = tpd.Block type Typed = tpd.Typed type Match = tpd.Match - type This = tpd.This + type ThisRef = tpd.ThisRef type CaseDef = tpd.CaseDef type Alternative = tpd.Alternative type DefDef = tpd.DefDef @@ -198,7 +198,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma implicit val ArrayValueTag: ClassTag[ArrayValue] = ClassTag[ArrayValue](classOf[ArrayValue]) implicit val MatchTag: ClassTag[Match] = ClassTag[Match](classOf[Match]) implicit val CaseDefTag: ClassTag[CaseDef] = ClassTag[CaseDef](classOf[CaseDef]) - implicit val ThisTag: ClassTag[This] = ClassTag[This](classOf[This]) + implicit val ThisTag: ClassTag[ThisRef] = ClassTag[ThisRef](classOf[ThisRef]) implicit val AlternativeTag: ClassTag[Alternative] = ClassTag[Alternative](classOf[Alternative]) implicit val DefDefTag: ClassTag[DefDef] = ClassTag[DefDef](classOf[DefDef]) implicit val ModuleDefTag: ClassTag[ModuleDef] = ClassTag[ModuleDef](classOf[ModuleDef]) @@ -1053,9 +1053,9 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma def get: Type = field.tpt.tpe } - object This extends ThisDeconstructor { + object ThisRef extends ThisDeconstructor { def get: Name = field.qual.name - def apply(s: Symbol): This = tpd.This(s.asClass) + def apply(s: Symbol): ThisRef = tpd.ThisRef(s.asClass) } object Labeled extends LabeledDeconstructor { diff --git a/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala b/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala index 55e2473bc405..494562752b69 100644 --- a/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala +++ b/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala @@ -784,7 +784,7 @@ class JSCodeGen()(implicit ctx: Context) { implicit def pos: SourcePosition = tree.sourcePos tree match { - case _: This => + case _: ThisRef => val sym = tree.symbol if (sym != currentClassSym.get && sym.is(Module)) genLoadModuleOrGlobalScope(sym) @@ -882,7 +882,7 @@ class JSCodeGen()(implicit ctx: Context) { /*case app: ApplyDynamic => genApplyDynamic(app)*/ - case tree: This => + case tree: ThisRef => val currentClass = currentClassSym.get val symIsModuleClass = tree.symbol.is(ModuleClass) assert(tree.symbol == currentClass || symIsModuleClass, @@ -988,7 +988,7 @@ class JSCodeGen()(implicit ctx: Context) { def ctorAssignment = ( currentMethodSym.get.name == nme.CONSTRUCTOR && currentMethodSym.get.owner == qualifier.symbol && - qualifier.isInstanceOf[This] + qualifier.isInstanceOf[ThisRef] ) // TODO This fails for OFFSET$x fields. Re-enable when we can. /*if (!sym.is(Mutable) && !ctorAssignment) @@ -1042,7 +1042,7 @@ class JSCodeGen()(implicit ctx: Context) { case fun: Ident => fun.tpe match { case TermRef(prefix: TermRef, _) => tpd.ref(prefix) - case TermRef(prefix: ThisType, _) => tpd.This(prefix.cls) + case TermRef(prefix: ThisType, _) => tpd.ThisRef(prefix.cls) } case Select(qualifier, _) => qualifier @@ -2141,7 +2141,7 @@ class JSCodeGen()(implicit ctx: Context) { implicit val pos = value.span val formalIdent = value match { case Ident(name) => freshLocalIdent(name.toString) - case This(_) => freshLocalIdent("this") + case ThisRef(_) => freshLocalIdent("this") case _ => freshLocalIdent() } val formalCapture = diff --git a/compiler/src/dotty/tools/backend/sjs/JUnitBootstrappers.scala b/compiler/src/dotty/tools/backend/sjs/JUnitBootstrappers.scala index ef69b5e2f9d5..1ac736d64e98 100644 --- a/compiler/src/dotty/tools/backend/sjs/JUnitBootstrappers.scala +++ b/compiler/src/dotty/tools/backend/sjs/JUnitBootstrappers.scala @@ -181,7 +181,7 @@ class JUnitBootstrappers extends MiniPhase { val sym = ctx.newDefaultConstructor(owner).entered DefDef(sym, { Block( - Super(This(owner), nme.EMPTY.toTypeName, inConstrCall = true).select(defn.ObjectClass.primaryConstructor).appliedToNone :: Nil, + Super(ThisRef(owner), nme.EMPTY.toTypeName, inConstrCall = true).select(defn.ObjectClass.primaryConstructor).appliedToNone :: Nil, unitLiteral ) }) diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index 739694b709b8..ca35a7c9dfb7 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -597,7 +597,7 @@ object desugar { val caseParams = derivedVparamss.head.toArray for (i <- List.range(0, arity) if nme.selectorName(i) `ne` caseParams(i).name) yield syntheticProperty(nme.selectorName(i), caseParams(i).tpt, - Select(This(EmptyTypeIdent), caseParams(i).name)) + Select(ThisRef(EmptyTypeIdent), caseParams(i).name)) } def ordinalMeths = if (isEnumCase) ordinalMethLit(nextOrdinal(CaseKind.Class)._1) :: Nil else Nil def copyMeths = { diff --git a/compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala b/compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala index 787d206dbf49..c0664a37d17b 100644 --- a/compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala +++ b/compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala @@ -79,7 +79,7 @@ object DesugarEnums { private def registerCall(implicit ctx: Context): List[Tree] = if (enumClass.typeParams.nonEmpty) Nil - else Apply(valuesDot("register"), This(EmptyTypeIdent) :: Nil) :: Nil + else Apply(valuesDot("register"), ThisRef(EmptyTypeIdent) :: Nil) :: Nil /** The following lists of definitions for an enum type E: * diff --git a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala index fcb619cfca13..eff71b8825eb 100644 --- a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala +++ b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala @@ -109,7 +109,7 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] => /** Is tree a path? */ def isPath(tree: Tree): Boolean = unsplice(tree) match { - case Ident(_) | This(_) | Super(_, _) => true + case Ident(_) | ThisRef(_) | Super(_, _) => true case Select(qual, _) => isPath(qual) case _ => false } @@ -118,7 +118,7 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] => * same object? */ def isSelfConstrCall(tree: Tree): Boolean = methPart(tree) match { - case Ident(nme.CONSTRUCTOR) | Select(This(_), nme.CONSTRUCTOR) => true + case Ident(nme.CONSTRUCTOR) | Select(ThisRef(_), nme.CONSTRUCTOR) => true case _ => false } @@ -136,7 +136,7 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] => def isSelfOrSuperConstrCall(tree: Tree): Boolean = methPart(tree) match { case Ident(nme.CONSTRUCTOR) - | Select(This(_), nme.CONSTRUCTOR) + | Select(ThisRef(_), nme.CONSTRUCTOR) | Select(Super(_, _), nme.CONSTRUCTOR) => true case _ => false } @@ -381,7 +381,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] => */ def exprPurity(tree: Tree)(implicit ctx: Context): PurityLevel = unsplice(tree) match { case EmptyTree - | This(_) + | ThisRef(_) | Super(_, _) | Literal(_) => PurePath @@ -557,7 +557,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] => /** Is tree a `this` node which belongs to `enclClass`? */ def isSelf(tree: Tree, enclClass: Symbol)(implicit ctx: Context): Boolean = unsplice(tree) match { - case This(_) => tree.symbol == enclClass + case ThisRef(_) => tree.symbol == enclClass case _ => false } @@ -770,7 +770,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] => def qualifier(tree: Tree)(implicit ctx: Context): Tree = tree match { case Select(qual, _) => qual case tree: Ident => desugarIdentPrefix(tree) - case _ => This(ctx.owner.enclosingClass.asClass) + case _ => ThisRef(ctx.owner.enclosingClass.asClass) } /** Is this a (potentially applied) selection of a member of a structural type diff --git a/compiler/src/dotty/tools/dotc/ast/Trees.scala b/compiler/src/dotty/tools/dotc/ast/Trees.scala index 5df9e1d0bc3e..5d9ddbf54b20 100644 --- a/compiler/src/dotty/tools/dotc/ast/Trees.scala +++ b/compiler/src/dotty/tools/dotc/ast/Trees.scala @@ -415,10 +415,10 @@ object Trees { } /** qual.this */ - case class This[-T >: Untyped] private[ast] (qual: untpd.Ident)(implicit @constructorOnly src: SourceFile) + case class ThisRef[-T >: Untyped] private[ast] (qual: untpd.Ident)(implicit @constructorOnly src: SourceFile) extends DenotingTree[T] with TermTree[T] { - type ThisTree[-T >: Untyped] = This[T] - // Denotation of a This tree is always the underlying class; needs correction for modules. + type ThisTree[-T >: Untyped] = ThisRef[T] + // Denotation of a ThisRef tree is always the underlying class; needs correction for modules. override def denot(implicit ctx: Context): Denotation = typeOpt match { case tpe @ TermRef(pre, _) if tpe.symbol.is(Module) => @@ -949,7 +949,7 @@ object Trees { type SearchFailureIdent = Trees.SearchFailureIdent[T] type Select = Trees.Select[T] type SelectWithSig = Trees.SelectWithSig[T] - type This = Trees.This[T] + type ThisRef = Trees.ThisRef[T] type Super = Trees.Super[T] type Apply = Trees.Apply[T] type TypeApply = Trees.TypeApply[T] @@ -1046,9 +1046,9 @@ object Trees { case Ident(_) => Ident(tree)(name) case Select(qual, _) => Select(tree)(qual, name) } - def This(tree: Tree)(qual: untpd.Ident)(implicit ctx: Context): This = tree match { - case tree: This if (qual eq tree.qual) => tree - case _ => finalize(tree, untpd.This(qual)(sourceFile(tree))) + def ThisRef(tree: Tree)(qual: untpd.Ident)(implicit ctx: Context): ThisRef = tree match { + case tree: ThisRef if (qual eq tree.qual) => tree + case _ => finalize(tree, untpd.ThisRef(qual)(sourceFile(tree))) } def Super(tree: Tree)(qual: Tree, mix: untpd.Ident)(implicit ctx: Context): Super = tree match { case tree: Super if (qual eq tree.qual) && (mix eq tree.mix) => tree @@ -1254,7 +1254,7 @@ object Trees { tree case Select(qualifier, name) => cpy.Select(tree)(transform(qualifier), name) - case This(qual) => + case ThisRef(qual) => tree case Super(qual, mix) => cpy.Super(tree)(transform(qual), mix) @@ -1378,7 +1378,7 @@ object Trees { x case Select(qualifier, name) => this(x, qualifier) - case This(qual) => + case ThisRef(qual) => x case Super(qual, mix) => this(x, qual) diff --git a/compiler/src/dotty/tools/dotc/ast/tpd.scala b/compiler/src/dotty/tools/dotc/ast/tpd.scala index a95d6bdb437a..dd9a755aded2 100644 --- a/compiler/src/dotty/tools/dotc/ast/tpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/tpd.scala @@ -32,8 +32,8 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { def Select(qualifier: Tree, tp: NamedType)(implicit ctx: Context): Select = untpd.Select(qualifier, tp.name).withType(tp) - def This(cls: ClassSymbol)(implicit ctx: Context): This = - untpd.This(untpd.Ident(cls.name)).withType(cls.thisType) + def ThisRef(cls: ClassSymbol)(implicit ctx: Context): ThisRef = + untpd.ThisRef(untpd.Ident(cls.name)).withType(cls.thisType) def Super(qual: Tree, mix: untpd.Ident, inConstrCall: Boolean, mixinClass: Symbol)(implicit ctx: Context): Super = ta.assignType(untpd.Super(qual, mix), qual, inConstrCall, mixinClass) @@ -376,7 +376,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { if (tp.isType) TypeTree(tp) else if (prefixIsElidable(tp)) Ident(tp) else if (tp.symbol.is(Module) && ctx.owner.isContainedIn(tp.symbol.moduleClass)) - followOuterLinks(This(tp.symbol.moduleClass.asClass)) + followOuterLinks(ThisRef(tp.symbol.moduleClass.asClass)) else if (tp.symbol hasAnnotation defn.ScalaStaticAnnot) Ident(tp) else { @@ -389,7 +389,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { ref(NamedType(sym.owner.thisType, sym.name, sym.denot)) private def followOuterLinks(t: Tree)(implicit ctx: Context) = t match { - case t: This if ctx.erasedTypes && !(t.symbol == ctx.owner.enclosingClass || t.symbol.isStaticOwner) => + case t: ThisRef if ctx.erasedTypes && !(t.symbol == ctx.owner.enclosingClass || t.symbol.isStaticOwner) => // after erasure outer paths should be respected ExplicitOuter.OuterOps(ctx).path(toCls = t.tpe.widen.classSymbol) case t => @@ -398,7 +398,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { def singleton(tp: Type)(implicit ctx: Context): Tree = tp match { case tp: TermRef => ref(tp) - case tp: ThisType => This(tp.cls) + case tp: ThisType => ThisRef(tp.cls) case tp: SkolemType => singleton(tp.narrow) case SuperType(qual, _) => singleton(qual) case ConstantType(value) => Literal(value) @@ -1260,7 +1260,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { case TermRef(prefix: TermRef, _) => ref(prefix) case TermRef(prefix: ThisType, _) => - This(prefix.cls) + ThisRef(prefix.cls) case _ => EmptyTree } diff --git a/compiler/src/dotty/tools/dotc/ast/untpd.scala b/compiler/src/dotty/tools/dotc/ast/untpd.scala index 232f86731538..a7555a102d34 100644 --- a/compiler/src/dotty/tools/dotc/ast/untpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/untpd.scala @@ -322,7 +322,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo { def SearchFailureIdent(name: Name)(implicit src: SourceFile): SearchFailureIdent = new SearchFailureIdent(name) def Select(qualifier: Tree, name: Name)(implicit src: SourceFile): Select = new Select(qualifier, name) def SelectWithSig(qualifier: Tree, name: Name, sig: Signature)(implicit src: SourceFile): Select = new SelectWithSig(qualifier, name, sig) - def This(qual: Ident)(implicit src: SourceFile): This = new This(qual) + def ThisRef(qual: Ident)(implicit src: SourceFile): ThisRef = new ThisRef(qual) def Super(qual: Tree, mix: Ident)(implicit src: SourceFile): Super = new Super(qual, mix) def Apply(fun: Tree, args: List[Tree])(implicit src: SourceFile): Apply = new Apply(fun, args) def TypeApply(fun: Tree, args: List[Tree])(implicit src: SourceFile): TypeApply = new TypeApply(fun, args) diff --git a/compiler/src/dotty/tools/dotc/core/Constraint.scala b/compiler/src/dotty/tools/dotc/core/Constraint.scala index b40b806c85bb..035717f88b5f 100644 --- a/compiler/src/dotty/tools/dotc/core/Constraint.scala +++ b/compiler/src/dotty/tools/dotc/core/Constraint.scala @@ -15,7 +15,7 @@ import printing.Showable */ abstract class Constraint extends Showable { - type This <: Constraint + type ThisConstraint <: Constraint /** Does the constraint's domain contain the type parameters of `tl`? */ def contains(tl: TypeLambda): Boolean @@ -77,7 +77,7 @@ abstract class Constraint extends Showable { * satisfiability but will solved to give instances of * type variables. */ - def add(poly: TypeLambda, tvars: List[TypeVar])(implicit ctx: Context): This + def add(poly: TypeLambda, tvars: List[TypeVar])(implicit ctx: Context): ThisConstraint /** A new constraint which is derived from this constraint by updating * the entry for parameter `param` to `tp`. @@ -88,18 +88,18 @@ abstract class Constraint extends Showable { * * @pre `this contains param`. */ - def updateEntry(param: TypeParamRef, tp: Type)(implicit ctx: Context): This + def updateEntry(param: TypeParamRef, tp: Type)(implicit ctx: Context): ThisConstraint /** A constraint that includes the relationship `p1 <: p2`. * `<:` relationships between parameters ("edges") are propagated, but * non-parameter bounds are left alone. */ - def addLess(p1: TypeParamRef, p2: TypeParamRef)(implicit ctx: Context): This + def addLess(p1: TypeParamRef, p2: TypeParamRef)(implicit ctx: Context): ThisConstraint /** A constraint resulting from adding p2 = p1 to this constraint, and at the same * time transferring all bounds of p2 to p1 */ - def unify(p1: TypeParamRef, p2: TypeParamRef)(implicit ctx: Context): This + def unify(p1: TypeParamRef, p2: TypeParamRef)(implicit ctx: Context): ThisConstraint /** A new constraint which is derived from this constraint by removing * the type parameter `param` from the domain and replacing all top-level occurrences @@ -107,7 +107,7 @@ abstract class Constraint extends Showable { * approximation of it if that is needed to avoid cycles. * Occurrences nested inside a refinement or prefix are not affected. */ - def replace(param: TypeParamRef, tp: Type)(implicit ctx: Context): This + def replace(param: TypeParamRef, tp: Type)(implicit ctx: Context): ThisConstraint /** Is entry associated with `tl` removable? This is the case if * all type parameters of the entry are associated with type variables @@ -116,10 +116,10 @@ abstract class Constraint extends Showable { def isRemovable(tl: TypeLambda): Boolean /** A new constraint with all entries coming from `tl` removed. */ - def remove(tl: TypeLambda)(implicit ctx: Context): This + def remove(tl: TypeLambda)(implicit ctx: Context): ThisConstraint /** A new constraint with entry `tl` renamed to a fresh type lambda */ - def rename(tl: TypeLambda)(implicit ctx: Context): This + def rename(tl: TypeLambda)(implicit ctx: Context): ThisConstraint /** The given `tl` in case it is not contained in this constraint, * a fresh copy of `tl` otherwise. diff --git a/compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala b/compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala index e578d5f0032e..91377aa21fd2 100644 --- a/compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala +++ b/compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala @@ -133,7 +133,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds, private val lowerMap : ParamOrdering, private val upperMap : ParamOrdering) extends Constraint { - type This = OrderingConstraint + type ThisConstraint = OrderingConstraint // ----------- Basic indices -------------------------------------------------- @@ -278,7 +278,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds, stripParams(tp, paramBuf, isUpper) .orElse(if (isUpper) defn.AnyType else defn.NothingType) - def add(poly: TypeLambda, tvars: List[TypeVar])(implicit ctx: Context): This = { + def add(poly: TypeLambda, tvars: List[TypeVar])(implicit ctx: Context): ThisConstraint = { assert(!contains(poly)) val nparams = poly.paramNames.length val entries1 = new Array[Type](nparams * 2) @@ -291,7 +291,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds, * Update all bounds to be normalized and update ordering to account for * dependent parameters. */ - private def init(poly: TypeLambda)(implicit ctx: Context): This = { + private def init(poly: TypeLambda)(implicit ctx: Context): ThisConstraint = { var current = this val loBuf, hiBuf = new mutable.ListBuffer[TypeParamRef] var i = 0 @@ -316,7 +316,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds, /** Add the fact `param1 <: param2` to the constraint `current` and propagate * `<:<` relationships between parameters ("edges") but not bounds. */ - private def order(current: This, param1: TypeParamRef, param2: TypeParamRef)(implicit ctx: Context): This = + private def order(current: ThisConstraint, param1: TypeParamRef, param2: TypeParamRef)(implicit ctx: Context): ThisConstraint = if (param1 == param2 || current.isLess(param1, param2)) this else { assert(contains(param1), i"$param1") @@ -328,10 +328,10 @@ class OrderingConstraint(private val boundsMap: ParamBounds, current2 } - def addLess(param1: TypeParamRef, param2: TypeParamRef)(implicit ctx: Context): This = + def addLess(param1: TypeParamRef, param2: TypeParamRef)(implicit ctx: Context): ThisConstraint = order(this, param1, param2) - def updateEntry(current: This, param: TypeParamRef, tp: Type)(implicit ctx: Context): This = { + def updateEntry(current: ThisConstraint, param: TypeParamRef, tp: Type)(implicit ctx: Context): ThisConstraint = { var current1 = boundsLens.update(this, current, param, tp) tp match { case TypeBounds(lo, hi) => @@ -344,10 +344,10 @@ class OrderingConstraint(private val boundsMap: ParamBounds, current1 } - def updateEntry(param: TypeParamRef, tp: Type)(implicit ctx: Context): This = + def updateEntry(param: TypeParamRef, tp: Type)(implicit ctx: Context): ThisConstraint = updateEntry(this, param, tp) - def unify(p1: TypeParamRef, p2: TypeParamRef)(implicit ctx: Context): This = { + def unify(p1: TypeParamRef, p2: TypeParamRef)(implicit ctx: Context): ThisConstraint = { val p1Bounds = (nonParamBounds(p1) & nonParamBounds(p2)).substParam(p2, p1) updateEntry(p1, p1Bounds).replace(p2, p1) } @@ -438,7 +438,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds, } } - def remove(pt: TypeLambda)(implicit ctx: Context): This = { + def remove(pt: TypeLambda)(implicit ctx: Context): ThisConstraint = { def removeFromOrdering(po: ParamOrdering) = { def removeFromBoundss(key: TypeLambda, bndss: Array[List[TypeParamRef]]): Array[List[TypeParamRef]] = { val bndss1 = bndss.map(_.filterConserve(_.binder ne pt)) diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index be885758046e..692fcaf6953a 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -1328,7 +1328,7 @@ object SymDenotations { /** The type parameters of a class symbol, Nil for all other symbols */ def typeParams(implicit ctx: Context): List[TypeSymbol] = Nil - /** The type This(cls), where cls is this class, NoPrefix for all other symbols */ + /** The type ThisType(cls), where cls is this class, NoPrefix for all other symbols */ def thisType(implicit ctx: Context): Type = NoPrefix def typeRef(implicit ctx: Context): TypeRef = diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index fd26d60c30b2..46e394c7f99a 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -2968,7 +2968,7 @@ object Types { trait LambdaType extends BindingType with TermType { self => type ThisName <: Name type PInfo <: Type - type This <: LambdaType{type PInfo = self.PInfo} + type ThisLambda <: LambdaType{type PInfo = self.PInfo} type ParamRefType <: ParamRef def paramNames: List[ThisName] @@ -3002,7 +3002,7 @@ object Types { if (isResultDependent) resultType.substParams(this, argTypes) else resultType - def companion: LambdaTypeCompanion[ThisName, PInfo, This] + def companion: LambdaTypeCompanion[ThisName, PInfo, ThisLambda] /** The type `[tparams := paramRefs] tp`, where `tparams` can be * either a list of type parameter symbols or a list of lambda parameters @@ -3019,7 +3019,7 @@ object Types { if ((paramNames eq this.paramNames) && (paramInfos eq this.paramInfos) && (resType eq this.resType)) this else newLikeThis(paramNames, paramInfos, resType) - final def newLikeThis(paramNames: List[ThisName], paramInfos: List[PInfo], resType: Type)(implicit ctx: Context): This = + final def newLikeThis(paramNames: List[ThisName], paramInfos: List[PInfo], resType: Type)(implicit ctx: Context): ThisLambda = companion(paramNames)( x => paramInfos.mapConserve(_.subst(this, x).asInstanceOf[PInfo]), x => resType.subst(this, x)) @@ -3077,7 +3077,7 @@ object Types { import DepStatus._ type ThisName = TermName type PInfo = Type - type This <: TermLambda + type ThisLambda <: TermLambda type ParamRefType = TermParamRef override def resultType(implicit ctx: Context): Type = @@ -3188,7 +3188,7 @@ object Types { resultTypeExp: MethodType => Type) extends MethodOrPoly with TermLambda with NarrowCached { thisMethodType => - type This = MethodType + type ThisLambda = MethodType val paramInfos: List[Type] = paramInfosExp(this) val resType: Type = resultTypeExp(this) @@ -3331,7 +3331,7 @@ object Types { trait TypeLambda extends LambdaType { type ThisName = TypeName type PInfo = TypeBounds - type This <: TypeLambda + type ThisLambda <: TypeLambda type ParamRefType = TypeParamRef def isResultDependent(implicit ctx: Context): Boolean = true @@ -3369,7 +3369,7 @@ object Types { class HKTypeLambda(val paramNames: List[TypeName])( paramInfosExp: HKTypeLambda => List[TypeBounds], resultTypeExp: HKTypeLambda => Type) extends HKLambda with TypeLambda { - type This = HKTypeLambda + type ThisLambda = HKTypeLambda def companion: HKTypeLambda.type = HKTypeLambda val paramInfos: List[TypeBounds] = paramInfosExp(this) @@ -3388,7 +3388,7 @@ object Types { paramInfosExp: PolyType => List[TypeBounds], resultTypeExp: PolyType => Type) extends MethodOrPoly with TypeLambda { - type This = PolyType + type ThisLambda = PolyType def companion: PolyType.type = PolyType val paramInfos: List[TypeBounds] = paramInfosExp(this) diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala index edaceec7e7e9..76e9f9a02e77 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala @@ -347,7 +347,7 @@ class TreePickler(pickler: TastyPickler) { pickleName(name) pickleType(tp) } - case This(qual) => + case ThisRef(qual) => if (qual.isEmpty) pickleType(tree.tpe) else { writeByte(QUALTHIS) diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index 410952c6d078..3b93b98de027 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -1005,7 +1005,7 @@ class TreeUnpickler(reader: TastyReader, readType() match { case path: TypeRef => TypeTree(path) case path: TermRef => ref(path) - case path: ThisType => untpd.This(untpd.EmptyTypeIdent).withType(path) + case path: ThisType => untpd.ThisRef(untpd.EmptyTypeIdent).withType(path) case path: ConstantType => Literal(path.value) } } @@ -1055,7 +1055,7 @@ class TreeUnpickler(reader: TastyReader, completeSelect(name, Signature.NotAMethod) case QUALTHIS => val (qual, tref) = readQualId() - untpd.This(qual).withType(ThisType.raw(tref)) + untpd.ThisRef(qual).withType(ThisType.raw(tref)) case NEW => New(readTpt()) case THROW => diff --git a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index 4bfcd1b5236d..9e2037f60e81 100644 --- a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -1197,7 +1197,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas case THIStree => setSym() val name = readTypeNameRef() - This(symbol.asClass) + ThisRef(symbol.asClass) case SELECTtree => setSym() diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 50b917574bc4..48959391cb9e 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -1050,14 +1050,14 @@ object Parsers { val start = in.offset def handleThis(qual: Ident) = { in.nextToken() - val t = atSpan(start) { This(qual) } + val t = atSpan(start) { ThisRef(qual) } if (!thisOK && in.token != DOT) syntaxError(DanglingThisInPath(), t.span) dotSelectors(t, finish) } def handleSuper(qual: Ident) = { in.nextToken() val mix = mixinQualifierOpt() - val t = atSpan(start) { Super(This(qual), mix) } + val t = atSpan(start) { Super(ThisRef(qual), mix) } accept(DOT) dotSelectors(selector(t), finish) } @@ -1152,7 +1152,7 @@ object Parsers { val tok = in.toToken(in.name) tok match { case TRUE | FALSE | NULL => literalOf(tok) - case THIS => This(EmptyTypeIdent) + case THIS => ThisRef(EmptyTypeIdent) case _ => Ident(in.name) } } @@ -1198,7 +1198,7 @@ object Parsers { } else if (in.token == THIS) { in.nextToken() - This(EmptyTypeIdent) + ThisRef(EmptyTypeIdent) } else if (in.token == LBRACE) if (inPattern) Block(Nil, inBraces(pattern())) @@ -3582,7 +3582,7 @@ object Parsers { val first = expr1() if (in.token == ARROW) { first match { - case Typed(tree @ This(EmptyTypeIdent), tpt) => + case Typed(tree @ ThisRef(EmptyTypeIdent), tpt) => self = makeSelfDef(nme.WILDCARD, tpt).withSpan(first.span) case _ => val ValDef(name, tpt, _) = convertToParam(first, "self type clause") diff --git a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala index 4610ab003499..d78d544e4e40 100644 --- a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -291,7 +291,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { case _ => false } - def optDotPrefix(tree: This) = optText(tree.qual)(_ ~ ".") provided !isLocalThis(tree) + def optDotPrefix(tree: ThisRef) = optText(tree.qual)(_ ~ ".") provided !isLocalThis(tree) def caseBlockText(tree: Tree): Text = tree match { case Block(stats, expr) => toText(stats :+ expr, "\n") @@ -377,9 +377,9 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { if (!printDebug && tree.hasType && tree.symbol == defn.QuotedType_splice) typeText("${") ~ toTextLocal(qual) ~ typeText("}") else if (qual.isType) toTextLocal(qual) ~ "#" ~ typeText(toText(name)) else toTextLocal(qual) ~ ("." ~ nameIdText(tree) provided (name != nme.CONSTRUCTOR || printDebug)) - case tree: This => + case tree: ThisRef => optDotPrefix(tree) ~ keywordStr("this") ~ idText(tree) - case Super(qual: This, mix) => + case Super(qual: ThisRef, mix) => optDotPrefix(qual) ~ keywordStr("super") ~ optText(mix)("[" ~ _ ~ "]") case app @ Apply(fun, args) => if (fun.hasType && fun.symbol == defn.throwMethod) diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala index 49de5fb09d43..909755004ac4 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala @@ -312,20 +312,20 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend def Literal_copy(original: Tree)(constant: Constant)(given Context): Literal = tpd.cpy.Literal(original)(constant) - type This = tpd.This + type ThisRef = tpd.ThisRef - def matchThis(x: Term)(given Context): Option[This] = x match { - case x: tpd.This => Some(x) + def matchThis(x: Term)(given Context): Option[ThisRef] = x match { + case x: tpd.ThisRef => Some(x) case _ => None } - def This_id(self: This)(given Context): Option[Id] = optional(self.qual) + def This_id(self: ThisRef)(given Context): Option[Id] = optional(self.qual) - def This_apply(cls: Symbol)(given Context): This = - withDefaultPos(tpd.This(cls.asClass)) + def This_apply(cls: Symbol)(given Context): ThisRef = + withDefaultPos(tpd.ThisRef(cls.asClass)) - def This_copy(original: Tree)(qual: Option[Id])(given Context): This = - tpd.cpy.This(original)(qual.getOrElse(untpd.EmptyTypeIdent)) + def This_copy(original: Tree)(qual: Option[Id])(given Context): ThisRef = + tpd.cpy.ThisRef(original)(qual.getOrElse(untpd.EmptyTypeIdent)) type New = tpd.New diff --git a/compiler/src/dotty/tools/dotc/transform/Bridges.scala b/compiler/src/dotty/tools/dotc/transform/Bridges.scala index 91b595728be8..9e9ab6685e3e 100644 --- a/compiler/src/dotty/tools/dotc/transform/Bridges.scala +++ b/compiler/src/dotty/tools/dotc/transform/Bridges.scala @@ -102,7 +102,7 @@ class Bridges(root: ClassSymbol, thisPhase: DenotTransformer)(implicit ctx: Cont } def bridgeRhs(argss: List[List[Tree]]) = { - val ref = This(root).select(member) + val ref = ThisRef(root).select(member) if (member.info.isParameterless) ref // can happen if `member` is a module else ref.appliedToArgss(argss) } diff --git a/compiler/src/dotty/tools/dotc/transform/CheckStatic.scala b/compiler/src/dotty/tools/dotc/transform/CheckStatic.scala index 00cf1638f602..8798cb3c0c92 100644 --- a/compiler/src/dotty/tools/dotc/transform/CheckStatic.scala +++ b/compiler/src/dotty/tools/dotc/transform/CheckStatic.scala @@ -62,7 +62,7 @@ class CheckStatic extends MiniPhase { val symbolWhitelist = tree.symbol.ownersIterator.flatMap(x => if (x.is(Flags.Module)) List(x, x.companionModule) else List(x)).toSet def isSafeQual(t: Tree): Boolean = // follow the desugared paths created by typer t match { - case t: This => true + case t: ThisRef => true case t: Select => isSafeQual(t.qualifier) && symbolWhitelist.contains(t.symbol) case t: Ident => symbolWhitelist.contains(t.symbol) case t: Block => t.stats.forall(tpd.isPureExpr) && isSafeQual(t.expr) diff --git a/compiler/src/dotty/tools/dotc/transform/Constructors.scala b/compiler/src/dotty/tools/dotc/transform/Constructors.scala index 49e3c4805d67..3fac6a1abee5 100644 --- a/compiler/src/dotty/tools/dotc/transform/Constructors.scala +++ b/compiler/src/dotty/tools/dotc/transform/Constructors.scala @@ -62,7 +62,7 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase = val owner = sym.owner.asClass tree match { - case Ident(_) | Select(This(_), _) => + case Ident(_) | Select(ThisRef(_), _) => def inConstructor = { val method = ctx.owner.enclosingMethod method.isPrimaryConstructor && ctx.owner.enclosingClass == owner @@ -146,7 +146,7 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase = // drop the () when replacing by the parameter. object intoConstr extends TreeMap { override def transform(tree: Tree)(implicit ctx: Context): Tree = tree match { - case Ident(_) | Select(This(_), _) => + case Ident(_) | Select(ThisRef(_), _) => var sym = tree.symbol if (sym.is(ParamAccessor, butNot = Mutable)) sym = sym.subst(accessors, paramSyms) if (sym.owner.isConstructor) ref(sym).withSpan(tree.span) else tree diff --git a/compiler/src/dotty/tools/dotc/transform/ElimStaticThis.scala b/compiler/src/dotty/tools/dotc/transform/ElimStaticThis.scala index abb4611479c5..9d39cb51ac96 100644 --- a/compiler/src/dotty/tools/dotc/transform/ElimStaticThis.scala +++ b/compiler/src/dotty/tools/dotc/transform/ElimStaticThis.scala @@ -15,7 +15,7 @@ class ElimStaticThis extends MiniPhase { import ast.tpd._ def phaseName: String = "elimStaticThis" - override def transformThis(tree: This)(implicit ctx: Context): Tree = + override def transformThis(tree: ThisRef)(implicit ctx: Context): Tree = if (!tree.symbol.is(Package) && ctx.owner.enclosingMethod.is(JavaStatic)) { assert(tree.symbol.is(ModuleClass)) ref(tree.symbol.sourceModule) diff --git a/compiler/src/dotty/tools/dotc/transform/Erasure.scala b/compiler/src/dotty/tools/dotc/transform/Erasure.scala index 27e903e488e0..0b2f2f6ba5fc 100644 --- a/compiler/src/dotty/tools/dotc/transform/Erasure.scala +++ b/compiler/src/dotty/tools/dotc/transform/Erasure.scala @@ -103,7 +103,7 @@ class Erasure extends Phase with DenotTransformer { override def checkPostCondition(tree: tpd.Tree)(implicit ctx: Context): Unit = { assertErased(tree) tree match { - case res: tpd.This => + case res: tpd.ThisRef => assert(!ExplicitOuter.referencesOuter(ctx.owner.lexicallyEnclosingClass, res), i"Reference to $res from ${ctx.owner.showLocated}") case ret: tpd.Return => @@ -171,7 +171,7 @@ object Erasure { * when enclosed in a box, the unboxed argument, otherwise EmptyTree. * Note that one can't always remove a Box(Unbox(x)) combination because the * process of unboxing x may lead to throwing an exception. - * This is important for specialization: calls to the super constructor should not box/unbox specialized + * ThisRef is important for specialization: calls to the super constructor should not box/unbox specialized * fields (see TupleX). (ID) */ private def safelyRemovableUnboxArg(tree: Tree)(implicit ctx: Context): Tree = tree match { @@ -376,13 +376,13 @@ object Erasure { } /** When erasing most TypeTrees we should not semi-erase value types. - * This is not the case for [[DefDef#tpt]], [[ValDef#tpt]] and [[Typed#tpt]], they + * ThisRef is not the case for [[DefDef#tpt]], [[ValDef#tpt]] and [[Typed#tpt]], they * are handled separately by [[typedDefDef]], [[typedValDef]] and [[typedTyped]]. */ override def typedTypeTree(tree: untpd.TypeTree, pt: Type)(implicit ctx: Context): TypeTree = tree.withType(erasure(tree.tpe)) - /** This override is only needed to semi-erase type ascriptions */ + /** ThisRef override is only needed to semi-erase type ascriptions */ override def typedTyped(tree: untpd.Typed, pt: Type)(implicit ctx: Context): Tree = { val Typed(expr, tpt) = tree val tpt1 = tpt match { @@ -500,7 +500,7 @@ object Erasure { checkValue(checkNotErased(recur(qual1)), pt) } - override def typedThis(tree: untpd.This)(implicit ctx: Context): Tree = + override def typedThis(tree: untpd.ThisRef)(implicit ctx: Context): Tree = if (tree.symbol == ctx.owner.lexicallyEnclosingClass || tree.symbol.isStaticOwner) promote(tree) else { ctx.log(i"computing outer path from ${ctx.owner.ownersIterator.toList}%, % to ${tree.symbol}, encl class = ${ctx.owner.enclosingClass}") @@ -571,7 +571,7 @@ object Erasure { // The following four methods take as the proto-type the erasure of the pre-existing type, // if the original proto-type is not a value type. - // This makes all branches be adapted to the correct type. + // ThisRef makes all branches be adapted to the correct type. override def typedSeqLiteral(tree: untpd.SeqLiteral, pt: Type)(implicit ctx: Context): SeqLiteral = super.typedSeqLiteral(tree, erasure(tree.typeOpt)) // proto type of typed seq literal is original type; diff --git a/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala b/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala index 86b15800f548..e352961c3d8d 100644 --- a/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala +++ b/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala @@ -274,7 +274,7 @@ object ExplicitOuter { case _ => false } tree match { - case _: This | _: Ident => isOuterRef(tree.tpe) + case _: ThisRef | _: Ident => isOuterRef(tree.tpe) case nw: New => val newCls = nw.tpe.classSymbol isOuterSym(newCls.owner.enclosingClass) || @@ -364,7 +364,7 @@ object ExplicitOuter { def outerArg(receiver: Tree): Tree = receiver match { case New(_) | Super(_, _) => singleton(fixThis(outerPrefix(receiver.tpe))) - case This(_) => + case ThisRef(_) => ref(outerParamAccessor(cls)) // will be rewired to outer argument of secondary constructor in phase Constructors case TypeApply(Select(r, nme.asInstanceOf_), args) => outerArg(r) // cast was inserted, skip @@ -386,7 +386,7 @@ object ExplicitOuter { * - if the initial `count` parameter is negative: where the class symbol of * the type of the reached tree matches `toCls`. */ - def path(start: Tree = This(ctx.owner.lexicallyEnclosingClass.asClass), + def path(start: Tree = ThisRef(ctx.owner.lexicallyEnclosingClass.asClass), toCls: Symbol = NoSymbol, count: Int = -1): Tree = try { @tailrec def loop(tree: Tree, count: Int): Tree = { diff --git a/compiler/src/dotty/tools/dotc/transform/ExplicitSelf.scala b/compiler/src/dotty/tools/dotc/transform/ExplicitSelf.scala index aec65969d706..d3575a869404 100644 --- a/compiler/src/dotty/tools/dotc/transform/ExplicitSelf.scala +++ b/compiler/src/dotty/tools/dotc/transform/ExplicitSelf.scala @@ -29,12 +29,12 @@ class ExplicitSelf extends MiniPhase { override def transformIdent(tree: Ident)(implicit ctx: Context): Tree = tree.tpe match { case tp: ThisType => ctx.debuglog(s"owner = ${ctx.owner}, context = ${ctx}") - This(tp.cls).withSpan(tree.span) + ThisRef(tp.cls).withSpan(tree.span) case _ => tree } override def transformSelect(tree: Select)(implicit ctx: Context): Tree = tree match { - case Select(thiz: This, name) if name.isTermName => + case Select(thiz: ThisRef, name) if name.isTermName => val cls = thiz.symbol.asClass if (cls.givenSelfType.exists && !cls.derivesFrom(tree.symbol.owner)) cpy.Select(tree)(thiz.cast(AndType(cls.classInfo.selfType, thiz.tpe)), name) diff --git a/compiler/src/dotty/tools/dotc/transform/FullParameterization.scala b/compiler/src/dotty/tools/dotc/transform/FullParameterization.scala index 7a5ca8a5ee5f..111d0ea022c0 100644 --- a/compiler/src/dotty/tools/dotc/transform/FullParameterization.scala +++ b/compiler/src/dotty/tools/dotc/transform/FullParameterization.scala @@ -208,7 +208,7 @@ trait FullParameterization { .subst(origTParams ++ origVParams, trefs ++ argRefs.map(_.tpe)) .substThisUnlessStatic(origClass, thisRef.tpe), treeMap = { - case tree: This if tree.symbol == origClass => thisRef + case tree: ThisRef if tree.symbol == origClass => thisRef case tree => rewireTree(tree, Nil) orElse tree }, oldOwners = origMeth :: Nil, @@ -225,7 +225,7 @@ trait FullParameterization { val fun = ref(derived.termRef) .appliedToTypes(allInstanceTypeParams(originalDef, abstractOverClass).map(_.typeRef)) - .appliedTo(This(originalDef.symbol.enclosingClass.asClass)) + .appliedTo(ThisRef(originalDef.symbol.enclosingClass.asClass)) (if (!liftThisType) fun.appliedToArgss(originalDef.vparamss.nestedMap(vparam => ref(vparam.symbol))) diff --git a/compiler/src/dotty/tools/dotc/transform/HoistSuperArgs.scala b/compiler/src/dotty/tools/dotc/transform/HoistSuperArgs.scala index d72f0895ca49..37c8c7fbb195 100644 --- a/compiler/src/dotty/tools/dotc/transform/HoistSuperArgs.scala +++ b/compiler/src/dotty/tools/dotc/transform/HoistSuperArgs.scala @@ -109,11 +109,11 @@ class HoistSuperArgs extends MiniPhase with IdentityDenotTransformer { thisPhase /** Super call argument is complex, needs to be hoisted */ def needsHoist(tree: Tree) = tree match { - case _: DefDef => true - case _: Template => true - case _: New => !tree.tpe.typeSymbol.isStatic - case _: RefTree | _: This => refNeedsHoist(tree.tpe) - case _ => false + case _: DefDef => true + case _: Template => true + case _: New => !tree.tpe.typeSymbol.isStatic + case _: RefTree | _: ThisRef => refNeedsHoist(tree.tpe) + case _ => false } // begin hoistSuperArg diff --git a/compiler/src/dotty/tools/dotc/transform/InterceptedMethods.scala b/compiler/src/dotty/tools/dotc/transform/InterceptedMethods.scala index be456b9b8e27..e97188e78c90 100644 --- a/compiler/src/dotty/tools/dotc/transform/InterceptedMethods.scala +++ b/compiler/src/dotty/tools/dotc/transform/InterceptedMethods.scala @@ -68,7 +68,7 @@ class InterceptedMethods extends MiniPhase { case TermRef(prefix: TermRef, _) => tpd.ref(prefix) case TermRef(prefix: ThisType, _) => - tpd.This(prefix.cls) + tpd.ThisRef(prefix.cls) } } diff --git a/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala b/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala index a53d3bc9b368..41446a6f5707 100644 --- a/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala +++ b/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala @@ -212,7 +212,7 @@ object LambdaLift { captureImplicitThis(tree.tpe) case tree: Select => if (sym.is(Method) && isLocal(sym)) markCalled(sym, enclosure) - case tree: This => + case tree: ThisRef => narrowTo(tree.symbol.asClass) case tree: DefDef => if (sym.owner.isTerm) @@ -324,7 +324,7 @@ object LambdaLift { private def liftLocals()(implicit ctx: Context): Unit = { for ((local, lOwner) <- liftedOwner) { val (newOwner, maybeStatic) = - if (lOwner is Package) { + if (lOwner is Package) { val encClass = local.enclosingClass val topClass = local.topLevelClass val preferEncClass = diff --git a/compiler/src/dotty/tools/dotc/transform/LazyVals.scala b/compiler/src/dotty/tools/dotc/transform/LazyVals.scala index 2802bae99fb3..af2044f9ffea 100644 --- a/compiler/src/dotty/tools/dotc/transform/LazyVals.scala +++ b/compiler/src/dotty/tools/dotc/transform/LazyVals.scala @@ -308,7 +308,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer { val computeState = Literal(Constant(1)) val computedState = Literal(Constant(3)) - val thiz = This(claz) + val thiz = ThisRef(claz) val fieldId = Literal(Constant(ord)) val flagSymbol = ctx.newSymbol(methodSymbol, lazyNme.flag, Synthetic, defn.LongType) diff --git a/compiler/src/dotty/tools/dotc/transform/LinkScala2Impls.scala b/compiler/src/dotty/tools/dotc/transform/LinkScala2Impls.scala index d97d51142012..db27ec91d28c 100644 --- a/compiler/src/dotty/tools/dotc/transform/LinkScala2Impls.scala +++ b/compiler/src/dotty/tools/dotc/transform/LinkScala2Impls.scala @@ -76,7 +76,7 @@ class LinkScala2Impls extends MiniPhase with IdentityDenotTransformer { thisPhas case Apply(sel @ Select(Super(_, _), _), args) if sel.symbol.owner.is(Scala2x) && currentClass.mixins.contains(sel.symbol.owner) && !ctx.settings.scalajs.value => val impl = implMethod(sel.symbol) - if (impl.exists) Apply(ref(impl), This(currentClass) :: args).withSpan(app.span) + if (impl.exists) Apply(ref(impl), ThisRef(currentClass) :: args).withSpan(app.span) else app // could have been an abstract method in a trait linked to from a super constructor case _ => app diff --git a/compiler/src/dotty/tools/dotc/transform/MegaPhase.scala b/compiler/src/dotty/tools/dotc/transform/MegaPhase.scala index 5f6ef3daf9ae..7fd572c2014b 100644 --- a/compiler/src/dotty/tools/dotc/transform/MegaPhase.scala +++ b/compiler/src/dotty/tools/dotc/transform/MegaPhase.scala @@ -48,7 +48,7 @@ object MegaPhase { def prepareForIdent(tree: Ident)(implicit ctx: Context): Context = ctx def prepareForSelect(tree: Select)(implicit ctx: Context): Context = ctx - def prepareForThis(tree: This)(implicit ctx: Context): Context = ctx + def prepareForThis(tree: ThisRef)(implicit ctx: Context): Context = ctx def prepareForSuper(tree: Super)(implicit ctx: Context): Context = ctx def prepareForApply(tree: Apply)(implicit ctx: Context): Context = ctx def prepareForTypeApply(tree: TypeApply)(implicit ctx: Context): Context = ctx @@ -82,7 +82,7 @@ object MegaPhase { def transformIdent(tree: Ident)(implicit ctx: Context): Tree = tree def transformSelect(tree: Select)(implicit ctx: Context): Tree = tree - def transformThis(tree: This)(implicit ctx: Context): Tree = tree + def transformThis(tree: ThisRef)(implicit ctx: Context): Tree = tree def transformSuper(tree: Super)(implicit ctx: Context): Tree = tree def transformApply(tree: Apply)(implicit ctx: Context): Tree = tree def transformTypeApply(tree: TypeApply)(implicit ctx: Context): Tree = tree @@ -180,7 +180,7 @@ class MegaPhase(val miniPhases: Array[MiniPhase]) extends Phase { case tree: TypeTree => goTypeTree(tree, start) case tree: Thicket => cpy.Thicket(tree)(tree.trees.mapConserve(transformNode(_, start))) - case tree: This => goThis(tree, start) + case tree: ThisRef => goThis(tree, start) case tree: Literal => goLiteral(tree, start) case tree: Block => goBlock(tree, start) case tree: TypeApply => goTypeApply(tree, start) @@ -275,7 +275,7 @@ class MegaPhase(val miniPhases: Array[MiniPhase]) extends Phase { goTypeTree(tree, start) case tree: Thicket => cpy.Thicket(tree)(transformTrees(tree.trees, start)) - case tree: This => + case tree: ThisRef => implicit val ctx = prepThis(tree, start)(outerCtx) goThis(tree, start) case tree: Literal => @@ -569,17 +569,17 @@ class MegaPhase(val miniPhases: Array[MiniPhase]) extends Phase { } } - def prepThis(tree: This, start: Int)(implicit ctx: Context): Context = { + def prepThis(tree: ThisRef, start: Int)(implicit ctx: Context): Context = { val phase = nxThisPrepPhase(start) if (phase == null) ctx else prepThis(tree, phase.idxInGroup + 1)(phase.prepareForThis(tree)) } - def goThis(tree: This, start: Int)(implicit ctx: Context): Tree = { + def goThis(tree: ThisRef, start: Int)(implicit ctx: Context): Tree = { val phase = nxThisTransPhase(start) if (phase == null) tree else phase.transformThis(tree)(ctx) match { - case tree1: This => goThis(tree1, phase.idxInGroup + 1) + case tree1: ThisRef => goThis(tree1, phase.idxInGroup + 1) case tree1 => transformNode(tree1, phase.idxInGroup + 1) } } diff --git a/compiler/src/dotty/tools/dotc/transform/Mixin.scala b/compiler/src/dotty/tools/dotc/transform/Mixin.scala index 6914f59fb1b6..f4a7764d41dd 100644 --- a/compiler/src/dotty/tools/dotc/transform/Mixin.scala +++ b/compiler/src/dotty/tools/dotc/transform/Mixin.scala @@ -239,7 +239,7 @@ class Mixin extends MiniPhase with SymTransformer { thisPhase => if (getter.is(Lazy, butNot = Module)) initial else if (getter.is(Module)) - New(getter.info.resultType, List(This(cls))) + New(getter.info.resultType, List(ThisRef(cls))) else Underscore(getter.info.resultType) else diff --git a/compiler/src/dotty/tools/dotc/transform/MixinOps.scala b/compiler/src/dotty/tools/dotc/transform/MixinOps.scala index 62338d744b5c..83cbe4755f3f 100644 --- a/compiler/src/dotty/tools/dotc/transform/MixinOps.scala +++ b/compiler/src/dotty/tools/dotc/transform/MixinOps.scala @@ -30,9 +30,9 @@ class MixinOps(cls: ClassSymbol, thisPhase: DenotTransformer)(implicit ctx: Cont def superRef(target: Symbol, span: Span = cls.span): Tree = { val sup = if (target.isConstructor && !target.owner.is(Trait)) - Super(This(cls), tpnme.EMPTY, true) + Super(ThisRef(cls), tpnme.EMPTY, true) else - Super(This(cls), target.owner.name.asTypeName, false, target.owner) + Super(ThisRef(cls), target.owner.name.asTypeName, false, target.owner) //println(i"super ref $target on $sup") ast.untpd.Select(sup.withSpan(span), target.name) .withType(NamedType(sup.tpe, target)) diff --git a/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala b/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala index c7293330d7e2..7df7d5375437 100644 --- a/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala +++ b/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala @@ -82,7 +82,7 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages( tree case tree: RefTree if tree.symbol.isAllOf(InlineParam) => tree - case _: This => + case _: ThisRef => assert(checkSymLevel(tree.symbol, tree.tpe, tree.sourcePos).isEmpty) tree case Ident(name) => diff --git a/compiler/src/dotty/tools/dotc/transform/ParamForwarding.scala b/compiler/src/dotty/tools/dotc/transform/ParamForwarding.scala index 794539d7fa1f..94aded89a860 100644 --- a/compiler/src/dotty/tools/dotc/transform/ParamForwarding.scala +++ b/compiler/src/dotty/tools/dotc/transform/ParamForwarding.scala @@ -68,7 +68,7 @@ class ParamForwarding(thisPhase: DenotTransformer) { sym.copySymDenotation(initFlags = sym.flags | Method | StableRealizable, info = sym.info.ensureMethodic) .installAfter(thisPhase) val superAcc = - Super(This(currentClass), tpnme.EMPTY, inConstrCall = false).select(alias) + Super(ThisRef(currentClass), tpnme.EMPTY, inConstrCall = false).select(alias) typr.println(i"adding param forwarder $superAcc") DefDef(sym, superAcc.ensureConforms(sym.info.widen)).withSpan(stat.span) } diff --git a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala index 94f611056b70..94f988136b1c 100644 --- a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala +++ b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala @@ -180,7 +180,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase try tree match { case tree: Ident if !tree.isType => tree.tpe match { - case tpe: ThisType => This(tpe.cls).withSpan(tree.span) + case tpe: ThisType => ThisRef(tpe.cls).withSpan(tree.span) case _ => tree } case tree @ Select(qual, name) => diff --git a/compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala b/compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala index f25f2e94843f..a41c191b8288 100644 --- a/compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala +++ b/compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala @@ -88,7 +88,7 @@ class SuperAccessors(thisPhase: DenotTransformer) { acc } - This(clazz).select(superAcc).withSpan(sel.span) + ThisRef(clazz).select(superAcc).withSpan(sel.span) } /** Check selection `super.f` for conforming to rules. If necessary, @@ -176,7 +176,7 @@ class SuperAccessors(thisPhase: DenotTransformer) { ProtectedAccessors.needsAccessorIfNotInSubclass(sym) && AccessProxies.hostForAccessorOf(sym).is(Trait) qual match { - case _: This if needsSuperAccessor => + case _: ThisRef if needsSuperAccessor => /* * A trait which extends a class and accesses a protected member * of that class cannot implement the necessary accessor method diff --git a/compiler/src/dotty/tools/dotc/transform/SyntheticMembers.scala b/compiler/src/dotty/tools/dotc/transform/SyntheticMembers.scala index ee1285281d1d..1ace60d39e75 100644 --- a/compiler/src/dotty/tools/dotc/transform/SyntheticMembers.scala +++ b/compiler/src/dotty/tools/dotc/transform/SyntheticMembers.scala @@ -112,7 +112,7 @@ class SyntheticMembers(thisPhase: DenotTransformer) { coord = clazz.coord).enteredAfter(thisPhase).asTerm def forwardToRuntime(vrefs: List[Tree]): Tree = - ref(defn.runtimeMethodRef("_" + sym.name.toString)).appliedToArgs(This(clazz) :: vrefs) + ref(defn.runtimeMethodRef("_" + sym.name.toString)).appliedToArgs(ThisRef(clazz) :: vrefs) def ownName: Tree = Literal(Constant(clazz.name.stripModuleClassSuffix.toString)) @@ -127,7 +127,7 @@ class SyntheticMembers(thisPhase: DenotTransformer) { case nme.productPrefix => ownName case nme.productElement => productElementBody(accessors.length, vrefss.head.head) case nme.productElementName => productElementNameBody(accessors.length, vrefss.head.head) - case nme.ordinal => Select(This(clazz), nme.ordinalDollar) + case nme.ordinal => Select(ThisRef(clazz), nme.ordinalDollar) } ctx.log(s"adding $synthetic to $clazz at ${ctx.phase}") synthesizeDef(synthetic, treess => ctx => syntheticRHS(treess)(ctx)) @@ -152,7 +152,7 @@ class SyntheticMembers(thisPhase: DenotTransformer) { def productElementBody(arity: Int, index: Tree)(implicit ctx: Context): Tree = { // case N => _${N + 1} val cases = 0.until(arity).map { i => - CaseDef(Literal(Constant(i)), EmptyTree, Select(This(clazz), nme.selectorName(i))) + CaseDef(Literal(Constant(i)), EmptyTree, Select(ThisRef(clazz), nme.selectorName(i))) } Match(index, (cases :+ generateIOBECase(index)).toList) @@ -227,7 +227,7 @@ class SyntheticMembers(thisPhase: DenotTransformer) { // compare primitive fields first, slow equality checks of non-primitive fields can be skipped when primitives differ val sortedAccessors = accessors.sortBy(accessor => if (accessor.info.typeSymbol.isPrimitiveValueClass) 0 else 1) val comparisons = sortedAccessors.map { accessor => - This(clazz).select(accessor).equal(ref(thatAsClazz).select(accessor)) } + ThisRef(clazz).select(accessor).equal(ref(thatAsClazz).select(accessor)) } val rhs = // this.x == this$0.x && this.y == x$0.y if (comparisons.isEmpty) Literal(Constant(true)) else comparisons.reduceLeft(_ and _) val matchingCase = CaseDef(pattern, EmptyTree, rhs) // case x$0 @ (_: C) => this.x == this$0.x && this.y == x$0.y @@ -235,7 +235,7 @@ class SyntheticMembers(thisPhase: DenotTransformer) { val matchExpr = Match(that, List(matchingCase, defaultCase)) if (isDerivedValueClass(clazz)) matchExpr else { - val eqCompare = This(clazz).select(defn.Object_eq).appliedTo(that.cast(defn.ObjectType)) + val eqCompare = ThisRef(clazz).select(defn.Object_eq).appliedTo(that.cast(defn.ObjectType)) eqCompare or matchExpr } } @@ -289,7 +289,7 @@ class SyntheticMembers(thisPhase: DenotTransformer) { else if (accessors.exists(_.info.finalResultType.classSymbol.isPrimitiveValueClass)) caseHashCodeBody else - ref(defn.ScalaRuntime__hashCode).appliedTo(This(clazz)) + ref(defn.ScalaRuntime__hashCode).appliedTo(ThisRef(clazz)) /** The class * @@ -313,7 +313,7 @@ class SyntheticMembers(thisPhase: DenotTransformer) { val acc = ctx.newSymbol(ctx.owner, nme.acc, Mutable | Synthetic, defn.IntType, coord = ctx.owner.span) val accDef = ValDef(acc, Literal(Constant(0xcafebabe))) val mixPrefix = Assign(ref(acc), - ref(defn.staticsMethod("mix")).appliedTo(ref(acc), This(clazz).select(defn.Product_productPrefix).select(defn.Any_hashCode).appliedToNone)) + ref(defn.staticsMethod("mix")).appliedTo(ref(acc), ThisRef(clazz).select(defn.Product_productPrefix).select(defn.Any_hashCode).appliedToNone)) val mixes = for (accessor <- accessors) yield Assign(ref(acc), ref(defn.staticsMethod("mix")).appliedTo(ref(acc), hashImpl(accessor))) val finish = ref(defn.staticsMethod("finalizeHash")).appliedTo(ref(acc), Literal(Constant(accessors.size))) diff --git a/compiler/src/dotty/tools/dotc/transform/TailRec.scala b/compiler/src/dotty/tools/dotc/transform/TailRec.scala index 6727ebe3d56d..02ba17496b74 100644 --- a/compiler/src/dotty/tools/dotc/transform/TailRec.scala +++ b/compiler/src/dotty/tools/dotc/transform/TailRec.scala @@ -151,7 +151,7 @@ class TailRec extends MiniPhase { (param, local) => ValDef(local.asTerm, ref(param)) } varForRewrittenThis match { - case Some(local) => ValDef(local.asTerm, This(enclosingClass)) :: initialParamVarDefs + case Some(local) => ValDef(local.asTerm, ThisRef(enclosingClass)) :: initialParamVarDefs case none => initialParamVarDefs } } @@ -163,7 +163,7 @@ class TailRec extends MiniPhase { typeMap = _.substThisUnlessStatic(enclosingClass, thisRef) .subst(rewrittenParamSyms, varsForRewrittenParamSyms.map(_.termRef)), treeMap = { - case tree: This if tree.symbol == enclosingClass => Ident(thisRef) + case tree: ThisRef if tree.symbol == enclosingClass => Ident(thisRef) case tree => tree } ).transform(rhsSemiTransformed) @@ -404,7 +404,7 @@ class TailRec extends MiniPhase { if (isMandatory) noTailTransform(tree.rhs) tree - case _: Super | _: This | _: Literal | _: TypeTree | _: TypeDef | EmptyTree => + case _: Super | _: ThisRef | _: Literal | _: TypeTree | _: TypeDef | EmptyTree => tree case Labeled(bind, expr) => diff --git a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala index f42011a3e261..fddaa4f2f6c5 100644 --- a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala +++ b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala @@ -233,7 +233,7 @@ class TreeChecker extends Phase with SymTransformer { case Apply(fun, args) => assertIdentNotJavaClass(fun) args.foreach(assertIdentNotJavaClass _) - // case tree: untpd.This => + // case tree: untpd.ThisRef => // case tree: untpd.Literal => // case tree: untpd.New => case Typed(expr, _) => @@ -374,7 +374,7 @@ class TreeChecker extends Phase with SymTransformer { checkNotRepeated(super.typedSelect(tree, pt)) } - override def typedThis(tree: untpd.This)(implicit ctx: Context): Tree = { + override def typedThis(tree: untpd.ThisRef)(implicit ctx: Context): Tree = { val res = super.typedThis(tree) val cls = res.symbol assert(cls.isStaticOwner || ctx.owner.isContainedIn(cls), i"error while typing $tree, ${ctx.owner} is not contained in $cls") diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index e86cd9f172bf..cbd8ea5c094a 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -343,7 +343,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic { Typ(erase(expr.tpe.stripAnnots), true) case Typed(pat, _) => project(pat) - case This(_) => + case ThisRef(_) => Typ(pat.tpe.stripAnnots, false) case EmptyTree => // default rethrow clause of try/catch, check tests/patmat/try2.scala Typ(WildcardType, false) diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 9d63c2a0da98..38e9a4d06f30 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -327,12 +327,12 @@ object Checking { case tree: MemberDef => foldOver(x, tree) seen += tree.symbol - case tree @ Select(This(_), _) => + case tree @ Select(ThisRef(_), _) => checkRef(tree, tree.symbol) case tree: RefTree => checkRef(tree, tree.symbol) foldOver(x, tree) - case tree: This => + case tree: ThisRef => selfRef(tree) case tree: TypeTree => val checkType = new TypeAccumulator[Unit] { @@ -1027,8 +1027,8 @@ trait Checking { } val sym = t.symbol t match { - case Ident(_) | Select(This(_), _) => check(sym.maybeOwner, sym) - case This(_) => check(sym, sym) + case Ident(_) | Select(ThisRef(_), _) => check(sym.maybeOwner, sym) + case ThisRef(_) => check(sym, sym) case _ => traverseChildren(t) } } diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index 64af560f8847..f32971856a3b 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -166,7 +166,7 @@ object Inliner { tpd.seq(transformSub(tree.bindings), transform(tree.expansion)(inlineContext(tree.call)))(ctx.withSource(curSource)) : Tree case tree: Ident => finalize(tree, untpd.Ident(tree.name)(curSource)) case tree: Literal => finalize(tree, untpd.Literal(tree.const)(curSource)) - case tree: This => finalize(tree, untpd.This(tree.qual)(curSource)) + case tree: ThisRef => finalize(tree, untpd.ThisRef(tree.qual)(curSource)) case tree: JavaSeqLiteral => finalize(tree, untpd.JavaSeqLiteral(transform(tree.elems), transform(tree.elemtpt))(curSource)) case tree: SeqLiteral => finalize(tree, untpd.SeqLiteral(transform(tree.elems), transform(tree.elemtpt))(curSource)) case tree: TypeTree => tpd.TypeTree(tree.tpe)(ctx.withSource(curSource)).withSpan(tree.span) @@ -238,7 +238,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) { private val (methPart, callTypeArgs, callValueArgss) = decomposeCall(call) private val inlinedMethod = methPart.symbol private val inlineCallPrefix = - qualifier(methPart).orElse(This(inlinedMethod.enclosingClass.asClass)) + qualifier(methPart).orElse(ThisRef(inlinedMethod.enclosingClass.asClass)) inlining.println(i"-----------------------\nInlining $call\nWith RHS $rhsToInline") @@ -410,7 +410,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) { /** Register type of leaf node */ private def registerLeaf(tree: Tree): Unit = tree match { - case _: This | _: Ident | _: TypeTree => + case _: ThisRef | _: Ident | _: TypeTree => tree.typeOpt.foreachPart(registerType, stopAtStatic = true) case _ => } @@ -481,7 +481,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) { override def mapClassInfo(tp: ClassInfo) = mapFullClassInfo(tp) }, treeMap = { - case tree: This => + case tree: ThisRef => tree.tpe match { case thistpe: ThisType => thisProxy.get(thistpe.cls) match { diff --git a/compiler/src/dotty/tools/dotc/typer/ReTyper.scala b/compiler/src/dotty/tools/dotc/typer/ReTyper.scala index ff7459e3242f..0e352e7bae0f 100644 --- a/compiler/src/dotty/tools/dotc/typer/ReTyper.scala +++ b/compiler/src/dotty/tools/dotc/typer/ReTyper.scala @@ -45,7 +45,7 @@ class ReTyper extends Typer with ReChecking { override def typedLiteral(tree: untpd.Literal)(implicit ctc: Context): Tree = promote(tree) - override def typedThis(tree: untpd.This)(implicit ctx: Context): Tree = + override def typedThis(tree: untpd.ThisRef)(implicit ctx: Context): Tree = promote(tree) override def typedSuper(tree: untpd.Super, pt: Type)(implicit ctx: Context): Tree = diff --git a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala index f69334742a9b..e02d06b0a8fa 100644 --- a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala +++ b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala @@ -344,7 +344,7 @@ trait TypeAssigner { } } - def assignType(tree: untpd.This)(implicit ctx: Context): This = { + def assignType(tree: untpd.ThisRef)(implicit ctx: Context): ThisRef = { val cls = qualifyingClass(tree, tree.qual.name, packageOK = false) tree.withType( if (cls.isClass) cls.thisType diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 66845e343f7f..5f39de845509 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -478,7 +478,7 @@ class Typer extends Namer typeSelectOnTerm(ctx) } - def typedThis(tree: untpd.This)(implicit ctx: Context): Tree = { + def typedThis(tree: untpd.ThisRef)(implicit ctx: Context): Tree = { record("typedThis") assignType(tree) } @@ -2059,7 +2059,7 @@ class Typer extends Namer def typedUnnamed(tree: untpd.Tree): Tree = tree match { case tree: untpd.Apply => if (ctx.mode is Mode.Pattern) typedUnApply(tree, pt) else typedApply(tree, pt) - case tree: untpd.This => typedThis(tree) + case tree: untpd.ThisRef => typedThis(tree) case tree: untpd.Number => typedNumber(tree, pt) case tree: untpd.Literal => typedLiteral(tree) case tree: untpd.New => typedNew(tree, pt) diff --git a/compiler/src/dotty/tools/dotc/util/WeakHashSet.scala b/compiler/src/dotty/tools/dotc/util/WeakHashSet.scala index a5d40c99421d..7d74c0dbb05c 100644 --- a/compiler/src/dotty/tools/dotc/util/WeakHashSet.scala +++ b/compiler/src/dotty/tools/dotc/util/WeakHashSet.scala @@ -23,7 +23,7 @@ final class WeakHashSet[A <: AnyRef](initialCapacity: Int, loadFactor: Double) e def this() = this(initialCapacity = WeakHashSet.defaultInitialCapacity, loadFactor = WeakHashSet.defaultLoadFactor) - type This = WeakHashSet[A] + type ThisType = WeakHashSet[A] /** * queue of Entries that hold elements scheduled for GC @@ -252,7 +252,7 @@ final class WeakHashSet[A <: AnyRef](initialCapacity: Int, loadFactor: Double) e } // true if this set is empty - override def empty: This = new WeakHashSet[A](initialCapacity, loadFactor) + override def empty: ThisType = new WeakHashSet[A](initialCapacity, loadFactor) // the number of elements in this set override def size: Int = { diff --git a/compiler/test/dotty/tools/dotc/parsing/parsePackage.scala b/compiler/test/dotty/tools/dotc/parsing/parsePackage.scala index c58cc673ccee..682be4071a56 100644 --- a/compiler/test/dotty/tools/dotc/parsing/parsePackage.scala +++ b/compiler/test/dotty/tools/dotc/parsing/parsePackage.scala @@ -19,8 +19,8 @@ object parsePackage extends ParserTest { tree match { case Ident(name) => Ident(name) - case This(name) => - This(name) + case ThisRef(name) => + ThisRef(name) case TypedSplice(t) => TypedSplice(t) case SymbolLit(str) => diff --git a/library/src/scala/internal/quoted/Matcher.scala b/library/src/scala/internal/quoted/Matcher.scala index d3c8ce7c2c14..94d7a277fc25 100644 --- a/library/src/scala/internal/quoted/Matcher.scala +++ b/library/src/scala/internal/quoted/Matcher.scala @@ -200,7 +200,7 @@ private[quoted] object Matcher { case (New(tpt1), New(tpt2)) => tpt1 =?= tpt2 - case (This(_), This(_)) if scrutinee.symbol == pattern.symbol => + case (ThisRef(_), ThisRef(_)) if scrutinee.symbol == pattern.symbol => matched case (Super(qual1, mix1), Super(qual2, mix2)) if mix1 == mix2 => diff --git a/library/src/scala/tasty/reflect/CompilerInterface.scala b/library/src/scala/tasty/reflect/CompilerInterface.scala index c91fdcc3e20a..bbd031b85f73 100644 --- a/library/src/scala/tasty/reflect/CompilerInterface.scala +++ b/library/src/scala/tasty/reflect/CompilerInterface.scala @@ -20,7 +20,7 @@ import scala.runtime.quoted.Unpickler * | | +- Select * | | * | +- Literal - * | +- This + * | +- ThisRef * | +- New * | +- NamedArg * | +- Apply @@ -333,14 +333,14 @@ trait CompilerInterface { def Literal_copy(original: Tree)(constant: Constant)(given ctx: Context): Literal /** Tree representing `this` in the source code */ - type This <: Term + type ThisRef <: Term - def matchThis(tree: Tree)(given ctx: Context): Option[This] + def matchThis(tree: Tree)(given ctx: Context): Option[ThisRef] - def This_id(self: This)(given ctx: Context): Option[Id] + def This_id(self: ThisRef)(given ctx: Context): Option[Id] - def This_apply(cls: Symbol)(given ctx: Context): This - def This_copy(original: Tree)(qual: Option[Id])(given ctx: Context): This + def This_apply(cls: Symbol)(given ctx: Context): ThisRef + def This_copy(original: Tree)(qual: Option[Id])(given ctx: Context): ThisRef /** Tree representing `new` in the source code */ type New <: Term diff --git a/library/src/scala/tasty/reflect/Core.scala b/library/src/scala/tasty/reflect/Core.scala index b6c5717db2c9..c27fa148c767 100644 --- a/library/src/scala/tasty/reflect/Core.scala +++ b/library/src/scala/tasty/reflect/Core.scala @@ -161,7 +161,7 @@ trait Core { type Literal = internal.Literal /** Tree representing `this` in the source code */ - type This = internal.This + type ThisRef = internal.ThisRef /** Tree representing `new` in the source code */ type New = internal.New diff --git a/library/src/scala/tasty/reflect/Printers.scala b/library/src/scala/tasty/reflect/Printers.scala index 760e90779710..7f962542d225 100644 --- a/library/src/scala/tasty/reflect/Printers.scala +++ b/library/src/scala/tasty/reflect/Printers.scala @@ -160,8 +160,8 @@ trait Printers this += "Ident(\"" += name += "\")" case Select(qualifier, name) => this += "Select(" += qualifier += ", \"" += name += "\")" - case This(qual) => - this += "This(" += qual += ")" + case ThisRef(qual) => + this += "ThisRef(" += qual += ")" case Super(qual, mix) => this += "Super(" += qual += ", " += mix += ")" case Apply(fun, args) => @@ -746,7 +746,7 @@ trait Printers case Literal(const) => printConstant(const) - case This(id) => + case ThisRef(id) => id match { case Some(x) => this += x.name.stripSuffix("$") += "." @@ -793,7 +793,7 @@ trait Printers case Apply(fn, args) => fn match { - case Select(This(_), "") => this += "this" // call to constructor inside a constructor + case Select(ThisRef(_), "") => this += "this" // call to constructor inside a constructor case Select(qual, "apply") if qual.tpe.isImplicitFunctionType => printTree(qual) += " given " case _ => printQualTree(fn) @@ -817,8 +817,8 @@ trait Printers case Super(qual, idOpt) => qual match { - case This(Some(Id(name))) => this += name += "." - case This(None) => + case ThisRef(Some(Id(name))) => this += name += "." + case ThisRef(None) => } this += "super" for (id <- idOpt) diff --git a/library/src/scala/tasty/reflect/TreeOps.scala b/library/src/scala/tasty/reflect/TreeOps.scala index 52ea20496372..533d218ce329 100644 --- a/library/src/scala/tasty/reflect/TreeOps.scala +++ b/library/src/scala/tasty/reflect/TreeOps.scala @@ -324,18 +324,18 @@ trait TreeOps extends Core { } object IsThis { - /** Matches any This and returns it */ - def unapply(tree: Tree)(given ctx: Context): Option[This] = internal.matchThis(tree) + /** Matches any ThisRef and returns it */ + def unapply(tree: Tree)(given ctx: Context): Option[ThisRef] = internal.matchThis(tree) } /** Scala `this` or `this[id]` */ - object This { + object ThisRef { /** Create a `this[` */ - def apply(cls: Symbol)(given ctx: Context): This = + def apply(cls: Symbol)(given ctx: Context): ThisRef = internal.This_apply(cls) - def copy(original: Tree)(qual: Option[Id])(given ctx: Context): This = + def copy(original: Tree)(qual: Option[Id])(given ctx: Context): ThisRef = internal.This_copy(original)(qual) /** Matches `this[` */ @@ -344,7 +344,7 @@ trait TreeOps extends Core { } - implicit class ThisAPI(self: This) { + implicit class ThisAPI(self: ThisRef) { def id(given ctx: Context): Option[Id] = internal.This_id(self) } diff --git a/tests/disabled/partest/run/existentials-in-compiler.check b/tests/disabled/partest/run/existentials-in-compiler.check index b0d852865d6f..f7ebde79f047 100644 --- a/tests/disabled/partest/run/existentials-in-compiler.check +++ b/tests/disabled/partest/run/existentials-in-compiler.check @@ -4,8 +4,8 @@ abstract trait Bippy[A <: AnyRef, B] extends AnyRef abstract trait BippyBud[A <: AnyRef, B, C <: List[A]] extends AnyRef extest.BippyBud[A,B,C] forSome { A <: AnyRef; B; C <: List[A] } -abstract trait BippyLike[A <: AnyRef, B <: List[A], This <: extest.BippyLike[A,B,This] with extest.Bippy[A,B]] extends AnyRef - extest.BippyLike[A,B,This] forSome { A <: AnyRef; B <: List[A]; This <: extest.BippyLike[A,B,This] with extest.Bippy[A,B] } +abstract trait BippyLike[A <: AnyRef, B <: List[A], Self <: extest.BippyLike[A,B,Self] with extest.Bippy[A,B]] extends AnyRef + extest.BippyLike[A,B,Self] forSome { A <: AnyRef; B <: List[A]; Self <: extest.BippyLike[A,B,Self] with extest.Bippy[A,B] } abstract trait Contra[-A >: AnyRef, -B] extends AnyRef extest.Contra[AnyRef, _] @@ -151,6 +151,6 @@ abstract trait Cov49[-A >: Null, -B] extends AnyRef abstract trait Covariant[+A <: AnyRef, +B] extends AnyRef extest.Covariant[AnyRef,Any] -abstract trait CovariantLike[+A <: AnyRef, +B <: List[A], +This <: extest.CovariantLike[A,B,This] with extest.Covariant[A,B]] extends AnyRef - extest.CovariantLike[A,B,This] forSome { +A <: AnyRef; +B <: List[A]; +This <: extest.CovariantLike[A,B,This] with extest.Covariant[A,B] } +abstract trait CovariantLike[+A <: AnyRef, +B <: List[A], +Self <: extest.CovariantLike[A,B,Self] with extest.Covariant[A,B]] extends AnyRef + extest.CovariantLike[A,B,Self] forSome { +A <: AnyRef; +B <: List[A]; +Self <: extest.CovariantLike[A,B,Self] with extest.Covariant[A,B] } diff --git a/tests/disabled/partest/run/existentials-in-compiler.scala b/tests/disabled/partest/run/existentials-in-compiler.scala index dfc7048b313f..f078dd8dca19 100644 --- a/tests/disabled/partest/run/existentials-in-compiler.scala +++ b/tests/disabled/partest/run/existentials-in-compiler.scala @@ -13,7 +13,7 @@ object Test extends CompilerTest { override def code = """ package extest { trait Bippy[A <: AnyRef, B] { } // wildcards - trait BippyLike[A <: AnyRef, B <: List[A], This <: BippyLike[A, B, This] with Bippy[A, B]] // no wildcards + trait BippyLike[A <: AnyRef, B <: List[A], Self <: BippyLike[A, B, Self] with Bippy[A, B]] // no wildcards trait BippyBud[A <: AnyRef, B, C <: List[A]] trait Cov01[+A <: AnyRef, +B] { } @@ -67,7 +67,7 @@ package extest { trait Cov49[-A >: Null, -B] { } trait Covariant[+A <: AnyRef, +B] { } - trait CovariantLike[+A <: AnyRef, +B <: List[A], +This <: CovariantLike[A, B, This] with Covariant[A, B]] + trait CovariantLike[+A <: AnyRef, +B <: List[A], +Self <: CovariantLike[A, B, Self] with Covariant[A, B]] trait Contra[-A >: AnyRef, -B] { } trait ContraLike[-A >: AnyRef, -B >: List[A]] diff --git a/tests/invalid/pos/IterableSelfRec.scala b/tests/invalid/pos/IterableSelfRec.scala index 7fd235f1211d..f5d33a295f75 100644 --- a/tests/invalid/pos/IterableSelfRec.scala +++ b/tests/invalid/pos/IterableSelfRec.scala @@ -5,27 +5,27 @@ package immutable import annotation.unchecked.uncheckedVariance trait Collection[T] { self => - type This <: Collection { type This <: self.This } - def companion: CollectionCompanion[This] + type ThisCollection <: Collection { type ThisCollection <: self.ThisCollection } + def companion: CollectionCompanion[ThisCollection] } trait Iterable[T] extends Collection[T] { self => - type This <: Iterable { type This <: self.This } - override def companion: IterableCompanion[This] = Iterable.asInstanceOf + type ThisCollection <: Iterable { type ThisCollection <: self.ThisCollection } + override def companion: IterableCompanion[ThisCollection] = Iterable.asInstanceOf def iterator: Iterator[T] } trait Seq[T] extends Iterable[T] { self => - type This <: Seq { type This <: self.This } - override def companion: IterableCompanion[This] = Seq.asInstanceOf + type ThisCollection <: Seq { type ThisCollection <: self.ThisCollection } + override def companion: IterableCompanion[ThisCollection] = Seq.asInstanceOf def apply(x: Int): T } -abstract class CollectionCompanion[+CC[X] <: Collection[X] { type This <: CC }] +abstract class CollectionCompanion[+CC[X] <: Collection[X] { type ThisCollection <: CC }] -abstract class IterableCompanion[+CC[X] <: Iterable[X] { type This <: CC }] extends CollectionCompanion[CC] { +abstract class IterableCompanion[+CC[X] <: Iterable[X] { type ThisCollection <: CC }] extends CollectionCompanion[CC] { def fromIterator[T](it: Iterator[T]): CC[T] def map[T, U](xs: Iterable[T], f: T => U): CC[U] = fromIterator(xs.iterator.map(f)) @@ -37,7 +37,7 @@ abstract class IterableCompanion[+CC[X] <: Iterable[X] { type This <: CC }] exte implicit def transformOps[T](xs: CC[T] @uncheckedVariance): TransformOps[CC, T] = ??? // new TransformOps[CC, T](xs) } -class TransformOps[+CC[X] <: Iterable[X] { type This <: CC }, T] (val xs: CC[T]) extends AnyVal { +class TransformOps[+CC[X] <: Iterable[X] { type ThisCollection <: CC }, T] (val xs: CC[T]) extends AnyVal { def companion[T](xs: CC[T] @uncheckedVariance): IterableCompanion[CC] = xs.companion def map[U](f: T => U): CC[U] = companion(xs).map(xs, f) def filter(p: T => Boolean): CC[T] = companion(xs).filter(xs, p) diff --git a/tests/neg/typeclass-encoding2.scala b/tests/neg/typeclass-encoding2.scala index d0fd4534e586..d04387eea45c 100644 --- a/tests/neg/typeclass-encoding2.scala +++ b/tests/neg/typeclass-encoding2.scala @@ -6,21 +6,21 @@ object runtime1 { trait TypeClass1[A] { val common: TypeClassCommon1 - type This[X] = common.This[X] + type ThisClass[X] = common.ThisClass[X] } trait TypeClassCommon1 { self => - type This[X] + type ThisClass[X] type Instance[X] <: TypeClass1[X] - def inject[A](x: This[A]): Instance[A]// { val common: self.type } + def inject[A](x: ThisClass[A]): Instance[A]// { val common: self.type } } trait Extension1[From[_], To[X] <: TypeClass1[X]] extends TypeClassCommon1 { - type This[X] = From[X] + type ThisClass[X] = From[X] type Instance[X] = To[X] } implicit def inject[A, From[_]](x: From[A]) - (implicit ev: Extension1[From, _]): ev.Instance[A] { type This[X] = From[X] } = - ev.inject(x) // error: found: ev.To[A], required: ev.To[A]{This = From} + (implicit ev: Extension1[From, _]): ev.Instance[A] { type ThisClass[X] = From[X] } = + ev.inject(x) // error: found: ev.To[A], required: ev.To[A]{ThisClass = From} } \ No newline at end of file diff --git a/tests/pending/pos/depmet_implicit_oopsla_session.scala b/tests/pending/pos/depmet_implicit_oopsla_session.scala index a9c8e56ce3d9..1f85aeec0f5b 100644 --- a/tests/pending/pos/depmet_implicit_oopsla_session.scala +++ b/tests/pending/pos/depmet_implicit_oopsla_session.scala @@ -1,8 +1,8 @@ object Sessions { - trait Session[This] { + trait Session[Self] { type Dual - type HasDual[D] = Session[This]{type Dual=D} - def run(p: This, dp: Dual): Unit + type HasDual[D] = Session[Self]{type Dual=D} + def run(p: Self, dp: Dual): Unit } implicit object StopSession extends Session[Stop] { diff --git a/tests/pos-with-compiler/tasty/definitions.scala b/tests/pos-with-compiler/tasty/definitions.scala index 0bc5f5c44b4c..bf3355bb2824 100644 --- a/tests/pos-with-compiler/tasty/definitions.scala +++ b/tests/pos-with-compiler/tasty/definitions.scala @@ -68,7 +68,7 @@ object definitions { case Ident(name: String, override val tpe: Type) case Select(prefix: Term, name: String, signature: Option[Signature]) case Literal(value: Constant) - case This(id: Option[Id]) + case Self(id: Option[Id]) case New(tpt: TypeTree) case Throw(expr: Term) case NamedArg(name: String, arg: Term) @@ -163,8 +163,8 @@ object definitions { } } - abstract class LambdaType[ParamInfo, This <: LambdaType[ParamInfo, This]]( - val companion: LambdaTypeCompanion[ParamInfo, This] + abstract class LambdaType[ParamInfo, Self <: LambdaType[ParamInfo, Self]]( + val companion: LambdaTypeCompanion[ParamInfo, Self] ) extends Type { private[Type] var _pinfos: List[ParamInfo] private[Type] var _restpe: Type @@ -174,10 +174,10 @@ object definitions { def resultType: Type = _restpe } - abstract class LambdaTypeCompanion[ParamInfo, This <: LambdaType[ParamInfo, This]] { - def apply(pnames: List[String], ptypes: List[ParamInfo], restpe: Type): This + abstract class LambdaTypeCompanion[ParamInfo, Self <: LambdaType[ParamInfo, Self]] { + def apply(pnames: List[String], ptypes: List[ParamInfo], restpe: Type): Self - def apply(pnames: List[String], ptypesExp: This => List[ParamInfo], restpeExp: This => Type): This = { + def apply(pnames: List[String], ptypesExp: Self => List[ParamInfo], restpeExp: Self => Type): Self = { val lambda = apply(pnames, Nil, PlaceHolder) lambda._pinfos = ptypesExp(lambda) lambda._restpe = restpeExp(lambda) diff --git a/tests/pos/extmethods-2.scala b/tests/pos/extmethods-2.scala index af1882f7a26d..246f102d8f41 100644 --- a/tests/pos/extmethods-2.scala +++ b/tests/pos/extmethods-2.scala @@ -1,7 +1,7 @@ package extMethods trait That1[A] -class T[A, This <: That1[A]](val x: Int) extends AnyVal { - self: This => - final def loop(x: This, cnt: Int): Int = loop(x, cnt + 1) +class T[A, Self <: That1[A]](val x: Int) extends AnyVal { + self: Self => + final def loop(x: Self, cnt: Int): Int = loop(x, cnt + 1) } diff --git a/tests/pos/extmethods.scala b/tests/pos/extmethods.scala index fe95a1c79b04..6a8dd34b60ac 100644 --- a/tests/pos/extmethods.scala +++ b/tests/pos/extmethods.scala @@ -1,7 +1,7 @@ trait That1[A] -class T[A, This <: That1[A]](val x: Int) extends AnyVal { - self: This => - final def loop(x: This, cnt: Int): Int = loop(x, cnt + 1) +class T[A, Self <: That1[A]](val x: Int) extends AnyVal { + self: Self => + final def loop(x: Self, cnt: Int): Int = loop(x, cnt + 1) def const[B](): Boolean = return true } diff --git a/tests/pos/i1401.scala b/tests/pos/i1401.scala index 03dd684fe421..5a22f41a22e7 100644 --- a/tests/pos/i1401.scala +++ b/tests/pos/i1401.scala @@ -4,19 +4,19 @@ trait Subtractable[AS, +Repr <: Subtractable[AS, Repr]] { def -(elem: AS): Repr } -trait BufferLike[BA, +This <: BufferLike[BA, This] with Buffer[BA]] - extends Subtractable[BA, This] -{ self : This => +trait BufferLike[BA, +Self <: BufferLike[BA, Self] with Buffer[BA]] + extends Subtractable[BA, Self] +{ self : Self => /* Without fix-#1401: * - error: overriding method - in trait Subtractable of type (elem: A)This & i1401.Buffer[A]; - method - of type (elem: BA)This has incompatible type - def -(elem: BA): This + error: overriding method - in trait Subtractable of type (elem: A)Self & i1401.Buffer[A]; + method - of type (elem: BA)Self has incompatible type + def -(elem: BA): Self ^ one error found */ - def -(elem: BA): This + def -(elem: BA): Self } trait Buffer[A] extends BufferLike[A, Buffer[A]] diff --git a/tests/pos/i4884.scala b/tests/pos/i4884.scala index cb1f8bd6f3b6..85daf45d40cd 100644 --- a/tests/pos/i4884.scala +++ b/tests/pos/i4884.scala @@ -14,7 +14,7 @@ object Test { } trait TestConstructor4[D] { trait TestConstructor5[E] { - trait MSetLike[X <: D & E, This <: MSet[X] with MSetLike[X, This]] + trait MSetLike[X <: D & E, Self <: MSet[X] with MSetLike[X, Self]] trait MSet[X <: D & E] extends MSetLike[X, MSet[X]] } } diff --git a/tests/pos/pets.scala b/tests/pos/pets.scala index e1d5df44e3ff..8c32321bdfc4 100644 --- a/tests/pos/pets.scala +++ b/tests/pos/pets.scala @@ -1,21 +1,21 @@ // Representing the current type trait Pet { - type This <: Pet + type ThisPet <: Pet def name: String - def renamed(newName: String): This + def renamed(newName: String): ThisPet } case class Fish(name: String, age: Int) extends Pet { - type This = Fish + type ThisPet = Fish def renamed(newName: String): Fish = copy(name = newName) } case class Kitty(name: String, age: Int) extends Pet { - type This = Kitty + type ThisPet = Kitty def renamed(newName: String): Kitty = copy(name = newName) } object Test { - def esquire[A <: Pet](a: A): a.This = a.renamed(a.name + ", Esq.") + def esquire[A <: Pet](a: A): a.ThisPet = a.renamed(a.name + ", Esq.") val f: Fish = esquire(new Fish("bob", 22)) } diff --git a/tests/pos/spec-partialmap.scala b/tests/pos/spec-partialmap.scala index f2001dc85ea8..bf53487e9a7b 100644 --- a/tests/pos/spec-partialmap.scala +++ b/tests/pos/spec-partialmap.scala @@ -8,5 +8,5 @@ trait PartialMap[@specialized A,@specialized B] extends PartialFunction[A,B] wit for ((k,v) <- iterator; if f(k)) yield v // if this is commented, it compiles fine: - def apply[This <: Iterable[A]](keys : IterableOps[A, Iterable, This]): Iterable[B] = keys.map(apply) + def apply[Self <: Iterable[A]](keys : IterableOps[A, Iterable, Self]): Iterable[B] = keys.map(apply) } diff --git a/tests/pos/t0039.scala b/tests/pos/t0039.scala index 7b51320e21ab..b83cd3045d80 100644 --- a/tests/pos/t0039.scala +++ b/tests/pos/t0039.scala @@ -1,5 +1,5 @@ -abstract class Extensible[A, This <: Extensible[A, This]](x: A, xs: This) { self: This => - def mkObj(x: A, xs: This): This; +abstract class Extensible[A, Self <: Extensible[A, Self]](x: A, xs: Self) { self: Self => + def mkObj(x: A, xs: Self): Self; } class Fixed[A](x: A, xs: Fixed[A]) extends Extensible[A, Fixed[A]](x, xs) { def mkObj(x: A, xs: Fixed[A]) = new Fixed(x, xs); diff --git a/tests/pos/t2399.scala b/tests/pos/t2399.scala index a99998a0a959..f05b274980b7 100644 --- a/tests/pos/t2399.scala +++ b/tests/pos/t2399.scala @@ -1,14 +1,14 @@ trait That1[A] trait That2[A, R <: That2[A, R]] -trait T[A, This >: Null <: That1[A] with T[A, This]] extends That2[A, This] { - self: This => +trait T[A, Self >: Null <: That1[A] with T[A, Self]] extends That2[A, Self] { + self: Self => - private var next: This = _ + private var next: Self = _ def isEmpty = next eq null def length: Int = { - def loop(x: This, cnt: Int): Int = if (x.isEmpty) cnt else loop(x.next, cnt + 1) + def loop(x: Self, cnt: Int): Int = if (x.isEmpty) cnt else loop(x.next, cnt + 1) loop(self, 0) } } diff --git a/tests/pos/t4243.scala b/tests/pos/t4243.scala index e6c66faff09c..0d272208cc60 100644 --- a/tests/pos/t4243.scala +++ b/tests/pos/t4243.scala @@ -4,13 +4,13 @@ object wrap { - trait DomainLike[@specialized(Int) A, +This <: Domain[A]] + trait DomainLike[@specialized(Int) A, +Self <: Domain[A]] trait Domain[@specialized(Int) B] extends DomainLike[B, Domain[B]] - trait IterableDomainLike[@specialized(Int) C, +This <: IterableDomain[C]] - extends DomainLike[C, This] + trait IterableDomainLike[@specialized(Int) C, +Self <: IterableDomain[C]] + extends DomainLike[C, Self] trait IterableDomain[@specialized(Int) D] extends Domain[D] with IterableDomainLike[D, IterableDomain[D]] diff --git a/tests/pos/typeclass-encoding.scala b/tests/pos/typeclass-encoding.scala index 52ad8126dd8e..b3eabf4ea15e 100644 --- a/tests/pos/typeclass-encoding.scala +++ b/tests/pos/typeclass-encoding.scala @@ -25,14 +25,14 @@ object runtime { trait TypeClass { - type This - type StaticPart[This] + type ThisClass + type StaticPart[ThisClass] } trait Implementation[From] { - type This = From + type ThisClass = From type Implemented <: TypeClass - def inject(x: From): Implemented { type This = From } + def inject(x: From): Implemented { type ThisClass = From } } class CompanionOf[T] { type StaticPart[_] } @@ -43,7 +43,7 @@ object runtime { ev1.asInstanceOf // can we avoid the cast? implicit def inject[From](x: From)( - implicit ev1: Implementation[From]): ev1.Implemented { type This = From } = + implicit ev1: Implementation[From]): ev1.Implemented { type ThisClass = From } = ev1.inject(x) } @@ -51,13 +51,13 @@ object semiGroups { import runtime._ trait SemiGroup extends TypeClass { - def add(that: This): This + def add(that: ThisClass): ThisClass } trait Monoid extends SemiGroup { - type StaticPart[This] <: MonoidStatic[This] + type StaticPart[ThisClass] <: MonoidStatic[ThisClass] } - abstract class MonoidStatic[This] { def unit: This } + abstract class MonoidStatic[ThisClass] { def unit: ThisClass } implicit def companionOfMonoid: CompanionOf[Monoid] { type StaticPart[X] = MonoidStatic[X] @@ -69,18 +69,18 @@ object semiGroups { type Implemented = Monoid def unit: Int = 0 def inject($this: Int) = new Monoid { - type This = Int - def add(that: This): This = $this + that + type ThisClass = Int + def add(that: ThisClass): ThisClass = $this + that } } implicit object extend_String_Monoid extends MonoidStatic[String], Implementation[String] { type Implemented = Monoid def unit = "" - def inject($this: String): Monoid { type This = String } = + def inject($this: String): Monoid { type ThisClass = String } = new Monoid { - type This = String - def add(that: This): This = $this ++ that + type ThisClass = String + def add(that: ThisClass): ThisClass = $this ++ that } } diff --git a/tests/pos/typeclass-encoding2.scala b/tests/pos/typeclass-encoding2.scala index 18559b784754..379bcf2123c6 100644 --- a/tests/pos/typeclass-encoding2.scala +++ b/tests/pos/typeclass-encoding2.scala @@ -1,12 +1,12 @@ /** 1. Simple type classes with monomorphic implementations and direct extensions. trait SemiGroup extends TypeClass { - def add(that: This): This + def add(that: ThisClass): ThisClass } trait Monoid extends SemiGroup common { - def unit: This + def unit: ThisClass } extension IntOps for Int : Monoid { @@ -43,22 +43,22 @@ object runtime { trait TypeClass { val commons: TypeClassCommon - type This = commons.This + type ThisClass = commons.ThisClass } trait TypeClassCommon { self => - type This + type ThisClass type Instance <: TypeClass - def inject(x: This): Instance { val commons: self.type } + def inject(x: ThisClass): Instance { val commons: self.type } } trait TypeClassCompanion { - type Impl[T] <: TypeClassCommon { type This = T } + type Impl[T] <: TypeClassCommon { type ThisClass = T } def impl[T](implicit ev: Impl[T]): Impl[T] = ev } implicit def inject[From](x: From) - (implicit ev: TypeClassCommon { type This = From }): ev.Instance { type This = From } = + (implicit ev: TypeClassCommon { type ThisClass = From }): ev.Instance { type ThisClass = From } = ev.inject(x) } import runtime._ @@ -68,13 +68,13 @@ object semiGroups { trait SemiGroup extends TypeClass { val commons: SemiGroupCommon import commons._ - def add(that: This): This + def add(that: ThisClass): ThisClass } trait SemiGroupCommon extends TypeClassCommon { type Instance <: SemiGroup } object SemiGroup extends TypeClassCompanion { - type Impl[T] = SemiGroupCommon { type This = T } + type Impl[T] = SemiGroupCommon { type ThisClass = T } } trait Monoid extends SemiGroup { @@ -83,29 +83,29 @@ object semiGroups { } trait MonoidCommon extends SemiGroupCommon { type Instance <: Monoid - def unit: This + def unit: ThisClass } object Monoid extends TypeClassCompanion { - type Impl[T] = MonoidCommon { type This = T } + type Impl[T] = MonoidCommon { type ThisClass = T } } implicit object IntOps extends MonoidCommon { - type This = Int + type ThisClass = Int type Instance = Monoid def unit: Int = 0 def inject($this: Int) = new Monoid { val commons: IntOps.this.type = IntOps.this - def add(that: This): This = $this + that + def add(that: ThisClass): ThisClass = $this + that } } implicit object StringOps extends MonoidCommon { - type This = String + type ThisClass = String type Instance = Monoid def unit = "" def inject($this: String) = new Monoid { val commons: StringOps.this.type = StringOps.this - def add(that: This): This = $this.concat(that) + def add(that: ThisClass): ThisClass = $this.concat(that) } } @@ -121,7 +121,7 @@ object semiGroups { val commons: Nat.type = Nat } object Nat extends MonoidCommon { - type This = Nat + type ThisClass = Nat type Instance = Nat def unit = Nat.Z def inject($this: Nat) = $this @@ -141,12 +141,12 @@ object semiGroups { /** 2. Generic implementations of simple type classes. trait Ord extends TypeClass { - def compareTo(that: This): Int - def < (that: This) = compareTo(that) < 0 - def > (that: This) = compareTo(that) > 0 + def compareTo(that: ThisClass): Int + def < (that: ThisClass) = compareTo(that) < 0 + def > (that: ThisClass) = compareTo(that) > 0 } common { - val minimum: This + val minimum: ThisClass } extension IntOrd for Int : Ord { @@ -180,32 +180,32 @@ object ord { trait Ord extends TypeClass { val commons: OrdCommon import commons._ - def compareTo(that: This): Int - def < (that: This) = compareTo(that) < 0 - def > (that: This) = compareTo(that) > 0 + def compareTo(that: ThisClass): Int + def < (that: ThisClass) = compareTo(that) < 0 + def > (that: ThisClass) = compareTo(that) > 0 } trait OrdCommon extends TypeClassCommon { type Instance <: Ord - def minimum: This + def minimum: ThisClass } object Ord extends TypeClassCompanion { - type Impl[T] = OrdCommon { type This = T } + type Impl[T] = OrdCommon { type ThisClass = T } } implicit object IntOrd extends OrdCommon { - type This = Int + type ThisClass = Int type Instance = Ord val minimum: Int = Int.MinValue def inject($this: Int) = new Ord { val commons: IntOrd.this.type = IntOrd.this import commons._ - def compareTo(that: This): Int = + def compareTo(that: ThisClass): Int = if (this < that) -1 else if (this > that) +1 else 0 } } class ListOrd[T](implicit ev: Ord.Impl[T]) extends OrdCommon { self => - type This = List[T] + type ThisClass = List[T] type Instance = Ord def minimum: List[T] = Nil def inject($this: List[T]) = new Ord { @@ -241,10 +241,10 @@ object ord { /** 3. Higher-kinded type classes trait Functor[A] extends TypeClass1 { - def map[B](f: A => B): This[B] + def map[B](f: A => B): ThisClass[B] } common { - def pure[A](x: A): This[A] + def pure[A](x: A): ThisClass[A] } // Generically, `pure[A]{.map(f)}^n` @@ -253,7 +253,7 @@ object ord { else develop[A, F](n - 1, f).map(f) trait Monad[A] extends Functor[A] { - def flatMap[B](f: A => This[B]): This[B] + def flatMap[B](f: A => ThisClass[B]): ThisClass[B] def map[B](f: A => B) = this.flatMap(f.andThen(pure)) } @@ -274,22 +274,22 @@ object runtime1 { trait TypeClass1 { val commons: TypeClassCommon1 - type This = commons.This + type ThisClass = commons.ThisClass } trait TypeClassCommon1 { self => - type This[X] + type ThisClass[X] type Instance[X] <: TypeClass1 - def inject[A](x: This[A]): Instance[A] { val commons: self.type } + def inject[A](x: ThisClass[A]): Instance[A] { val commons: self.type } } trait TypeClassCompanion1 { - type Impl[T[_]] <: TypeClassCommon1 { type This = T } + type Impl[T[_]] <: TypeClassCommon1 { type ThisClass = T } def impl[T[_]](implicit ev: Impl[T]): Impl[T] = ev } implicit def inject1[A, From[_]](x: From[A]) - (implicit ev: TypeClassCommon1 { type This = From }): ev.Instance[A] { type This = From } = + (implicit ev: TypeClassCommon1 { type ThisClass = From }): ev.Instance[A] { type ThisClass = From } = ev.inject(x) } import runtime1._ @@ -299,27 +299,27 @@ object functors { trait Functor[A] extends TypeClass1 { val commons: FunctorCommon import commons._ - def map[B](f: A => B): This[B] + def map[B](f: A => B): ThisClass[B] } trait FunctorCommon extends TypeClassCommon1 { type Instance[X] <: Functor[X] - def pure[A](x: A): This[A] + def pure[A](x: A): ThisClass[A] } object Functor extends TypeClassCompanion1 { - type Impl[T[_]] = FunctorCommon { type This = T } + type Impl[T[_]] = FunctorCommon { type ThisClass = T } } trait Monad[A] extends Functor[A] { val commons: MonadCommon import commons._ - def flatMap[B](f: A => This[B]): This[B] + def flatMap[B](f: A => ThisClass[B]): ThisClass[B] def map[B](f: A => B) = this.flatMap(f.andThen(commons.pure)) } trait MonadCommon extends FunctorCommon { type Instance[X] <: Monad[X] } object Monad extends TypeClassCompanion1 { - type Impl[T[_]] = MonadCommon { type This = T } + type Impl[T[_]] = MonadCommon { type ThisClass = T } } def develop[A, F[X]](n: Int, x: A, f: A => A)(implicit ev: Functor.Impl[F]): F[A] = @@ -327,7 +327,7 @@ object functors { else develop(n - 1, x, f).map(f) implicit object ListMonad extends MonadCommon { - type This = List + type ThisClass = List type Instance = Monad def pure[A](x: A) = x :: Nil def inject[A]($this: List[A]) = new Monad[A] { diff --git a/tests/pos/typeclass-encoding3.scala b/tests/pos/typeclass-encoding3.scala index 37a4dd2670a0..0f2a4bb4b34f 100644 --- a/tests/pos/typeclass-encoding3.scala +++ b/tests/pos/typeclass-encoding3.scala @@ -34,7 +34,7 @@ object Test { Monomorphic: trait SemiGroup - def combine(that: This): This + def combine(that: ThisClass): ThisClass common type This @@ -63,14 +63,14 @@ object Test { val common: SemiGroup.Common import common._ - def combine(that: This): This + def combine(that: ThisClass): ThisClass } object SemiGroup { trait Common { self => - type This - def inject(x: This): SemiGroup { val common: self.type } + type ThisClass + def inject(x: ThisClass): SemiGroup { val common: self.type } } - def by[A](implicit ev: SemiGroup.Common { type This = A }): ev.type = ev + def by[A](implicit ev: SemiGroup.Common { type ThisClass = A }): ev.type = ev } trait Monoid extends SemiGroup { @@ -79,10 +79,10 @@ object Test { } object Monoid { trait Common extends SemiGroup.Common { self => - def inject(x: This): Monoid { val common: self.type } - def unit: This + def inject(x: ThisClass): Monoid { val common: self.type } + def unit: ThisClass } - def by[A](implicit ev: Monoid.Common { type This = A }): ev.type = ev + def by[A](implicit ev: Monoid.Common { type ThisClass = A }): ev.type = ev } class Str(val s: String) extends Monoid { @@ -90,28 +90,28 @@ object Test { def combine(that: Str): Str = new Str(this.s + that.s) } object Str extends Monoid.Common { - type This = Str - def inject(x: This): Str = x + type ThisClass = Str + def inject(x: ThisClass): Str = x def unit = new Str("") } class SubStr(s: String) extends Str(s) implicit object String_Monoid extends Monoid.Common { self => - type This = String - class Impl(`this`: This) extends Monoid { + type ThisClass = String + class Impl(`this`: ThisClass) extends Monoid { val common: self.type = self def combine(that: String): String = `this` + that } - def inject(x: This): Impl = new Impl(x) + def inject(x: ThisClass): Impl = new Impl(x) def unit = "" } - def f[X](x: X)(implicit ev: Monoid.Common { type This = X }) = { + def f[X](x: X)(implicit ev: Monoid.Common { type ThisClass = X }) = { ev.inject(Monoid.by[X].unit).combine(x) } - def sum[A](xs: List[A])(implicit ev: Monoid.Common { type This = A }): A = + def sum[A](xs: List[A])(implicit ev: Monoid.Common { type ThisClass = A }): A = xs.foldLeft(Monoid.by[A].unit)(ev.inject(_).combine(_)) f(new Str("abc"))(Str) @@ -158,33 +158,33 @@ object Test { val common: Ord.Common import common._ - def compareTo(that: This): Int - def < (that: This) = compareTo(that) < 0 - def > (that: This) = compareTo(that) > 0 + def compareTo(that: ThisClass): Int + def < (that: ThisClass) = compareTo(that) < 0 + def > (that: ThisClass) = compareTo(that) > 0 } object Ord { trait Common { self => - type This - def inject(x: This): Ord { val common: self.type } - val minimum: This + type ThisClass + def inject(x: ThisClass): Ord { val common: self.type } + val minimum: ThisClass } - def by[A](implicit ev: Ord.Common { type This = A }): ev.type = ev + def by[A](implicit ev: Ord.Common { type ThisClass = A }): ev.type = ev } implicit object Int_Ord extends Ord.Common { self => - type This = Int - class Impl(`this`: This) extends Ord { + type ThisClass = Int + class Impl(`this`: ThisClass) extends Ord { val common: self.type = self def compareTo(that: Int) = if (`this` < that) -1 else if (`this` > that) +1 else 0 } - def inject(x: This): Impl = new Impl(x) + def inject(x: ThisClass): Impl = new Impl(x) val minimum = Int.MinValue } - class List_Ord[T](implicit ev: Ord.Common { type This = T }) extends Ord.Common { self => - type This = List[T] - class Impl(`this`: This) extends Ord { + class List_Ord[T](implicit ev: Ord.Common { type ThisClass = T }) extends Ord.Common { self => + type ThisClass = List[T] + class Impl(`this`: ThisClass) extends Ord { val common: self.type = self def compareTo(that: List[T]): Int = (`this`, that) match { case (Nil, Nil) => 0 @@ -195,16 +195,16 @@ object Test { if (fst != 0) fst else List_Ord[T].inject(xs).compareTo(ys) } } - def inject(x: This): Impl = new Impl(x) + def inject(x: ThisClass): Impl = new Impl(x) val minimum = Nil } - implicit def List_Ord[T](implicit ev: Ord.Common { type This = T }): List_Ord[T] = + implicit def List_Ord[T](implicit ev: Ord.Common { type ThisClass = T }): List_Ord[T] = new List_Ord[T] - def max[T](x: T, y: T)(implicit ev: Ord.Common { type This = T }) = if (ev.inject(x) < y) x else y + def max[T](x: T, y: T)(implicit ev: Ord.Common { type ThisClass = T }) = if (ev.inject(x) < y) x else y - def max[T](xs: List[T])(implicit ev: Ord.Common { type This = T }): T = + def max[T](xs: List[T])(implicit ev: Ord.Common { type ThisClass = T }): T = xs.foldLeft(Ord.by[T].minimum)(max(_, _)) val x1 = max(1, 2) @@ -243,48 +243,48 @@ object Test { val common: Functor.Common import common._ - def map[B](f: A => B): This[B] + def map[B](f: A => B): ThisClass[B] } object Functor { trait Common { self => - type This[A] - def inject[A](x: This[A]): Functor[A] { val common: self.type } + type ThisClass[A] + def inject[A](x: ThisClass[A]): Functor[A] { val common: self.type } } - inline def by[F[_]](implicit ev: Functor.Common { type This[A] = F[A] }): ev.type = ev + inline def by[F[_]](implicit ev: Functor.Common { type ThisClass[A] = F[A] }): ev.type = ev } trait Monad[A] extends Functor[A] { self => val common: Monad.Common import common._ - def flatMap[B](f: A => This[B]): This[B] - def map[B](f: A => B): This[B] = flatMap(f `andThen` pure) + def flatMap[B](f: A => ThisClass[B]): ThisClass[B] + def map[B](f: A => B): ThisClass[B] = flatMap(f `andThen` pure) } object Monad { trait Common extends Functor.Common { self => - def pure[A](x: A): This[A] - def inject[A](x: This[A]): Monad[A] { val common: self.type } + def pure[A](x: A): ThisClass[A] + def inject[A](x: ThisClass[A]): Monad[A] { val common: self.type } } - def by[F[_]](implicit ev: Monad.Common { type This[A] = F[A] }): ev.type = ev + def by[F[_]](implicit ev: Monad.Common { type ThisClass[A] = F[A] }): ev.type = ev } implicit object List_Monad extends Monad.Common { self => - type This[A] = List[A] - class Impl[A](`this`: This[A]) extends Monad[A] { + type ThisClass[A] = List[A] + class Impl[A](`this`: ThisClass[A]) extends Monad[A] { val common: self.type = self - def flatMap[B](f: A => This[B]): This[B] = `this`.flatMap(f) + def flatMap[B](f: A => ThisClass[B]): ThisClass[B] = `this`.flatMap(f) } - def pure[A](x: A): This[A] = x :: Nil + def pure[A](x: A): ThisClass[A] = x :: Nil def inject[A](x: List[A]): Impl[A] = new Impl[A](x) } - def g[F[_], A, B](x: A, f: A => B)(implicit ev: Monad.Common { type This[A] = F[A] }) - : ev.This[B] = + def g[F[_], A, B](x: A, f: A => B)(implicit ev: Monad.Common { type ThisClass[A] = F[A] }) + : ev.ThisClass[B] = ev.inject(Monad.by[F].pure(x)).map(f) - def h[F[_], A, B](x: A)(implicit ev: Monad.Common { type This[A] = F[A] }) - : (A => ev.This[B]) => ev.This[B] = + def h[F[_], A, B](x: A)(implicit ev: Monad.Common { type ThisClass[A] = F[A] }) + : (A => ev.ThisClass[B]) => ev.ThisClass[B] = f => ev.inject(Monad.by[F].pure(x)).flatMap(f) val r = g[F = List](1, _.toString) @@ -302,15 +302,15 @@ object Test { * ---------------------------------------------------------------------------- */ class $eq$gt_Monad[Ctx] extends Monad.Common { self => - type This[A] = Ctx => A - class Impl[A](`this`: This[A]) extends Monad[A] { + type ThisClass[A] = Ctx => A + class Impl[A](`this`: ThisClass[A]) extends Monad[A] { val common: self.type = self - def flatMap[B](f: A => This[B]): This[B] = + def flatMap[B](f: A => ThisClass[B]): ThisClass[B] = ctx => f(`this`(ctx))(ctx) } - def pure[A](x: A): This[A] = + def pure[A](x: A): ThisClass[A] = ctx => x - def inject[A](x: This[A]): Impl[A] = new Impl[A](x) + def inject[A](x: ThisClass[A]): Impl[A] = new Impl[A](x) } implicit def $eq$gt_Monad[Ctx]: $eq$gt_Monad[Ctx] = new $eq$gt_Monad[Ctx] diff --git a/tests/run/mixins1/A_1.scala b/tests/run/mixins1/A_1.scala index 9d1de641ccbf..9e70ae080c1e 100644 --- a/tests/run/mixins1/A_1.scala +++ b/tests/run/mixins1/A_1.scala @@ -1,4 +1,4 @@ -trait A[This <: A[This] with B] { self: B => +trait A[Self <: A[Self] with B] { self: B => var x = 3 println("hi") val y = x * x diff --git a/tests/run/t3452f.scala b/tests/run/t3452f.scala index af64f5c04229..da42f0c6a454 100644 --- a/tests/run/t3452f.scala +++ b/tests/run/t3452f.scala @@ -6,8 +6,8 @@ trait GenSetTemplate[A, +CC[X] <: GenSet[X]] { def empty: CC[A] = ??? } -trait SetLike[A, +This <: SetLike[A, This] with Set[A]] { - def empty: This +trait SetLike[A, +Self <: SetLike[A, Self] with Set[A]] { + def empty: Self } abstract class Set[A] extends GenSet[A] with SetLike[A,Set[A]] with GenSetTemplate[A,Set] diff --git a/tests/untried/neg/abstract-concrete-methods.scala b/tests/untried/neg/abstract-concrete-methods.scala index 7f1aea0dbcb1..c8f8e76d42c4 100644 --- a/tests/untried/neg/abstract-concrete-methods.scala +++ b/tests/untried/neg/abstract-concrete-methods.scala @@ -1,8 +1,8 @@ -trait Outer[This <: Outer[This]] { - self: This => +trait Outer[Self <: Outer[Self]] { + self: Self => trait Inner - def score(i: This#Inner): Double + def score(i: Self#Inner): Double } class Outer2 extends Outer[Outer2] { class Inner extends super.Inner diff --git a/tests/untried/neg/t6042.scala b/tests/untried/neg/t6042.scala index 5a123d17cad7..ad03ded8dd17 100644 --- a/tests/untried/neg/t6042.scala +++ b/tests/untried/neg/t6042.scala @@ -1,8 +1,8 @@ -trait LazyExp[+This <: LazyExp[This]] { this: This => - type OpSemExp <: LazyExp[OpSemExp] with This +trait LazyExp[+Self <: LazyExp[Self]] { this: Self => + type OpSemExp <: LazyExp[OpSemExp] with Self type Val } object Test { - def foo[AA <: LazyExp[_]](a: AA): a.OpSemExp#Val = ??? // a.OpSemExp is volatile, because of `with This` + def foo[AA <: LazyExp[_]](a: AA): a.OpSemExp#Val = ??? // a.OpSemExp is volatile, because of `with Self` } diff --git a/tests/untried/pos/t6556.scala b/tests/untried/pos/t6556.scala index 13560e8bafe7..949c4106045a 100644 --- a/tests/untried/pos/t6556.scala +++ b/tests/untried/pos/t6556.scala @@ -1,9 +1,9 @@ package nl.ndervorst.commons.scalapimps trait Adapter[X] {self => - type This = self.type + type Self = self.type val adaptee: X - val adapt: This = self + val adapt: Self = self } object Adapter {