diff --git a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala index bc4f84c147c8..6aefa9736cde 100644 --- a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala +++ b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala @@ -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 @@ -2190,6 +2191,9 @@ 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 @@ -2197,9 +2201,10 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler 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 diff --git a/library/src/scala/quoted/Quotes.scala b/library/src/scala/quoted/Quotes.scala index 15df4a08e1f0..7e72f29e67c2 100644 --- a/library/src/scala/quoted/Quotes.scala +++ b/library/src/scala/quoted/Quotes.scala @@ -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) } @@ -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") @@ -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 diff --git a/project/MiMaFilters.scala b/project/MiMaFilters.scala index fc7b1e29bafc..bbe7cef0f0eb 100644 --- a/project/MiMaFilters.scala +++ b/project/MiMaFilters.scala @@ -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"),