This commit is contained in:
JanUlrich 2024-04-17 16:45:24 +02:00
parent 6702d9b0cb
commit 0c51692936

View File

@ -17,13 +17,35 @@ List<String> ls = emptyList();
Local type inference \cite{javaTIisBroken} is able to find a type substitution $\sigma$ satisfying Local type inference \cite{javaTIisBroken} is able to find a type substitution $\sigma$ satisfying
$\overline{\type{A} <: \sigma(\type{F}) }, \sigma(\type{R}) <: \type{E}$. $\overline{\type{A} <: \sigma(\type{F}) }, \sigma(\type{R}) <: \type{E}$.
It is important that $\overline{\type{A}}$ and $\type{E}$ are given types and do not contain
type placeholders already used in $\overline{\type{F}}$.
The type parameters are not allowed on the left side of $A <: F$ The type parameters are not allowed on the left side of $A <: F$
We can generate method calls where this is the case. The second call to \texttt{get}. We can generate method calls where this is the case. The second call to \texttt{get}.
Local type inference is based on matching and not unification.
When calling the \texttt{emptyList} method without context its return value will be set to a \texttt{List<Object>}.
The following Java code snippet is incorrect, because \texttt{emptyList()} returns
a \texttt{List<Object>} instead of the required \texttt{List<String>}.
\begin{verbatim} \begin{verbatim}
emptyList().get(0).get(0); emptyList().add(new List<String>())
.get(0)
.get(0);
\end{verbatim} \end{verbatim}
%List<String> <. A
%List<A> <: List<B>, B <: List<C>
% B = A and therefore A on the left and right side of constraints.
% this makes matching impossible
\begin{verbatim}
this.<List<String>>emptyList().add(new List<String>())
.get(0)
.get(0);
\end{verbatim}
Local type inference cannot deal with type inference during the algorithm.
If the left side contains unknown type parameters.
\begin{verbatim} \begin{verbatim}
import java.util.ArrayList; import java.util.ArrayList;