@@ -22445,16 +22445,17 @@ \subsection{Function Types}
22445
22445
22446
22446
\LMHash{}%
22447
22447
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$.
22451
22452
\commentary{%
22452
22453
Consequently, all function types are subtypes of \FUNCTION{}
22453
22454
(\ref{subtypes}).%
22454
22455
}
22455
22456
22456
22457
22457
- \subsection{Type \FUNCTION }
22458
+ \subsection{Type Function }
22458
22459
\LMLabel{functionType}
22459
22460
22460
22461
\LMHash{}%
@@ -22476,13 +22477,13 @@ \subsection{Type \FUNCTION}
22476
22477
\LMHash{}%
22477
22478
If a mixin application mixes \FUNCTION{} onto a superclass, it follows the
22478
22479
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
22480
22481
that clause has no effect, the resulting class also does not
22481
22482
implement \FUNCTION.
22482
22483
\commentary{%
22483
22484
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.%
22486
22487
}
22487
22488
22488
22489
\rationale{%
@@ -22495,7 +22496,7 @@ \subsection{Type \FUNCTION}
22495
22496
}
22496
22497
22497
22498
22498
- \subsection{Type \DYNAMIC }
22499
+ \subsection{Type dynamic }
22499
22500
\LMLabel{typeDynamic}
22500
22501
22501
22502
\LMHash{}%
@@ -22636,7 +22637,7 @@ \subsection{Type \DYNAMIC}
22636
22637
\metavar{typeArguments} is a list of actual
22637
22638
type arguments derived from \synt{typeArguments}, and
22638
22639
\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
22640
22641
a non-generic method declared in \code{Object}.
22641
22642
\commentary{%
22642
22643
No generic methods are declared in \code{Object}.
@@ -22711,7 +22712,7 @@ \subsection{Type FutureOr}
22711
22712
That is, \code{FutureOr} is in a sense
22712
22713
the union of $T$ and the corresponding future type.
22713
22714
The last point guarantees that
22714
- \code{FutureOr<$T$>} <: \code{Object},
22715
+ \code{FutureOr<$T$>} <: \code{Object? },
22715
22716
and also that \code{FutureOr} is covariant in its type parameter,
22716
22717
just like class types:
22717
22718
if $S$ <: $T$ then \code{FutureOr<$S$>} <: \code{FutureOr<$T$>}.%
@@ -22720,7 +22721,7 @@ \subsection{Type FutureOr}
22720
22721
\LMHash{}%
22721
22722
If the type arguments passed to \code{FutureOr} would incur compile-time errors
22722
22723
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}.
22724
22725
The name \code{FutureOr} as an expression
22725
22726
denotes a \code{Type} object representing the type \code{FutureOr<dynamic>}.
22726
22727
@@ -22765,7 +22766,7 @@ \subsection{Type FutureOr}
22765
22766
\end{itemize}
22766
22767
22767
22768
22768
- \subsection{Type Void }
22769
+ \subsection{Type void }
22769
22770
\LMLabel{typeVoid}
22770
22771
22771
22772
\LMHash{}%
@@ -22795,16 +22796,16 @@ \subsection{Type Void}
22795
22796
\commentary{%
22796
22797
The type \VOID{} is a top type
22797
22798
(\ref{superBoundedTypes}),
22798
- so \VOID{} and \code{Object} are subtypes of each other
22799
+ so \VOID{} and \code{Object? } are subtypes of each other
22799
22800
(\ref{subtypes}),
22800
22801
which also implies that any object can be
22801
22802
the value of an expression of type \VOID.
22802
22803
%
22803
22804
Consequently, any instance of type \code{Type} which reifies the type \VOID{}
22804
22805
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? }
22806
22807
(\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 .
22808
22809
In fact, it is not recommended that implementations strive to achieve this,
22809
22810
because it may be more important to ensure that diagnostic messages
22810
22811
(including stack traces and dynamic error messages)
@@ -22816,7 +22817,7 @@ \subsection{Type Void}
22816
22817
In support of the notion
22817
22818
that the value of an expression with static type \VOID{} should be discarded,
22818
22819
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}
22820
22821
unless it is permitted according to one of the following rules.
22821
22822
22822
22823
\begin{itemize}
@@ -22846,6 +22847,7 @@ \subsection{Type Void}
22846
22847
where it is not an error to have it.%
22847
22848
}
22848
22849
\item
22850
+ %% This relies on \IsMoreTopType{\VOID}{$T$} = \VOID.
22849
22851
In a conditional expression \code{$e$\,?\,$e_1$\,:\,$e_2$},
22850
22852
$e_1$ and $e_2$ may have type \VOID.
22851
22853
\rationale{%
@@ -22855,20 +22857,13 @@ \subsection{Type Void}
22855
22857
in some context where it is not an error to have it.%
22856
22858
}
22857
22859
\item
22860
+ %% This relies on \IsMoreTopType{\VOID}{$T$} = \VOID.
22858
22861
In a null coalescing expression \code{$e_1$\,??\,$e_2$},
22859
22862
$e_2$ may have type \VOID.
22860
22863
\rationale{%
22861
22864
The static type of the null coalescing expression is then \VOID,
22862
22865
which in turn restricts where it can occur.%
22863
22866
}
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
- }
22872
22867
\item
22873
22868
\commentary{%
22874
22869
In a return statement \code{\RETURN\,$e$;},
@@ -22950,13 +22945,13 @@ \subsection{Type Void}
22950
22945
Finally, we need to address situations involving implicit usage of
22951
22946
an object whose static type can be \VOID.
22952
22947
%
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
22954
22949
expression of type $T$ such that \code{Iterator<\VOID{}>}
22955
22950
is the most specific instantiation of \code{Iterator}
22956
22951
that is a superinterface of $T$, unless the
22957
22952
iteration variable has type \VOID.
22958
22953
%
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
22960
22955
to have a stream expression of type $T$
22961
22956
such that \code{Stream<\VOID{}>} is the most specific
22962
22957
instantiation of \code{Stream} that is a superinterface of $T$,
@@ -22965,7 +22960,7 @@ \subsection{Type Void}
22965
22960
\commentary{Here are some examples:}
22966
22961
22967
22962
\begin{dartCode}
22968
- \FOR{} (Object x in <\VOID>[]) \{\} // \comment{Error.}
22963
+ \FOR{} (Object? x in <\VOID>[]) \{\} // \comment{Error.}
22969
22964
\AWAIT{} \FOR{} (int x \IN{} new Stream<\VOID{}>.empty()) \{\} // \comment{Error.}
22970
22965
\FOR{} (\VOID{} x \IN{} <\VOID{}>[]) \{\ldots\} // \comment{OK.}
22971
22966
\FOR (\VAR{} x \IN{} <\VOID{}>[]) \{\ldots\} // \comment{OK, type of x inferred.}
@@ -23013,22 +23008,22 @@ \subsubsection{Void Soundness}
23013
23008
\ABSTRACT{} \CLASS A<X> \{
23014
23009
final X x;
23015
23010
A(this.x);
23016
- Object foo(X x);
23011
+ Object? foo(X x);
23017
23012
\}
23018
23013
\\
23019
23014
\CLASS{} B<X> \EXTENDS{} A<X> \{
23020
23015
B(X x): super(x);
23021
- Object foo(Object x) => x;
23016
+ Object? foo(Object? x) => x;
23022
23017
\}
23023
23018
\\
23024
- Object f<X>(X x) => x;
23019
+ Object? f<X>(X x) => x;
23025
23020
\\
23026
23021
\VOID{} main() \{
23027
23022
\VOID x = 42;
23028
23023
print(f(x)); // \comment{(1)}
23029
23024
\\
23030
23025
A<\VOID{}> a = B<\VOID{}>(x);
23031
- A<Object> aObject = a;
23026
+ A<Object? > aObject = a;
23032
23027
print(aObject.x); // \comment{(2)}
23033
23028
print(a.foo(x)); // \comment{(3)}
23034
23029
\}
@@ -23045,25 +23040,25 @@ \subsubsection{Void Soundness}
23045
23040
which is or contains a type variable whose value could be \VOID,
23046
23041
so we are allowed to return \code{x} in the body of \code{f},
23047
23042
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? }.
23049
23044
23050
23045
At (2), we indirectly obtain access to the value of
23051
23046
the variable \code{x} with type \VOID,
23052
23047
because we use an assignment to get access to the instance of \code{B}
23053
23048
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,
23056
23051
that is, they are equivalent according to the subtype rules,
23057
23052
so neither static nor dynamic type checks will fail.
23058
23053
23059
23054
At (3), we indirectly obtain access to the value of
23060
23055
the variable \code{x} with type \VOID{}
23061
- under the static type \code{Object},
23056
+ under the static type \code{Object? },
23062
23057
because the statically known method signature of \code{foo}
23063
23058
has parameter type \VOID,
23064
23059
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.%
23067
23062
}
23068
23063
23069
23064
\rationale{%
@@ -23084,7 +23079,7 @@ \subsubsection{Void Soundness}
23084
23079
from one variable or parameter to the next one, all with type \VOID,
23085
23080
explicitly, or as the value of a type parameter.
23086
23081
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,
23088
23083
or parameter types in the opposite direction;
23089
23084
parameterized types with type argument \VOID{} could not be assigned
23090
23085
to variables where the corresponding type argument is anything other than
@@ -23132,7 +23127,7 @@ \subsection{Parameterized Types}
23132
23127
Let $T$ be a parameterized type \code{$G$<$S_1, \ldots,\ S_n$>}.
23133
23128
23134
23129
\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,
23136
23131
or $G$ is a generic type,
23137
23132
but the number of formal type parameters in the declaration of $G$ is not $n$.
23138
23133
Otherwise, let
@@ -23147,7 +23142,7 @@ \subsection{Parameterized Types}
23147
23142
or $T$ is not well-bounded (\ref{superBoundedTypes}).
23148
23143
23149
23144
\LMHash{}%
23150
- It is a compile-time error if $T$ is malbounded.
23145
+ It is a \Error{ compile-time error} if $T$ is malbounded.
23151
23146
23152
23147
\LMHash{}%
23153
23148
$T$ is evaluated as follows.
@@ -23171,7 +23166,8 @@ \subsection{Parameterized Types}
23171
23166
%% replaced by the bottom type (`Null`, for now) in locations of the member
23172
23167
%% type where it occurs contravariantly. For instance, `c.f` should have
23173
23168
%% 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.
23175
23171
23176
23172
23177
23173
\subsubsection{Actual Types}
@@ -23352,7 +23348,7 @@ \subsubsection{Reserved Words}
23352
23348
\LMHash{}%
23353
23349
A \Index{reserved word} can only be used in the syntactic positions
23354
23350
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
23356
23352
where an identifier is expected.
23357
23353
23358
23354
\commentary{%
0 commit comments