Skip to content

Commit

Permalink
Make MethodTypeKind into an enum
Browse files Browse the repository at this point in the history
  • Loading branch information
jchyb committed Apr 25, 2024
1 parent 4eff748 commit 4d7e6ad
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
19 changes: 10 additions & 9 deletions compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2204,13 +2204,6 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
case _ => None
end MethodOrPolyTypeTest

type MethodTypeKind = dotc.core.Types.MethodTypeCompanion

object MethodTypeKind extends MethodTypeKindModule:
val Plain: MethodTypeKind = Types.MethodType
val Contextual: MethodTypeKind = Types.ContextualMethodType
val Implicit: MethodTypeKind = Types.ImplicitMethodType

type MethodType = dotc.core.Types.MethodType

object MethodTypeTypeTest extends TypeTest[TypeRepr, MethodType]:
Expand All @@ -2223,7 +2216,11 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
def apply(paramNames: List[String])(paramInfosExp: MethodType => List[TypeRepr], resultTypeExp: MethodType => TypeRepr): MethodType =
Types.MethodType(paramNames.map(_.toTermName))(paramInfosExp, resultTypeExp)
def apply(kind: MethodTypeKind)(paramNames: List[String])(paramInfosExp: MethodType => List[TypeRepr], resultTypeExp: MethodType => TypeRepr): MethodType =
kind.apply(paramNames.map(_.toTermName))(paramInfosExp, resultTypeExp)
val companion = kind match
case MethodTypeKind.Contextual => Types.ContextualMethodType
case MethodTypeKind.Implicit => Types.ImplicitMethodType
case MethodTypeKind.Plain => Types.MethodType
companion.apply(paramNames.map(_.toTermName))(paramInfosExp, resultTypeExp)
def unapply(x: MethodType): (List[String], List[TypeRepr], TypeRepr) =
(x.paramNames.map(_.toString), x.paramTypes, x.resType)
end MethodType
Expand All @@ -2233,7 +2230,11 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
def isErased: Boolean = false
def isImplicit: Boolean = self.isImplicitMethod
def isContextual: Boolean = self.isContextualMethod
def methodTypeKind: MethodTypeKind = self.companion
def methodTypeKind: MethodTypeKind =
self.companion match
case Types.ContextualMethodType => MethodTypeKind.Contextual
case Types.ImplicitMethodType => MethodTypeKind.Implicit
case _ => MethodTypeKind.Plain
def param(idx: Int): TypeRepr = self.newParamRef(idx)

def erasedParams: List[Boolean] = self.erasedParams
Expand Down
19 changes: 7 additions & 12 deletions library/src/scala/quoted/Quotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
* +- TypeBounds
* +- NoPrefix
*
* +- MethodTypeKind
* +- MethodTypeKind -+- Contextual
* +- Implicit
* +- Plain
*
* +- Selector -+- SimpleSelector
* +- RenameSelector
Expand Down Expand Up @@ -3237,20 +3239,13 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
given MethodOrPolyTypeTest: TypeTest[TypeRepr, MethodOrPoly]

/** Type which decides on the kind of parameter list represented by `MethodType`. */
type MethodTypeKind

/** Module object of `type MethodKind` */
val MethodTypeKind: MethodTypeKindModule

/** Methods of the module object `val MethodKind` */
trait MethodTypeKindModule { this: MethodTypeKind.type =>
enum MethodTypeKind:
/** Represents a parameter list without any implicitness of parameters, like (x1: X1, x2: X2, ...) */
val Plain: MethodTypeKind
case Plain
/** Represents a parameter list with implicit parameters, like `(implicit X1, ..., Xn)`, `(using X1, ..., Xn)`, `(using x1: X1, ..., xn: Xn)` */
val Implicit: MethodTypeKind
case Implicit
/** Represents a parameter list of a contextual method, like `(using X1, ..., Xn)` or `(using x1: X1, ..., xn: Xn)` */
val Contextual: MethodTypeKind
}
case Contextual

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

0 comments on commit 4d7e6ad

Please sign in to comment.