@@ -1672,19 +1672,30 @@ object Types {
16721672 case _ => resultType
16731673 }
16741674
1675- /** Determine the expected function type from the prototype. If multiple
1676- * function types are found in a union or intersection, their intersection
1677- * is returned. If no function type is found, Any is returned.
1675+ /** Determine the expected function type from the prototype.
1676+ * If no function type is found, NoType is returned. If multiple
1677+ * function types are found in an intersection, their intersection
1678+ * is returned. This works since `&` invokes `TypeComparer.distributeAnd`, which
1679+ * ensures that `(A1 => B1) & (A2 => B2)` simplifies to `(A1 | A2) => (B1 & B2)`,
1680+ * so the result is again a function type. An analogous distribution mechanism
1681+ * does not exist for `|`. Therefore, a union of function types also yields `NoType`,
1682+ * since we cannot determine a single expected function type.
16781683 */
16791684 def findFunctionType (using Context ): Type = dealias match
1680- case tp : AndOrType =>
1685+ case tp : AndType =>
16811686 tp.tp1.findFunctionType & tp.tp2.findFunctionType
1687+ case tp : OrType =>
1688+ val tf1 = tp.tp1.findFunctionType
1689+ val tf2 = tp.tp2.findFunctionType
1690+ if ! tf1.exists then tf2
1691+ else if ! tf2.exists then tf1
1692+ else NoType
16821693 case t if defn.isNonRefinedFunction(t) =>
16831694 t
16841695 case t @ SAMType (_) =>
16851696 t
16861697 case _ =>
1687- defn. AnyType
1698+ NoType
16881699
16891700 /** This type seen as a TypeBounds */
16901701 final def bounds (using Context ): TypeBounds = this match {
0 commit comments