File tree 2 files changed +16
-8
lines changed
compiler/src/dotty/tools/dotc 2 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -273,19 +273,24 @@ trait UntypedTreeInfo extends TreeInfo[Untyped] { self: Trees.Instance[Untyped]
273
273
case _ => false
274
274
}
275
275
276
- def isFunctionWithUnknownParamType (tree : Tree ): Boolean = tree match {
276
+ def functionWithUnknownParamType (tree : Tree ): Option [ Tree ] = tree match {
277
277
case Function (args, _) =>
278
- args.exists {
278
+ if ( args.exists {
279
279
case ValDef (_, tpt, _) => tpt.isEmpty
280
280
case _ => false
281
- }
281
+ }) Some (tree)
282
+ else None
282
283
case Match (EmptyTree , _) =>
283
- true
284
+ Some (tree)
284
285
case Block (Nil , expr) =>
285
- isFunctionWithUnknownParamType(expr)
286
- case _ => false
286
+ functionWithUnknownParamType(expr)
287
+ case _ =>
288
+ None
287
289
}
288
290
291
+ def isFunctionWithUnknownParamType (tree : Tree ): Boolean =
292
+ functionWithUnknownParamType(tree).isDefined
293
+
289
294
/** Is `tree` an implicit function or closure, possibly nested in a block? */
290
295
def isImplicitClosure (tree : Tree )(implicit ctx : Context ): Boolean = unsplice(tree) match {
291
296
case Function ((param : untpd.ValDef ) :: _, _) => param.mods.is(Implicit )
Original file line number Diff line number Diff line change @@ -1402,7 +1402,8 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
1402
1402
case ValDef (_, tpt, _) => tpt.isEmpty
1403
1403
case _ => false
1404
1404
}
1405
- if (untpd.isFunctionWithUnknownParamType(arg)) {
1405
+ val fn = untpd.functionWithUnknownParamType(arg)
1406
+ if (fn.isDefined) {
1406
1407
def isUniform [T ](xs : List [T ])(p : (T , T ) => Boolean ) = xs.forall(p(_, xs.head))
1407
1408
val formalsForArg : List [Type ] = altFormals.map(_.head)
1408
1409
def argTypesOfFormal (formal : Type ): List [Type ] =
@@ -1422,7 +1423,9 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
1422
1423
// type of the i'th parameter of the closure.
1423
1424
if (isUniform(ps)(ctx.typeComparer.isSameTypeWhenFrozen(_, _))) ps.head
1424
1425
else WildcardType )
1425
- def isPartial = formalsForArg.forall(_.isRef(defn.PartialFunctionClass ))
1426
+ def isPartial = // we should generate a partial function for the arg
1427
+ fn.get.isInstanceOf [untpd.Match ] &&
1428
+ formalsForArg.exists(_.isRef(defn.PartialFunctionClass ))
1426
1429
val commonFormal =
1427
1430
if (isPartial) defn.PartialFunctionOf (commonParamTypes.head, newTypeVar(TypeBounds .empty))
1428
1431
else defn.FunctionOf (commonParamTypes, WildcardType )
You can’t perform that action at this time.
0 commit comments