@@ -217,14 +217,14 @@ object Types {
217
217
*/
218
218
def isVarArgsMethod (implicit ctx : Context ): Boolean = this match {
219
219
case tp : PolyType => tp.resultType.isVarArgsMethod
220
- case MethodType (_, paramTypes) => paramTypes.nonEmpty && paramTypes.last.isRepeatedParam
220
+ case mt : MethodType => mt. paramTypes.nonEmpty && mt. paramTypes.last.isRepeatedParam
221
221
case _ => false
222
222
}
223
223
224
224
/** Is this the type of a method with a leading empty parameter list?
225
225
*/
226
226
def isNullaryMethod (implicit ctx : Context ): Boolean = this match {
227
- case MethodType (Nil , _ ) => true
227
+ case MethodType (Nil ) => true
228
228
case tp : PolyType => tp.resultType.isNullaryMethod
229
229
case _ => false
230
230
}
@@ -732,7 +732,7 @@ object Types {
732
732
*/
733
733
final def overrides (that : Type )(implicit ctx : Context ) = {
734
734
def result (tp : Type ): Type = tp match {
735
- case ExprType (_) | MethodType (Nil , _ ) => tp.resultType
735
+ case ExprType (_) | MethodType (Nil ) => tp.resultType
736
736
case _ => tp
737
737
}
738
738
(this frozen_<:< that) || {
@@ -1218,8 +1218,8 @@ object Types {
1218
1218
* when forming the function type.
1219
1219
*/
1220
1220
def toFunctionType (dropLast : Int = 0 )(implicit ctx : Context ): Type = this match {
1221
- case mt @ MethodType (_, formals) if ! mt.isDependent || ctx.mode.is(Mode .AllowDependentFunctions ) =>
1222
- val formals1 = if (dropLast == 0 ) formals else formals dropRight dropLast
1221
+ case mt : MethodType if ! mt.isDependent || ctx.mode.is(Mode .AllowDependentFunctions ) =>
1222
+ val formals1 = if (dropLast == 0 ) mt.paramTypes else mt.paramTypes dropRight dropLast
1223
1223
defn.FunctionOf (
1224
1224
formals1 mapConserve (_.underlyingIfRepeated(mt.isJava)), mt.resultType, mt.isImplicit && ! ctx.erasedTypes)
1225
1225
}
@@ -2312,14 +2312,16 @@ object Types {
2312
2312
2313
2313
trait MethodOrPoly extends MethodicType
2314
2314
2315
- abstract case class MethodType (paramNames : List [TermName ], paramTypes : List [Type ])
2316
- (resultTypeExp : MethodType => Type )
2315
+ abstract case class MethodType (paramNames : List [TermName ])(
2316
+ paramTypesExp : MethodType => List [Type ],
2317
+ resultTypeExp : MethodType => Type )
2317
2318
extends CachedGroundType with BindingType with TermType with MethodOrPoly with NarrowCached { thisMethodType =>
2318
2319
import MethodType ._
2319
2320
2320
2321
def isJava = false
2321
2322
def isImplicit = false
2322
2323
2324
+ val paramTypes = paramTypesExp(this )
2323
2325
private [core] val resType = resultTypeExp(this )
2324
2326
assert(resType.exists)
2325
2327
@@ -2399,10 +2401,11 @@ object Types {
2399
2401
resType : Type = this .resType)(implicit ctx : Context ) =
2400
2402
if ((paramNames eq this .paramNames) && (paramTypes eq this .paramTypes) && (resType eq this .resType)) this
2401
2403
else {
2404
+ val paramTypesFn = (x : MethodType ) => paramTypes.map(_.subst(this , x))
2402
2405
val resTypeFn = (x : MethodType ) => resType.subst(this , x)
2403
- if (isJava) JavaMethodType (paramNames, paramTypes)( resTypeFn)
2404
- else if (isImplicit) ImplicitMethodType (paramNames, paramTypes)( resTypeFn)
2405
- else MethodType (paramNames, paramTypes)( resTypeFn)
2406
+ if (isJava) JavaMethodType (paramNames)(paramTypesFn, resTypeFn)
2407
+ else if (isImplicit) ImplicitMethodType (paramNames)(paramTypesFn, resTypeFn)
2408
+ else MethodType (paramNames)(paramTypesFn, resTypeFn)
2406
2409
}
2407
2410
2408
2411
def instantiate (argTypes : => List [Type ])(implicit ctx : Context ): Type =
@@ -2424,29 +2427,31 @@ object Types {
2424
2427
override def toString = s " $prefixString( $paramNames, $paramTypes, $resType) "
2425
2428
}
2426
2429
2427
- final class CachedMethodType (paramNames : List [TermName ], paramTypes : List [Type ])( resultTypeExp : MethodType => Type )
2428
- extends MethodType (paramNames, paramTypes)( resultTypeExp) {
2430
+ final class CachedMethodType (paramNames : List [TermName ])( paramTypesExp : MethodType => List [Type ], resultTypeExp : MethodType => Type )
2431
+ extends MethodType (paramNames)(paramTypesExp, resultTypeExp) {
2429
2432
override def equals (that : Any ) = super .equals(that) && that.isInstanceOf [CachedMethodType ]
2430
2433
}
2431
2434
2432
- final class JavaMethodType (paramNames : List [TermName ], paramTypes : List [Type ])( resultTypeExp : MethodType => Type )
2433
- extends MethodType (paramNames, paramTypes)( resultTypeExp) {
2435
+ final class JavaMethodType (paramNames : List [TermName ])( paramTypesExp : MethodType => List [Type ], resultTypeExp : MethodType => Type )
2436
+ extends MethodType (paramNames)(paramTypesExp, resultTypeExp) {
2434
2437
override def isJava = true
2435
2438
override def equals (that : Any ) = super .equals(that) && that.isInstanceOf [JavaMethodType ]
2436
2439
override def computeHash = addDelta(super .computeHash, 1 )
2437
2440
override protected def prefixString = " JavaMethodType"
2438
2441
}
2439
2442
2440
- final class ImplicitMethodType (paramNames : List [TermName ], paramTypes : List [Type ])( resultTypeExp : MethodType => Type )
2441
- extends MethodType (paramNames, paramTypes)( resultTypeExp) {
2443
+ final class ImplicitMethodType (paramNames : List [TermName ])( paramTypesExp : MethodType => List [Type ], resultTypeExp : MethodType => Type )
2444
+ extends MethodType (paramNames)(paramTypesExp, resultTypeExp) {
2442
2445
override def isImplicit = true
2443
2446
override def equals (that : Any ) = super .equals(that) && that.isInstanceOf [ImplicitMethodType ]
2444
2447
override def computeHash = addDelta(super .computeHash, 2 )
2445
2448
override protected def prefixString = " ImplicitMethodType"
2446
2449
}
2447
2450
2448
2451
abstract class MethodTypeCompanion {
2449
- def apply (paramNames : List [TermName ], paramTypes : List [Type ])(resultTypeExp : MethodType => Type )(implicit ctx : Context ): MethodType
2452
+ def apply (paramNames : List [TermName ])(paramTypesExp : MethodType => List [Type ], resultTypeExp : MethodType => Type )(implicit ctx : Context ): MethodType
2453
+ def apply (paramNames : List [TermName ], paramTypes : List [Type ])(resultTypeExp : MethodType => Type )(implicit ctx : Context ): MethodType =
2454
+ apply(paramNames)(_ => paramTypes, resultTypeExp)
2450
2455
def apply (paramNames : List [TermName ], paramTypes : List [Type ], resultType : Type )(implicit ctx : Context ): MethodType =
2451
2456
apply(paramNames, paramTypes)(_ => resultType)
2452
2457
def apply (paramTypes : List [Type ])(resultTypeExp : MethodType => Type )(implicit ctx : Context ): MethodType =
@@ -2484,8 +2489,8 @@ object Types {
2484
2489
}
2485
2490
2486
2491
object MethodType extends MethodTypeCompanion {
2487
- def apply (paramNames : List [TermName ], paramTypes : List [Type ])( resultTypeExp : MethodType => Type )(implicit ctx : Context ) =
2488
- unique(new CachedMethodType (paramNames, paramTypes)( resultTypeExp))
2492
+ def apply (paramNames : List [TermName ])( paramTypesExp : MethodType => List [Type ], resultTypeExp : MethodType => Type )(implicit ctx : Context ): MethodType =
2493
+ unique(new CachedMethodType (paramNames)(paramTypesExp, resultTypeExp))
2489
2494
2490
2495
private type DependencyStatus = Byte
2491
2496
private final val Unknown : DependencyStatus = 0 // not yet computed
@@ -2497,13 +2502,19 @@ object Types {
2497
2502
}
2498
2503
2499
2504
object JavaMethodType extends MethodTypeCompanion {
2500
- def apply (paramNames : List [TermName ], paramTypes : List [Type ])( resultTypeExp : MethodType => Type )(implicit ctx : Context ) =
2501
- unique(new JavaMethodType (paramNames, paramTypes)( resultTypeExp))
2505
+ def apply (paramNames : List [TermName ])( paramTypesExp : MethodType => List [Type ], resultTypeExp : MethodType => Type )(implicit ctx : Context ): MethodType =
2506
+ unique(new JavaMethodType (paramNames)(paramTypesExp, resultTypeExp))
2502
2507
}
2503
2508
2504
2509
object ImplicitMethodType extends MethodTypeCompanion {
2505
- def apply (paramNames : List [TermName ], paramTypes : List [Type ])(resultTypeExp : MethodType => Type )(implicit ctx : Context ) =
2506
- unique(new ImplicitMethodType (paramNames, paramTypes)(resultTypeExp))
2510
+ def apply (paramNames : List [TermName ])(paramTypesExp : MethodType => List [Type ], resultTypeExp : MethodType => Type )(implicit ctx : Context ): MethodType =
2511
+ unique(new ImplicitMethodType (paramNames)(paramTypesExp, resultTypeExp))
2512
+ }
2513
+
2514
+ /** A ternary extractor for MethodType */
2515
+ object MethodTpe {
2516
+ def unapply (mt : MethodType )(implicit ctx : Context ) =
2517
+ Some ((mt.paramNames, mt.paramTypes, mt.resultType))
2507
2518
}
2508
2519
2509
2520
/** A by-name parameter type of the form `=> T`, or the type of a method with no parameter list. */
@@ -3651,9 +3662,9 @@ object Types {
3651
3662
this (y, hi)
3652
3663
}
3653
3664
3654
- case tp @ MethodType (pnames, ptypes) =>
3665
+ case tp : MethodType =>
3655
3666
variance = - variance
3656
- val y = foldOver(x, ptypes )
3667
+ val y = foldOver(x, tp.paramTypes )
3657
3668
variance = - variance
3658
3669
this (y, tp.resultType)
3659
3670
0 commit comments