Skip to content

Commit ce8bba7

Browse files
committed
Switch TypeApplications to exported extensions
1 parent 73b935c commit ce8bba7

File tree

3 files changed

+15
-19
lines changed

3 files changed

+15
-19
lines changed

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ object TypeApplications {
1717

1818
type TypeParamInfo = ParamInfo.Of[TypeName]
1919

20-
/** Assert type is not a TypeBounds instance and return it unchanged */
21-
def noBounds(tp: Type): Type = tp match {
22-
case tp: TypeBounds => throw new AssertionError("no TypeBounds allowed")
23-
case _ => tp
24-
}
25-
2620
/** Extractor for
2721
*
2822
* [X1: B1, ..., Xn: Bn] -> C[X1, ..., Xn]
@@ -153,13 +147,9 @@ object TypeApplications {
153147
mapOver(t)
154148
}
155149
}
156-
}
157-
158-
import TypeApplications.*
159-
160-
/** A decorator that provides methods for modeling type application */
161-
class TypeApplications(val self: Type) extends AnyVal {
162150

151+
// Extensions that model type application.
152+
extension (self: Type) {
163153
/** The type parameters of this type are:
164154
* For a ClassInfo type, the type parameters of its class.
165155
* For a typeref referring to a class, the type parameters of the class.
@@ -554,7 +544,7 @@ class TypeApplications(val self: Type) extends AnyVal {
554544
case _ => self.dropDependentRefinement.dealias.argInfos
555545

556546
/** Argument types where existential types in arguments are disallowed */
557-
def argTypes(using Context): List[Type] = argInfos mapConserve noBounds
547+
def argTypes(using Context): List[Type] = argInfos.mapConserve(_.noBounds)
558548

559549
/** Argument types where existential types in arguments are approximated by their lower bound */
560550
def argTypesLo(using Context): List[Type] = argInfos.mapConserve(_.loBound)
@@ -588,4 +578,10 @@ class TypeApplications(val self: Type) extends AnyVal {
588578
.orElse(self.baseType(defn.ArrayClass))
589579
.argInfos.headOption.getOrElse(NoType)
590580
}
581+
582+
/** Assert type is not a TypeBounds instance and return it unchanged */
583+
def noBounds: self.type =
584+
assert(!self.isInstanceOf[TypeBounds], "no TypeBounds allowed")
585+
self
586+
}
591587
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4372,10 +4372,10 @@ object Types extends TypeUtils {
43724372
setVariances(tparams.tail, vs.tail)
43734373

43744374
override val isDeclaredVarianceLambda = variances.nonEmpty
4375-
if isDeclaredVarianceLambda then setVariances(typeParams, variances)
4375+
if isDeclaredVarianceLambda then setVariances(this.typeParams, variances)
43764376

43774377
def declaredVariances =
4378-
if isDeclaredVarianceLambda then typeParams.map(_.declaredVariance)
4378+
if isDeclaredVarianceLambda then this.typeParams.map(_.declaredVariance)
43794379
else Nil
43804380

43814381
override def computeHash(bs: Binders): Int =
@@ -4388,7 +4388,7 @@ object Types extends TypeUtils {
43884388
paramNames.eqElements(that.paramNames)
43894389
&& isDeclaredVarianceLambda == that.isDeclaredVarianceLambda
43904390
&& (!isDeclaredVarianceLambda
4391-
|| typeParams.corresponds(that.typeParams)((x, y) =>
4391+
|| this.typeParams.corresponds(that.typeParams)((x, y) =>
43924392
x.declaredVariance == y.declaredVariance))
43934393
&& {
43944394
val bs1 = new SomeBinderPairs(this, that, bs)
@@ -7162,7 +7162,7 @@ object Types extends TypeUtils {
71627162

71637163
// ----- Helpers and Decorator implicits --------------------------------------
71647164

7165-
implicit def decorateTypeApplications(tpe: Type): TypeApplications = new TypeApplications(tpe)
7165+
export TypeApplications.{EtaExpandIfHK as _, EtaExpansion as _, TypeParamInfo as _, *}
71667166

71677167
extension (tps1: List[Type]) {
71687168
@tailrec def hashIsStable: Boolean =

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,9 +1897,9 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
18971897
dotc.core.Symbols.defn.isTupleNType(self)
18981898
def select(sym: Symbol): TypeRepr = self.select(sym)
18991899
def appliedTo(targ: TypeRepr): TypeRepr =
1900-
dotc.core.Types.decorateTypeApplications(self).appliedTo(targ)
1900+
dotc.core.Types.appliedTo(self)(targ)
19011901
def appliedTo(targs: List[TypeRepr]): TypeRepr =
1902-
dotc.core.Types.decorateTypeApplications(self).appliedTo(targs)
1902+
dotc.core.Types.appliedTo(self)(targs)
19031903
def substituteTypes(from: List[Symbol], to: List[TypeRepr]): TypeRepr =
19041904
self.subst(from, to)
19051905

0 commit comments

Comments
 (0)