Skip to content

Commit b1f8bd7

Browse files
committed
WIP
1 parent 0e07a88 commit b1f8bd7

File tree

1 file changed

+38
-42
lines changed

1 file changed

+38
-42
lines changed

specification/dartLangSpec.tex

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -22445,16 +22445,17 @@ \subsection{Function Types}
2244522445

2244622446
\LMHash{}%
2244722447
A function object is always an instance of some class $C$ that implements
22448-
the class \FUNCTION{} (\ref{functionType}),
22449-
and which has a method named \CALL,
22450-
whose signature is the function type $C$ itself.
22448+
a function type $F$ which is a subtype of the class \FUNCTION{}
22449+
(\ref{functionType}).
22450+
The function object has a method named \CALL,
22451+
whose signature is said function type $F$.
2245122452
\commentary{%
2245222453
Consequently, all function types are subtypes of \FUNCTION{}
2245322454
(\ref{subtypes}).%
2245422455
}
2245522456

2245622457

22457-
\subsection{Type \FUNCTION}
22458+
\subsection{Type Function}
2245822459
\LMLabel{functionType}
2245922460

2246022461
\LMHash{}%
@@ -22476,13 +22477,13 @@ \subsection{Type \FUNCTION}
2247622477
\LMHash{}%
2247722478
If a mixin application mixes \FUNCTION{} onto a superclass, it follows the
2247822479
normal rules for mixin-application, but since the result of that mixin
22479-
application is equivalent to a class with \code{implements Function}, and
22480+
application is equivalent to a class with \code{implements \FUNCTION}, and
2248022481
that clause has no effect, the resulting class also does not
2248122482
implement \FUNCTION.
2248222483
\commentary{%
2248322484
The \FUNCTION{} class declares no concrete instance members,
22484-
so the mixin application creates a sub-class of
22485-
the superclass with no new members and no new interfaces.%
22485+
so the mixin application creates a sub-class
22486+
of the superclass with no new members and no new interfaces.%
2248622487
}
2248722488

2248822489
\rationale{%
@@ -22495,7 +22496,7 @@ \subsection{Type \FUNCTION}
2249522496
}
2249622497

2249722498

22498-
\subsection{Type \DYNAMIC}
22499+
\subsection{Type dynamic}
2249922500
\LMLabel{typeDynamic}
2250022501

2250122502
\LMHash{}%
@@ -22636,7 +22637,7 @@ \subsection{Type \DYNAMIC}
2263622637
\metavar{typeArguments} is a list of actual
2263722638
type arguments derived from \synt{typeArguments}, and
2263822639
\metavar{arguments} is an actual argument list derived from \synt{arguments}.
22639-
It is a compile-time error if \id{} is the name of
22640+
It is a \Error{compile-time error} if \id{} is the name of
2264022641
a non-generic method declared in \code{Object}.
2264122642
\commentary{%
2264222643
No generic methods are declared in \code{Object}.
@@ -22711,7 +22712,7 @@ \subsection{Type FutureOr}
2271122712
That is, \code{FutureOr} is in a sense
2271222713
the union of $T$ and the corresponding future type.
2271322714
The last point guarantees that
22714-
\code{FutureOr<$T$>} <: \code{Object},
22715+
\code{FutureOr<$T$>} <: \code{Object?},
2271522716
and also that \code{FutureOr} is covariant in its type parameter,
2271622717
just like class types:
2271722718
if $S$ <: $T$ then \code{FutureOr<$S$>} <: \code{FutureOr<$T$>}.%
@@ -22720,7 +22721,7 @@ \subsection{Type FutureOr}
2272022721
\LMHash{}%
2272122722
If the type arguments passed to \code{FutureOr} would incur compile-time errors
2272222723
if applied to a normal generic class with one type parameter,
22723-
the same compile-time errors are issued for \code{FutureOr}.
22724+
the same \Error{compile-time errors} are issued for \code{FutureOr}.
2272422725
The name \code{FutureOr} as an expression
2272522726
denotes a \code{Type} object representing the type \code{FutureOr<dynamic>}.
2272622727

@@ -22765,7 +22766,7 @@ \subsection{Type FutureOr}
2276522766
\end{itemize}
2276622767

2276722768

22768-
\subsection{Type Void}
22769+
\subsection{Type void}
2276922770
\LMLabel{typeVoid}
2277022771

2277122772
\LMHash{}%
@@ -22795,16 +22796,16 @@ \subsection{Type Void}
2279522796
\commentary{%
2279622797
The type \VOID{} is a top type
2279722798
(\ref{superBoundedTypes}),
22798-
so \VOID{} and \code{Object} are subtypes of each other
22799+
so \VOID{} and \code{Object?} are subtypes of each other
2279922800
(\ref{subtypes}),
2280022801
which also implies that any object can be
2280122802
the value of an expression of type \VOID.
2280222803
%
2280322804
Consequently, any instance of type \code{Type} which reifies the type \VOID{}
2280422805
must compare equal (according to the \lit{==} operator \ref{equality})
22805-
to any instance of \code{Type} which reifies the type \code{Object}
22806+
to any instance of \code{Type} which reifies the type \code{Object?}
2280622807
(\ref{dynamicTypeSystem}).
22807-
It is not guaranteed that \code{identical(\VOID, Object)} evaluates to true.
22808+
It is not guaranteed that those two reified types are identical.
2280822809
In fact, it is not recommended that implementations strive to achieve this,
2280922810
because it may be more important to ensure that diagnostic messages
2281022811
(including stack traces and dynamic error messages)
@@ -22816,7 +22817,7 @@ \subsection{Type Void}
2281622817
In support of the notion
2281722818
that the value of an expression with static type \VOID{} should be discarded,
2281822819
such objects can only be used in specific situations:
22819-
The occurrence of an expression of type \VOID{} is a compile-time error
22820+
The occurrence of an expression of type \VOID{} is a \Error{compile-time error}
2282022821
unless it is permitted according to one of the following rules.
2282122822

2282222823
\begin{itemize}
@@ -22846,6 +22847,7 @@ \subsection{Type Void}
2284622847
where it is not an error to have it.%
2284722848
}
2284822849
\item
22850+
%% This relies on \IsMoreTopType{\VOID}{$T$} = \VOID.
2284922851
In a conditional expression \code{$e$\,?\,$e_1$\,:\,$e_2$},
2285022852
$e_1$ and $e_2$ may have type \VOID.
2285122853
\rationale{%
@@ -22855,20 +22857,13 @@ \subsection{Type Void}
2285522857
in some context where it is not an error to have it.%
2285622858
}
2285722859
\item
22860+
%% This relies on \IsMoreTopType{\VOID}{$T$} = \VOID.
2285822861
In a null coalescing expression \code{$e_1$\,??\,$e_2$},
2285922862
$e_2$ may have type \VOID.
2286022863
\rationale{%
2286122864
The static type of the null coalescing expression is then \VOID,
2286222865
which in turn restricts where it can occur.%
2286322866
}
22864-
\item
22865-
In an expression of the form \code{\AWAIT\,\,$e$}, $e$ may have type \VOID.
22866-
\rationale{%
22867-
This rule was adopted because it was a substantial breaking change
22868-
to turn this situation into an error
22869-
at the time where the treatment of \VOID{} was changed.
22870-
Tools may choose to give a hint in such cases.%
22871-
}
2287222867
\item
2287322868
\commentary{%
2287422869
In a return statement \code{\RETURN\,$e$;},
@@ -22950,13 +22945,13 @@ \subsection{Type Void}
2295022945
Finally, we need to address situations involving implicit usage of
2295122946
an object whose static type can be \VOID.
2295222947
%
22953-
It is a compile-time error for a for-in statement to have an iterator
22948+
It is a \Error{compile-time error} for a for-in statement to have an iterator
2295422949
expression of type $T$ such that \code{Iterator<\VOID{}>}
2295522950
is the most specific instantiation of \code{Iterator}
2295622951
that is a superinterface of $T$, unless the
2295722952
iteration variable has type \VOID.
2295822953
%
22959-
It is a compile-time error for an asynchronous for-in statement
22954+
It is a \Error{compile-time error} for an asynchronous for-in statement
2296022955
to have a stream expression of type $T$
2296122956
such that \code{Stream<\VOID{}>} is the most specific
2296222957
instantiation of \code{Stream} that is a superinterface of $T$,
@@ -22965,7 +22960,7 @@ \subsection{Type Void}
2296522960
\commentary{Here are some examples:}
2296622961

2296722962
\begin{dartCode}
22968-
\FOR{} (Object x in <\VOID>[]) \{\} // \comment{Error.}
22963+
\FOR{} (Object? x in <\VOID>[]) \{\} // \comment{Error.}
2296922964
\AWAIT{} \FOR{} (int x \IN{} new Stream<\VOID{}>.empty()) \{\} // \comment{Error.}
2297022965
\FOR{} (\VOID{} x \IN{} <\VOID{}>[]) \{\ldots\} // \comment{OK.}
2297122966
\FOR (\VAR{} x \IN{} <\VOID{}>[]) \{\ldots\} // \comment{OK, type of x inferred.}
@@ -23013,22 +23008,22 @@ \subsubsection{Void Soundness}
2301323008
\ABSTRACT{} \CLASS A<X> \{
2301423009
final X x;
2301523010
A(this.x);
23016-
Object foo(X x);
23011+
Object? foo(X x);
2301723012
\}
2301823013
\\
2301923014
\CLASS{} B<X> \EXTENDS{} A<X> \{
2302023015
B(X x): super(x);
23021-
Object foo(Object x) => x;
23016+
Object? foo(Object? x) => x;
2302223017
\}
2302323018
\\
23024-
Object f<X>(X x) => x;
23019+
Object? f<X>(X x) => x;
2302523020
\\
2302623021
\VOID{} main() \{
2302723022
\VOID x = 42;
2302823023
print(f(x)); // \comment{(1)}
2302923024
\\
2303023025
A<\VOID{}> a = B<\VOID{}>(x);
23031-
A<Object> aObject = a;
23026+
A<Object?> aObject = a;
2303223027
print(aObject.x); // \comment{(2)}
2303323028
print(a.foo(x)); // \comment{(3)}
2303423029
\}
@@ -23045,25 +23040,25 @@ \subsubsection{Void Soundness}
2304523040
which is or contains a type variable whose value could be \VOID,
2304623041
so we are allowed to return \code{x} in the body of \code{f},
2304723042
even though this means that we indirectly get access to the value
23048-
of an expression of type \VOID, under the static type \code{Object}.
23043+
of an expression of type \VOID, under the static type \code{Object?}.
2304923044

2305023045
At (2), we indirectly obtain access to the value of
2305123046
the variable \code{x} with type \VOID,
2305223047
because we use an assignment to get access to the instance of \code{B}
2305323048
which was created with type argument \VOID{} under the type
23054-
\code{A<Object>}.
23055-
Note that \code{A<Object>} and \code{A<\VOID{}>} are subtypes of each other,
23049+
\code{A<Object?>}.
23050+
Note that \code{A<Object?>} and \code{A<\VOID{}>} are subtypes of each other,
2305623051
that is, they are equivalent according to the subtype rules,
2305723052
so neither static nor dynamic type checks will fail.
2305823053

2305923054
At (3), we indirectly obtain access to the value of
2306023055
the variable \code{x} with type \VOID{}
23061-
under the static type \code{Object},
23056+
under the static type \code{Object?},
2306223057
because the statically known method signature of \code{foo}
2306323058
has parameter type \VOID,
2306423059
but the actual implementation of \code{foo} which is invoked
23065-
is an override whose parameter type is \code{Object},
23066-
which is allowed because \code{Object} and \VOID{} are both top types.%
23060+
is an override whose parameter type is \code{Object?},
23061+
which is allowed because \code{Object?} and \VOID{} are both top types.%
2306723062
}
2306823063

2306923064
\rationale{%
@@ -23084,7 +23079,7 @@ \subsubsection{Void Soundness}
2308423079
from one variable or parameter to the next one, all with type \VOID,
2308523080
explicitly, or as the value of a type parameter.
2308623081
In particular, we could require that method overrides should
23087-
never override return type \code{Object} by return type \VOID,
23082+
never override return type \code{Object?} by return type \VOID,
2308823083
or parameter types in the opposite direction;
2308923084
parameterized types with type argument \VOID{} could not be assigned
2309023085
to variables where the corresponding type argument is anything other than
@@ -23132,7 +23127,7 @@ \subsection{Parameterized Types}
2313223127
Let $T$ be a parameterized type \code{$G$<$S_1, \ldots,\ S_n$>}.
2313323128

2313423129
\LMHash{}%
23135-
It is a compile-time error if $G$ is not a generic type,
23130+
It is a \Error{compile-time error} if $G$ is not a generic type,
2313623131
or $G$ is a generic type,
2313723132
but the number of formal type parameters in the declaration of $G$ is not $n$.
2313823133
Otherwise, let
@@ -23147,7 +23142,7 @@ \subsection{Parameterized Types}
2314723142
or $T$ is not well-bounded (\ref{superBoundedTypes}).
2314823143

2314923144
\LMHash{}%
23150-
It is a compile-time error if $T$ is malbounded.
23145+
It is a \Error{compile-time error} if $T$ is malbounded.
2315123146

2315223147
\LMHash{}%
2315323148
$T$ is evaluated as follows.
@@ -23171,7 +23166,8 @@ \subsection{Parameterized Types}
2317123166
%% replaced by the bottom type (`Null`, for now) in locations of the member
2317223167
%% type where it occurs contravariantly. For instance, `c.f` should have
2317323168
%% static type `void Function(Null)` when `c` has static type `C<T>` for any
23174-
%% `T`, and we have `class C<X> { void Function(X) f; }`.
23169+
%% `T`, and we have `class C<X> { void Function(X) f; }`. Cf. issue
23170+
%% https://github.com/dart-lang/language/issues/297.
2317523171

2317623172

2317723173
\subsubsection{Actual Types}
@@ -23352,7 +23348,7 @@ \subsubsection{Reserved Words}
2335223348
\LMHash{}%
2335323349
A \Index{reserved word} can only be used in the syntactic positions
2335423350
specified by the grammar.
23355-
In particular, a compile-time error occurs if a reserved word is used
23351+
In particular, a \Error{compile-time error} occurs if a reserved word is used
2335623352
where an identifier is expected.
2335723353

2335823354
\commentary{%

0 commit comments

Comments
 (0)