Skip to content

Commit

Permalink
Interface type and subtype rule fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
eernstg committed Jan 7, 2022
1 parent 264652b commit f5cb6da
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions specification/dartLangSpec.tex
Original file line number Diff line number Diff line change
Expand Up @@ -19947,7 +19947,8 @@ \section{Types}
\LMLabel{types}

\LMHash{}%
Dart supports optional typing based on interface types.
Dart supports optional typing based on interface types
(\ref{interfaceTypes}).

\rationale{%
The type system is unsound, due to the covariance of generic classes.
Expand Down Expand Up @@ -20747,8 +20748,7 @@ \subsection{Subtypes}
T \in \{\code{Object?}, \DYNAMIC, \VOID\}}{S}{T}
% ------------------------------------------------ Right Object
\RuleRaw{\SrnRightObjectFour}{%
\mbox{$S$ is an interface type,}\\
\mbox{a function type, or \FUNCTION}}{S}{\code{Object}}
\mbox{$S$ is an interface type or \FUNCTION}}{S}{\code{Object}}
% ------------------------------------------------ Left Null 2
\Rule{\SrnNullTwo}{\code{Null}}{T}{%
\code{Null}}{\code{FutureOr<$T$>}}
Expand Down Expand Up @@ -21123,8 +21123,7 @@ \subsubsection{Informal Subtype Rule Descriptions}
\Item{\SrnBottom}{Bottom}
\code{Never} is a subtype of every type.
\Item{\SrnRightObjectFour}{Right Object}
Interface types, function types, and \FUNCTION{}
are subtypes of \code{Object}.
Interface types and \FUNCTION{} are subtypes of \code{Object}.
\Item{\SrnNullOne}{Null Nullable}
\code{Null} is a subtype of every type of the form \code{$T$?}.
\Item{\SrnNullTwo}{Null FutureOr}
Expand Down Expand Up @@ -21312,7 +21311,7 @@ \subsection{Type Nullability}
\item \code{Never}.
\item Any function type.
\item The type \FUNCTION.
\item Any interface type except \code{Null}.
\item Any interface type.
\item \code{FutureOr<$S$>}, for any non-nullable type $S$.
\item Any type variable $X$ whose bound is non-nullable.
\item Any type of the form \code{$X$\,\&\,$S$}, where
Expand Down Expand Up @@ -22631,15 +22630,13 @@ \subsubsection{The Standard Upper Bound of Distinct Interface Types}

\LMHash{}%
We define the auxiliary function \NominalTypeDepthName{}
on interface types and \code{Object?} as follows:
on interface types as follows:

\begin{itemize}
\item
\DefEquals{\NominalTypeDepth{Object?}}{0}.
\item
\DefEquals{\NominalTypeDepth{Object}}{1}.
\item
\DefEquals{\NominalTypeDepth{Null}}{1}.
% We could make it 1 rather than 0, to "reserve space" for `Object?`,
% but this function is never used with `Object?` anyway.
\DefEquals{\NominalTypeDepth{Object}}{0}.
\item
Let $T$ be a class or a mixin,
and let $M$ be the set of immediate superinterfaces of $T$.
Expand All @@ -22648,10 +22645,6 @@ \subsubsection{The Standard Upper Bound of Distinct Interface Types}
$\metavar{max}\,\{\;\NominalTypeDepth{$S$}\;|\;S\;\in M\;\}$.
\end{itemize}

\commentary{%

}

\LMHash{}%
\BlindDefineSymbol{I, J, M}%
The algorithm that determines
Expand Down Expand Up @@ -23040,21 +23033,22 @@ \subsection{Interface Types}
(\ref{typedef}).
We say that $T$ is an \Index{interface type} if{}f
$T'$ is of the form \code{$C$<\List{T}{1}{k}>},
where $C$ denotes a class different from \code{Never},
where $C$ denotes a class different from \code{Never} and \code{Null},
or $C$ denotes a mixin.

\commentary{%
Note that \List{T}{1}{k} can be arbitrary types.
Non-generic classes are included because we can have $k = 0$.

In particular, the following types are \emph{not} interface types:
\VOID, \DYNAMIC, \FUNCTION, \code{FutureOr<$T$>} for any $T$, \code{Never},
\VOID, \DYNAMIC, \FUNCTION, \code{FutureOr<$T$>} for any $T$,
\code{Never}, \code{Null},
any function type, any type variable, any intersection type,
and any type of the form \code{$T$?}.

Conversely, built-in classes
like \code{Object}, \code{Null}, \code{num}, \code{int},
\code{String}, and \code{Exception} are interface types,
Conversely, built-in classes like, e.g.,
\code{Object}, \code{num}, \code{int}, \code{String}, and \code{Exception}
are interface types,
and so are
\code{Future<$T$>}, \code{Stream<$T$>}, \code{Iterable<$T$>},
\code{List<$T$>}, \code{Map<$S$,\,\,$T$}, and \code{Set<$T$>},
Expand Down

0 comments on commit f5cb6da

Please sign in to comment.