summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan@lightbend.com>2016-07-27 11:18:08 -0700
committerAdriaan Moors <adriaan@lightbend.com>2016-08-12 16:39:31 -0700
commit228d1b1ceb7643df1313672cd620cddb1a429029 (patch)
tree4fb946f9fe8a03cf759f194b94e17c8544bbd4fb /spec
parent618d42c747955a43557655bdc0c4281fec5a7923 (diff)
downloadscala-228d1b1ceb7643df1313672cd620cddb1a429029.tar.gz
scala-228d1b1ceb7643df1313672cd620cddb1a429029.tar.bz2
scala-228d1b1ceb7643df1313672cd620cddb1a429029.zip
Propagate overloaded function type to expected arg type
Infer missing parameter types for function literals passed to higher-order overloaded methods by deriving the expected argument type from the function types in the overloaded method type's argument types. This eases the pain caused by methods becoming overloaded because SAM types and function types are compatible, which used to disable parameter type inference because for overload resolution arguments are typed without expected type, while typedFunction needs the expected type to infer missing parameter types for function literals. It also aligns us with dotty. The special case for function literals seems reasonable, as it has precedent, and it just enables the special case in typing function literals (derive the param types from the expected type). Since this does change type inference, you can opt out using the Scala 2.11 source level. Fix scala/scala-dev#157
Diffstat (limited to 'spec')
-rw-r--r--spec/06-expressions.md11
1 files changed, 8 insertions, 3 deletions
diff --git a/spec/06-expressions.md b/spec/06-expressions.md
index 30ad73a3cd..1ecba5adf1 100644
--- a/spec/06-expressions.md
+++ b/spec/06-expressions.md
@@ -1426,9 +1426,14 @@ Let $\mathscr{B}$ be the set of alternatives in $\mathscr{A}$ that are [_applica
to expressions $(e_1 , \ldots , e_n)$ of types $(\mathit{shape}(e_1) , \ldots , \mathit{shape}(e_n))$.
If there is precisely one alternative in $\mathscr{B}$, that alternative is chosen.
-Otherwise, let $S_1 , \ldots , S_m$ be the vector of types obtained by
-typing each argument with an undefined expected type. For every
-member $m$ in $\mathscr{B}$ one determines whether it is applicable
+Otherwise, let $S_1 , \ldots , S_m$ be the list of types obtained by typing each argument as follows.
+An argument `$e_i$` of the shape `($p_1$: $T_1 , \ldots , p_n$: $T_n$) => $b$` where one of the `$T_i$` is missing,
+i.e., a function literal with a missing parameter type, is typed with an expected function type that
+propagates the least upper bound of the fully defined types of the corresponding parameters of
+the ([SAM-converted](#sam-conversion)) function types specified by the `$i$`th argument type found in each alternative.
+All other arguments are typed with an undefined expected type.
+
+For every member $m$ in $\mathscr{B}$ one determines whether it is applicable
to expressions ($e_1 , \ldots , e_m$) of types $S_1, \ldots , S_m$.
It is an error if none of the members in $\mathscr{B}$ is applicable. If there is one