Skip to content

Commit 04fca6b

Browse files
committed
Switch TypeApplications to exported extensions
1 parent 14b7f03 commit 04fca6b

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

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

43794379
def declaredVariances =
4380-
if isDeclaredVarianceLambda then typeParams.map(_.declaredVariance)
4380+
if isDeclaredVarianceLambda then this.typeParams.map(_.declaredVariance)
43814381
else Nil
43824382

43834383
override def computeHash(bs: Binders): Int =
@@ -4390,7 +4390,7 @@ object Types extends TypeUtils {
43904390
paramNames.eqElements(that.paramNames)
43914391
&& isDeclaredVarianceLambda == that.isDeclaredVarianceLambda
43924392
&& (!isDeclaredVarianceLambda
4393-
|| typeParams.corresponds(that.typeParams)((x, y) =>
4393+
|| this.typeParams.corresponds(that.typeParams)((x, y) =>
43944394
x.declaredVariance == y.declaredVariance))
43954395
&& {
43964396
val bs1 = new SomeBinderPairs(this, that, bs)
@@ -7183,7 +7183,7 @@ object Types extends TypeUtils {
71837183

71847184
// ----- Helpers and Decorator implicits --------------------------------------
71857185

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

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