Skip to content

Commit 4d7e6ad

Browse files
committed
Make MethodTypeKind into an enum
1 parent 4eff748 commit 4d7e6ad

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

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

+10-9
Original file line numberDiff line numberDiff line change
@@ -2204,13 +2204,6 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
22042204
case _ => None
22052205
end MethodOrPolyTypeTest
22062206

2207-
type MethodTypeKind = dotc.core.Types.MethodTypeCompanion
2208-
2209-
object MethodTypeKind extends MethodTypeKindModule:
2210-
val Plain: MethodTypeKind = Types.MethodType
2211-
val Contextual: MethodTypeKind = Types.ContextualMethodType
2212-
val Implicit: MethodTypeKind = Types.ImplicitMethodType
2213-
22142207
type MethodType = dotc.core.Types.MethodType
22152208

22162209
object MethodTypeTypeTest extends TypeTest[TypeRepr, MethodType]:
@@ -2223,7 +2216,11 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
22232216
def apply(paramNames: List[String])(paramInfosExp: MethodType => List[TypeRepr], resultTypeExp: MethodType => TypeRepr): MethodType =
22242217
Types.MethodType(paramNames.map(_.toTermName))(paramInfosExp, resultTypeExp)
22252218
def apply(kind: MethodTypeKind)(paramNames: List[String])(paramInfosExp: MethodType => List[TypeRepr], resultTypeExp: MethodType => TypeRepr): MethodType =
2226-
kind.apply(paramNames.map(_.toTermName))(paramInfosExp, resultTypeExp)
2219+
val companion = kind match
2220+
case MethodTypeKind.Contextual => Types.ContextualMethodType
2221+
case MethodTypeKind.Implicit => Types.ImplicitMethodType
2222+
case MethodTypeKind.Plain => Types.MethodType
2223+
companion.apply(paramNames.map(_.toTermName))(paramInfosExp, resultTypeExp)
22272224
def unapply(x: MethodType): (List[String], List[TypeRepr], TypeRepr) =
22282225
(x.paramNames.map(_.toString), x.paramTypes, x.resType)
22292226
end MethodType
@@ -2233,7 +2230,11 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
22332230
def isErased: Boolean = false
22342231
def isImplicit: Boolean = self.isImplicitMethod
22352232
def isContextual: Boolean = self.isContextualMethod
2236-
def methodTypeKind: MethodTypeKind = self.companion
2233+
def methodTypeKind: MethodTypeKind =
2234+
self.companion match
2235+
case Types.ContextualMethodType => MethodTypeKind.Contextual
2236+
case Types.ImplicitMethodType => MethodTypeKind.Implicit
2237+
case _ => MethodTypeKind.Plain
22372238
def param(idx: Int): TypeRepr = self.newParamRef(idx)
22382239

22392240
def erasedParams: List[Boolean] = self.erasedParams

library/src/scala/quoted/Quotes.scala

+7-12
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
212212
* +- TypeBounds
213213
* +- NoPrefix
214214
*
215-
* +- MethodTypeKind
215+
* +- MethodTypeKind -+- Contextual
216+
* +- Implicit
217+
* +- Plain
216218
*
217219
* +- Selector -+- SimpleSelector
218220
* +- RenameSelector
@@ -3237,20 +3239,13 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
32373239
given MethodOrPolyTypeTest: TypeTest[TypeRepr, MethodOrPoly]
32383240

32393241
/** Type which decides on the kind of parameter list represented by `MethodType`. */
3240-
type MethodTypeKind
3241-
3242-
/** Module object of `type MethodKind` */
3243-
val MethodTypeKind: MethodTypeKindModule
3244-
3245-
/** Methods of the module object `val MethodKind` */
3246-
trait MethodTypeKindModule { this: MethodTypeKind.type =>
3242+
enum MethodTypeKind:
32473243
/** Represents a parameter list without any implicitness of parameters, like (x1: X1, x2: X2, ...) */
3248-
val Plain: MethodTypeKind
3244+
case Plain
32493245
/** Represents a parameter list with implicit parameters, like `(implicit X1, ..., Xn)`, `(using X1, ..., Xn)`, `(using x1: X1, ..., xn: Xn)` */
3250-
val Implicit: MethodTypeKind
3246+
case Implicit
32513247
/** Represents a parameter list of a contextual method, like `(using X1, ..., Xn)` or `(using x1: X1, ..., xn: Xn)` */
3252-
val Contextual: MethodTypeKind
3253-
}
3248+
case Contextual
32543249

32553250
/** Type of the definition of a method taking a single list of parameters. It's return type may be a MethodType. */
32563251
type MethodType <: MethodOrPoly

0 commit comments

Comments
 (0)