@@ -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 eq JavaMethodType
2717+ final override def isImplicitMethod : Boolean = companion eq ImplicitMethodType
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,7 @@ 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 =>
28062798
28072799 /** Produce method type from parameter symbols, with special mappings for repeated
28082800 * and inline parameters:
@@ -2833,6 +2825,9 @@ object Types {
28332825 tl => tl.integrate(params, resultType))
28342826 }
28352827
2828+ final def apply (paramNames : List [TermName ])(paramInfosExp : MethodType => List [Type ], resultTypeExp : MethodType => Type )(implicit ctx : Context ): MethodType =
2829+ checkValid(new CachedMethodType (paramNames)(paramInfosExp, resultTypeExp, self))
2830+
28362831 def checkValid (mt : MethodType )(implicit ctx : Context ): mt.type = {
28372832 if (Config .checkMethodTypes)
28382833 for ((paramInfo, idx) <- mt.paramInfos.zipWithIndex)
@@ -2844,20 +2839,9 @@ object Types {
28442839 }
28452840 }
28462841
2847- 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)))
2850- }
2851-
2852- 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))
2855- }
2856-
2857- 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)))
2860- }
2842+ object MethodType extends MethodTypeCompanion
2843+ object JavaMethodType extends MethodTypeCompanion
2844+ object ImplicitMethodType extends MethodTypeCompanion
28612845
28622846 /** A ternary extractor for MethodType */
28632847 object MethodTpe {
0 commit comments