aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Typer.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-10-30 19:11:19 +0100
committerMartin Odersky <odersky@gmail.com>2015-10-30 19:11:23 +0100
commitb80b179d6fbb92c8f6ff3616cec1f3aab5106799 (patch)
tree3c22873902406337024eaa00ff51189405f22ad6 /src/dotty/tools/dotc/typer/Typer.scala
parent9fbb9c9c9b6050183dd71b8541a63fc6ebf9e2a6 (diff)
downloaddotty-b80b179d6fbb92c8f6ff3616cec1f3aab5106799.tar.gz
dotty-b80b179d6fbb92c8f6ff3616cec1f3aab5106799.tar.bz2
dotty-b80b179d6fbb92c8f6ff3616cec1f3aab5106799.zip
Also handle SAM functions when adaptiing arity of case lambdas.
Diffstat (limited to 'src/dotty/tools/dotc/typer/Typer.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala27
1 files changed, 13 insertions, 14 deletions
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index 4c07e07de..15ce59c8b 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -502,6 +502,16 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
assignType(cpy.If(tree)(cond1, thenp2, elsep2), thenp2, elsep2)
}
+ private def decomposeProtoFunction(pt: Type, defaultArity: Int)(implicit ctx: Context): (List[Type], Type) = pt match {
+ case _ if defn.isFunctionType(pt) =>
+ (pt.dealias.argInfos.init, pt.dealias.argInfos.last)
+ case SAMType(meth) =>
+ val mt @ MethodType(_, paramTypes) = meth.info
+ (paramTypes, mt.resultType)
+ case _ =>
+ (List.range(0, defaultArity) map alwaysWildcardType, WildcardType)
+ }
+
def typedFunction(tree: untpd.Function, pt: Type)(implicit ctx: Context) = track("typedFunction") {
val untpd.Function(args, body) = tree
if (ctx.mode is Mode.Type)
@@ -509,15 +519,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
untpd.TypeTree(defn.FunctionClass(args.length).typeRef), args :+ body), pt)
else {
val params = args.asInstanceOf[List[untpd.ValDef]]
- val (protoFormals, protoResult): (List[Type], Type) = pt match {
- case _ if defn.isFunctionType(pt) =>
- (pt.dealias.argInfos.init, pt.dealias.argInfos.last)
- case SAMType(meth) =>
- val mt @ MethodType(_, paramTypes) = meth.info
- (paramTypes, mt.resultType)
- case _ =>
- (params map alwaysWildcardType, WildcardType)
- }
+ val (protoFormals, protoResult) = decomposeProtoFunction(pt, params.length)
def refersTo(arg: untpd.Tree, param: untpd.ValDef): Boolean = arg match {
case Ident(name) => name == param.name
@@ -629,11 +631,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
def typedMatch(tree: untpd.Match, pt: Type)(implicit ctx: Context) = track("typedMatch") {
tree.selector match {
case EmptyTree =>
- val arity = pt match {
- case defn.FunctionType(args, _) => args.length
- case _ => 1
- }
- typed(desugar.makeCaseLambda(tree.cases, arity) withPos tree.pos, pt)
+ val (protoFormals, _) = decomposeProtoFunction(pt, 1)
+ typed(desugar.makeCaseLambda(tree.cases, protoFormals.length) withPos tree.pos, pt)
case _ =>
val sel1 = typedExpr(tree.selector)
val selType = widenForMatchSelector(