@@ -1227,6 +1227,8 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
1227
1227
def typeShape (tree : untpd.Tree ): Type = tree match {
1228
1228
case untpd.Function (args, body) =>
1229
1229
defn.FunctionOf (args map Function .const(defn.AnyType ), typeShape(body))
1230
+ case Match (EmptyTree , _) =>
1231
+ defn.PartialFunctionType .appliedTo(defn.AnyType :: defn.NothingType :: Nil )
1230
1232
case _ =>
1231
1233
defn.NothingType
1232
1234
}
@@ -1271,7 +1273,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
1271
1273
alts filter (alt => sizeFits(alt, alt.widen))
1272
1274
1273
1275
def narrowByShapes (alts : List [TermRef ]): List [TermRef ] = {
1274
- if (normArgs exists (_. isInstanceOf [ untpd.Function ]) )
1276
+ if (normArgs exists untpd.isFunctionWithUnknownParamType )
1275
1277
if (hasNamedArg(args)) narrowByTrees(alts, args map treeShape, resultType)
1276
1278
else narrowByTypes(alts, normArgs map typeShape, resultType)
1277
1279
else
@@ -1351,33 +1353,31 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
1351
1353
case ValDef (_, tpt, _) => tpt.isEmpty
1352
1354
case _ => false
1353
1355
}
1354
- arg match {
1355
- case arg : untpd.Function if arg.args.exists(isUnknownParamType) =>
1356
- def isUniform [T ](xs : List [T ])(p : (T , T ) => Boolean ) = xs.forall(p(_, xs.head))
1357
- val formalsForArg : List [Type ] = altFormals.map(_.head)
1358
- // For alternatives alt_1, ..., alt_n, test whether formal types for current argument are of the form
1359
- // (p_1_1, ..., p_m_1) => r_1
1360
- // ...
1361
- // (p_1_n, ..., p_m_n) => r_n
1362
- val decomposedFormalsForArg : List [Option [(List [Type ], Type , Boolean )]] =
1363
- formalsForArg.map(defn.FunctionOf .unapply)
1364
- if (decomposedFormalsForArg.forall(_.isDefined)) {
1365
- val formalParamTypessForArg : List [List [Type ]] =
1366
- decomposedFormalsForArg.map(_.get._1)
1367
- if (isUniform(formalParamTypessForArg)((x, y) => x.length == y.length)) {
1368
- val commonParamTypes = formalParamTypessForArg.transpose.map(ps =>
1369
- // Given definitions above, for i = 1,...,m,
1370
- // ps(i) = List(p_i_1, ..., p_i_n) -- i.e. a column
1371
- // If all p_i_k's are the same, assume the type as formal parameter
1372
- // type of the i'th parameter of the closure.
1373
- if (isUniform(ps)(ctx.typeComparer.isSameTypeWhenFrozen(_, _))) ps.head
1374
- else WildcardType )
1375
- val commonFormal = defn.FunctionOf (commonParamTypes, WildcardType )
1376
- overload.println(i " pretype arg $arg with expected type $commonFormal" )
1377
- pt.typedArg(arg, commonFormal)
1378
- }
1356
+ if (untpd.isFunctionWithUnknownParamType(arg)) {
1357
+ def isUniform [T ](xs : List [T ])(p : (T , T ) => Boolean ) = xs.forall(p(_, xs.head))
1358
+ val formalsForArg : List [Type ] = altFormals.map(_.head)
1359
+ // For alternatives alt_1, ..., alt_n, test whether formal types for current argument are of the form
1360
+ // (p_1_1, ..., p_m_1) => r_1
1361
+ // ...
1362
+ // (p_1_n, ..., p_m_n) => r_n
1363
+ val decomposedFormalsForArg : List [Option [(List [Type ], Type , Boolean )]] =
1364
+ formalsForArg.map(defn.FunctionOf .unapply)
1365
+ if (decomposedFormalsForArg.forall(_.isDefined)) {
1366
+ val formalParamTypessForArg : List [List [Type ]] =
1367
+ decomposedFormalsForArg.map(_.get._1)
1368
+ if (isUniform(formalParamTypessForArg)((x, y) => x.length == y.length)) {
1369
+ val commonParamTypes = formalParamTypessForArg.transpose.map(ps =>
1370
+ // Given definitions above, for i = 1,...,m,
1371
+ // ps(i) = List(p_i_1, ..., p_i_n) -- i.e. a column
1372
+ // If all p_i_k's are the same, assume the type as formal parameter
1373
+ // type of the i'th parameter of the closure.
1374
+ if (isUniform(ps)(ctx.typeComparer.isSameTypeWhenFrozen(_, _))) ps.head
1375
+ else WildcardType )
1376
+ val commonFormal = defn.FunctionOf (commonParamTypes, WildcardType )
1377
+ overload.println(i " pretype arg $arg with expected type $commonFormal" )
1378
+ pt.typedArg(arg, commonFormal)
1379
1379
}
1380
- case _ =>
1380
+ }
1381
1381
}
1382
1382
recur(altFormals.map(_.tail), args1)
1383
1383
case _ =>
0 commit comments