Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Quotes MethodTypeCompanion #18499

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2180,6 +2180,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
end MethodOrPolyTypeTest

type MethodType = dotc.core.Types.MethodType
type MethodTypeCompanion = dotc.core.Types.MethodTypeCompanion

object MethodTypeTypeTest extends TypeTest[TypeRepr, MethodType]:
def unapply(x: TypeRepr): Option[MethodType & x.type] = x match
Expand All @@ -2190,16 +2191,20 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
object MethodType extends MethodTypeModule:
def apply(paramNames: List[String])(paramInfosExp: MethodType => List[TypeRepr], resultTypeExp: MethodType => TypeRepr): MethodType =
Types.MethodType(paramNames.map(_.toTermName))(paramInfosExp, resultTypeExp)
def Plain: MethodTypeCompanion = Types.MethodType
def Contextual: MethodTypeCompanion = Types.ContextualMethodType
def Implicit: MethodTypeCompanion = Types.ImplicitMethodType
def unapply(x: MethodType): (List[String], List[TypeRepr], TypeRepr) =
(x.paramNames.map(_.toString), x.paramTypes, x.resType)
end MethodType

given MethodTypeMethods: MethodTypeMethods with
extension (self: MethodType)
def isErased: Boolean = false
def isContextual: Boolean = self.isContextualMethod
def isImplicit: Boolean = self.isImplicitMethod
def companion: MethodTypeCompanion = self.companion
def param(idx: Int): TypeRepr = self.newParamRef(idx)

def erasedParams: List[Boolean] = self.erasedParams
def hasErasedParams: Boolean = self.hasErasedParams
end extension
Expand Down
18 changes: 18 additions & 0 deletions library/src/scala/quoted/Quotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3185,6 +3185,12 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
/** Methods of the module object `val MethodType` */
trait MethodTypeModule { this: MethodType.type =>
def apply(paramNames: List[String])(paramInfosExp: MethodType => List[TypeRepr], resultTypeExp: MethodType => TypeRepr): MethodType
/** Companion for method type without implicit nor contextual parameter */
def Plain: MethodTypeCompanion
/** Companion for method type with contextual parameter */
def Contextual: MethodTypeCompanion
/** Companion for method type with implicit parameter */
def Implicit: MethodTypeCompanion
def unapply(x: MethodType): (List[String], List[TypeRepr], TypeRepr)
}

Expand All @@ -3194,8 +3200,12 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
/** Extension methods of `MethodType` */
trait MethodTypeMethods:
extension (self: MethodType)
/** Is this the type of using parameter clause `(using X1, ..., Xn)` or `(using x1: X1, ..., xn: Xn)` */
def isContextual: Boolean
/** Is this the type of using parameter clause `(implicit X1, ..., Xn)`, `(using X1, ..., Xn)` or `(using x1: X1, ..., xn: Xn)` */
def isImplicit: Boolean
/** Companion of this method type. Can be used to construct method types with the same implicitness of parameters */
def companion: MethodTypeCompanion
/** Is this the type of erased parameter clause `(erased x1: X1, ..., xn: Xn)` */
// TODO:deprecate in 3.4 and stabilize `erasedParams` and `hasErasedParams`.
// @deprecated("Use `hasErasedParams`","3.4")
Expand All @@ -3211,6 +3221,14 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
end extension
end MethodTypeMethods

/** Companion of a method type. It provides a way to instantiate new method types with a given implicitness of arguments. */
type MethodTypeCompanion

trait MethodTypeCompanionMethods {
/** Create a MethodType with the same implicitness as this companion */
def apply(paramNames: List[String])(paramInfosExp: MethodType => List[TypeRepr], resultTypeExp: MethodType => TypeRepr): MethodType
}

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

Expand Down
9 changes: 7 additions & 2 deletions project/MiMaFilters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ object MiMaFilters {
// New API in 3.4.X
ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule.ValOrDefDefTypeTest"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule.ValOrDefDefMethods"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule#defnModule.FunctionClass")
// New API in 3.4.X
ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule#defnModule.FunctionClass"),

ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule#MethodTypeMethods.isContextual"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule#MethodTypeMethods.companion"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule#MethodTypeModule.Plain"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule#MethodTypeModule.Contextual"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule#MethodTypeModule.Implicit"),
)
val TastyCore: Seq[ProblemFilter] = Seq(
ProblemFilters.exclude[DirectMissingMethodProblem]("dotty.tools.tasty.TastyFormat.EXPLICITtpt"),
Expand Down
Loading