@@ -288,6 +288,12 @@ object Types {
288288 /** Is this an alias TypeBounds? */
289289 final def isAlias : Boolean = this .isInstanceOf [TypeAlias ]
290290
291+ /** Is this a MethodType which is from Java */
292+ def isJavaMethod : Boolean = false
293+
294+ /** Is this a MethodType which has implicit parameters */
295+ def isImplicitMethod : Boolean = false
296+
291297// ----- Higher-order combinators -----------------------------------
292298
293299 /** Returns true if there is a part of this type that satisfies predicate `p`.
@@ -1317,7 +1323,7 @@ object Types {
13171323 case mt : MethodType if ! mt.isDependent || ctx.mode.is(Mode .AllowDependentFunctions ) =>
13181324 val formals1 = if (dropLast == 0 ) mt.paramInfos else mt.paramInfos dropRight dropLast
13191325 defn.FunctionOf (
1320- formals1 mapConserve (_.underlyingIfRepeated(mt.isJava )), mt.resultType, mt.isImplicit && ! ctx.erasedTypes)
1326+ formals1 mapConserve (_.underlyingIfRepeated(mt.isJavaMethod )), mt.resultType, mt.isImplicitMethod && ! ctx.erasedTypes)
13211327 }
13221328
13231329 /** The signature of this type. This is by default NotAMethod,
@@ -2552,9 +2558,6 @@ object Types {
25522558
25532559 override def resultType (implicit ctx : Context ) = resType
25542560
2555- def isJava : Boolean = false
2556- def isImplicit = false
2557-
25582561 def isDependent (implicit ctx : Context ): Boolean
25592562 def isParamDependent (implicit ctx : Context ): Boolean
25602563
@@ -2708,12 +2711,17 @@ object Types {
27082711
27092712 type This = MethodType
27102713
2714+ def companion : MethodTypeCompanion
2715+
2716+ final override def isJavaMethod : Boolean = companion.isJava
2717+ final override def isImplicitMethod : Boolean = companion.isImplicit
2718+
27112719 val paramInfos = paramInfosExp(this )
27122720 val resType = resultTypeExp(this )
27132721 assert(resType.exists)
27142722
27152723 def computeSignature (implicit ctx : Context ): Signature =
2716- resultSignature.prepend(paramInfos, isJava )
2724+ resultSignature.prepend(paramInfos, isJavaMethod )
27172725
27182726 final override def computeHash = doHash(paramNames, resType, paramInfos)
27192727
@@ -2740,24 +2748,8 @@ object Types {
27402748 protected def prefixString = " MethodType"
27412749 }
27422750
2743- final class CachedMethodType (paramNames : List [TermName ])(paramInfosExp : MethodType => List [Type ], resultTypeExp : MethodType => Type )
2744- extends MethodType (paramNames)(paramInfosExp, resultTypeExp) {
2745- def companion = MethodType
2746- }
2747-
2748- final class JavaMethodType (paramNames : List [TermName ])(paramInfosExp : MethodType => List [Type ], resultTypeExp : MethodType => Type )
2749- extends MethodType (paramNames)(paramInfosExp, resultTypeExp) {
2750- def companion = JavaMethodType
2751- override def isJava = true
2752- override protected def prefixString = " JavaMethodType"
2753- }
2754-
2755- final class ImplicitMethodType (paramNames : List [TermName ])(paramInfosExp : MethodType => List [Type ], resultTypeExp : MethodType => Type )
2756- extends MethodType (paramNames)(paramInfosExp, resultTypeExp) {
2757- def companion = ImplicitMethodType
2758- override def isImplicit = true
2759- override protected def prefixString = " ImplicitMethodType"
2760- }
2751+ final class CachedMethodType (paramNames : List [TermName ])(paramInfosExp : MethodType => List [Type ], resultTypeExp : MethodType => Type , val companion : MethodTypeCompanion )
2752+ extends MethodType (paramNames)(paramInfosExp, resultTypeExp)
27612753
27622754 abstract class LambdaTypeCompanion [N <: Name , PInfo <: Type , LT <: LambdaType ] {
27632755 def syntheticParamName (n : Int ): N
@@ -2802,7 +2794,10 @@ object Types {
28022794 def syntheticParamName (n : Int ) = tpnme.syntheticTypeParamName(n)
28032795 }
28042796
2805- abstract class MethodTypeCompanion extends TermLambdaCompanion [MethodType ] {
2797+ abstract class MethodTypeCompanion extends TermLambdaCompanion [MethodType ] { self =>
2798+
2799+ def isJava : Boolean = false
2800+ def isImplicit : Boolean = false
28062801
28072802 /** Produce method type from parameter symbols, with special mappings for repeated
28082803 * and inline parameters:
@@ -2833,6 +2828,9 @@ object Types {
28332828 tl => tl.integrate(params, resultType))
28342829 }
28352830
2831+ final def apply (paramNames : List [TermName ])(paramInfosExp : MethodType => List [Type ], resultTypeExp : MethodType => Type )(implicit ctx : Context ): MethodType =
2832+ checkValid(new CachedMethodType (paramNames)(paramInfosExp, resultTypeExp, self))
2833+
28362834 def checkValid (mt : MethodType )(implicit ctx : Context ): mt.type = {
28372835 if (Config .checkMethodTypes)
28382836 for ((paramInfo, idx) <- mt.paramInfos.zipWithIndex)
@@ -2845,18 +2843,19 @@ object Types {
28452843 }
28462844
28472845 object MethodType extends MethodTypeCompanion {
2848- def apply (paramNames : List [TermName ])(paramInfosExp : MethodType => List [Type ], resultTypeExp : MethodType => Type )(implicit ctx : Context ): MethodType =
2849- checkValid(unique(new CachedMethodType (paramNames)(paramInfosExp, resultTypeExp)))
2846+ def withKind (isJava : Boolean = false , isImplicit : Boolean = false ): MethodTypeCompanion = {
2847+ if (isJava) JavaMethodType
2848+ else if (isImplicit) ImplicitMethodType
2849+ else MethodType
2850+ }
28502851 }
28512852
28522853 object JavaMethodType extends MethodTypeCompanion {
2853- def apply (paramNames : List [TermName ])(paramInfosExp : MethodType => List [Type ], resultTypeExp : MethodType => Type )(implicit ctx : Context ): MethodType =
2854- unique(new JavaMethodType (paramNames)(paramInfosExp, resultTypeExp))
2854+ override def isJava : Boolean = true
28552855 }
28562856
28572857 object ImplicitMethodType extends MethodTypeCompanion {
2858- def apply (paramNames : List [TermName ])(paramInfosExp : MethodType => List [Type ], resultTypeExp : MethodType => Type )(implicit ctx : Context ): MethodType =
2859- checkValid(unique(new ImplicitMethodType (paramNames)(paramInfosExp, resultTypeExp)))
2858+ override def isImplicit : Boolean = true
28602859 }
28612860
28622861 /** A ternary extractor for MethodType */
0 commit comments