@@ -502,22 +502,24 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
502
502
assignType(cpy.If (tree)(cond1, thenp2, elsep2), thenp2, elsep2)
503
503
}
504
504
505
+ private def decomposeProtoFunction (pt : Type , defaultArity : Int )(implicit ctx : Context ): (List [Type ], Type ) = pt match {
506
+ case _ if defn.isFunctionType(pt) =>
507
+ (pt.dealias.argInfos.init, pt.dealias.argInfos.last)
508
+ case SAMType (meth) =>
509
+ val mt @ MethodType (_, paramTypes) = meth.info
510
+ (paramTypes, mt.resultType)
511
+ case _ =>
512
+ (List .range(0 , defaultArity) map alwaysWildcardType, WildcardType )
513
+ }
514
+
505
515
def typedFunction (tree : untpd.Function , pt : Type )(implicit ctx : Context ) = track(" typedFunction" ) {
506
516
val untpd .Function (args, body) = tree
507
517
if (ctx.mode is Mode .Type )
508
518
typed(cpy.AppliedTypeTree (tree)(
509
519
untpd.TypeTree (defn.FunctionClass (args.length).typeRef), args :+ body), pt)
510
520
else {
511
521
val params = args.asInstanceOf [List [untpd.ValDef ]]
512
- val (protoFormals, protoResult): (List [Type ], Type ) = pt match {
513
- case _ if defn.isFunctionType(pt) =>
514
- (pt.dealias.argInfos.init, pt.dealias.argInfos.last)
515
- case SAMType (meth) =>
516
- val mt @ MethodType (_, paramTypes) = meth.info
517
- (paramTypes, mt.resultType)
518
- case _ =>
519
- (params map alwaysWildcardType, WildcardType )
520
- }
522
+ val (protoFormals, protoResult) = decomposeProtoFunction(pt, params.length)
521
523
522
524
def refersTo (arg : untpd.Tree , param : untpd.ValDef ): Boolean = arg match {
523
525
case Ident (name) => name == param.name
@@ -629,7 +631,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
629
631
def typedMatch (tree : untpd.Match , pt : Type )(implicit ctx : Context ) = track(" typedMatch" ) {
630
632
tree.selector match {
631
633
case EmptyTree =>
632
- typed(desugar.makeCaseLambda(tree.cases) withPos tree.pos, pt)
634
+ val (protoFormals, _) = decomposeProtoFunction(pt, 1 )
635
+ typed(desugar.makeCaseLambda(tree.cases, protoFormals.length) withPos tree.pos, pt)
633
636
case _ =>
634
637
val sel1 = typedExpr(tree.selector)
635
638
val selType = widenForMatchSelector(
0 commit comments