Skip to content

Commit 1091031

Browse files
committed
Switch TypeApplications to exported extensions
1 parent 5429b1f commit 1091031

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
@@ -4370,10 +4370,10 @@ object Types extends TypeUtils {
43704370
setVariances(tparams.tail, vs.tail)
43714371

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

43754375
def declaredVariances =
4376-
if isDeclaredVarianceLambda then typeParams.map(_.declaredVariance)
4376+
if isDeclaredVarianceLambda then this.typeParams.map(_.declaredVariance)
43774377
else Nil
43784378

43794379
override def computeHash(bs: Binders): Int =
@@ -4386,7 +4386,7 @@ object Types extends TypeUtils {
43864386
paramNames.eqElements(that.paramNames)
43874387
&& isDeclaredVarianceLambda == that.isDeclaredVarianceLambda
43884388
&& (!isDeclaredVarianceLambda
4389-
|| typeParams.corresponds(that.typeParams)((x, y) =>
4389+
|| this.typeParams.corresponds(that.typeParams)((x, y) =>
43904390
x.declaredVariance == y.declaredVariance))
43914391
&& {
43924392
val bs1 = new SomeBinderPairs(this, that, bs)
@@ -7160,7 +7160,7 @@ object Types extends TypeUtils {
71607160

71617161
// ----- Helpers and Decorator implicits --------------------------------------
71627162

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

71657165
extension (tps1: List[Type]) {
71667166
@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)