@@ -22443,16 +22443,17 @@ \subsection{Function Types}
22443
22443
22444
22444
\LMHash{}%
22445
22445
A function object is always an instance of some class $C$ that implements
22446
- the class \FUNCTION{} (\ref{functionType}),
22447
- and which has a method named \CALL,
22448
- whose signature is the function type $C$ itself.
22446
+ a function type $F$ which is a subtype of the class \FUNCTION{}
22447
+ (\ref{functionType}).
22448
+ The function object has a method named \CALL,
22449
+ whose signature is said function type $F$.
22449
22450
\commentary{%
22450
22451
Consequently, all function types are subtypes of \FUNCTION{}
22451
22452
(\ref{subtypes}).%
22452
22453
}
22453
22454
22454
22455
22455
- \subsection{Type \FUNCTION }
22456
+ \subsection{Type Function }
22456
22457
\LMLabel{functionType}
22457
22458
22458
22459
\LMHash{}%
@@ -22474,13 +22475,13 @@ \subsection{Type \FUNCTION}
22474
22475
\LMHash{}%
22475
22476
If a mixin application mixes \FUNCTION{} onto a superclass, it follows the
22476
22477
normal rules for mixin-application, but since the result of that mixin
22477
- application is equivalent to a class with \code{implements Function }, and
22478
+ application is equivalent to a class with \code{implements \FUNCTION }, and
22478
22479
that clause has no effect, the resulting class also does not
22479
22480
implement \FUNCTION.
22480
22481
\commentary{%
22481
22482
The \FUNCTION{} class declares no concrete instance members,
22482
- so the mixin application creates a sub-class of
22483
- the superclass with no new members and no new interfaces.%
22483
+ so the mixin application creates a sub-class
22484
+ of the superclass with no new members and no new interfaces.%
22484
22485
}
22485
22486
22486
22487
\rationale{%
@@ -22493,7 +22494,7 @@ \subsection{Type \FUNCTION}
22493
22494
}
22494
22495
22495
22496
22496
- \subsection{Type \DYNAMIC }
22497
+ \subsection{Type dynamic }
22497
22498
\LMLabel{typeDynamic}
22498
22499
22499
22500
\LMHash{}%
@@ -22634,7 +22635,7 @@ \subsection{Type \DYNAMIC}
22634
22635
\metavar{typeArguments} is a list of actual
22635
22636
type arguments derived from \synt{typeArguments}, and
22636
22637
\metavar{arguments} is an actual argument list derived from \synt{arguments}.
22637
- It is a compile-time error if \id{} is the name of
22638
+ It is a \Error{ compile-time error} if \id{} is the name of
22638
22639
a non-generic method declared in \code{Object}.
22639
22640
\commentary{%
22640
22641
No generic methods are declared in \code{Object}.
@@ -22709,7 +22710,7 @@ \subsection{Type FutureOr}
22709
22710
That is, \code{FutureOr} is in a sense
22710
22711
the union of $T$ and the corresponding future type.
22711
22712
The last point guarantees that
22712
- \code{FutureOr<$T$>} <: \code{Object},
22713
+ \code{FutureOr<$T$>} <: \code{Object? },
22713
22714
and also that \code{FutureOr} is covariant in its type parameter,
22714
22715
just like class types:
22715
22716
if $S$ <: $T$ then \code{FutureOr<$S$>} <: \code{FutureOr<$T$>}.%
@@ -22718,7 +22719,7 @@ \subsection{Type FutureOr}
22718
22719
\LMHash{}%
22719
22720
If the type arguments passed to \code{FutureOr} would incur compile-time errors
22720
22721
if applied to a normal generic class with one type parameter,
22721
- the same compile-time errors are issued for \code{FutureOr}.
22722
+ the same \Error{ compile-time errors} are issued for \code{FutureOr}.
22722
22723
The name \code{FutureOr} as an expression
22723
22724
denotes a \code{Type} object representing the type \code{FutureOr<dynamic>}.
22724
22725
@@ -22763,7 +22764,7 @@ \subsection{Type FutureOr}
22763
22764
\end{itemize}
22764
22765
22765
22766
22766
- \subsection{Type Void }
22767
+ \subsection{Type void }
22767
22768
\LMLabel{typeVoid}
22768
22769
22769
22770
\LMHash{}%
@@ -22793,16 +22794,16 @@ \subsection{Type Void}
22793
22794
\commentary{%
22794
22795
The type \VOID{} is a top type
22795
22796
(\ref{superBoundedTypes}),
22796
- so \VOID{} and \code{Object} are subtypes of each other
22797
+ so \VOID{} and \code{Object? } are subtypes of each other
22797
22798
(\ref{subtypes}),
22798
22799
which also implies that any object can be
22799
22800
the value of an expression of type \VOID.
22800
22801
%
22801
22802
Consequently, any instance of type \code{Type} which reifies the type \VOID{}
22802
22803
must compare equal (according to the \lit{==} operator \ref{equality})
22803
- to any instance of \code{Type} which reifies the type \code{Object}
22804
+ to any instance of \code{Type} which reifies the type \code{Object? }
22804
22805
(\ref{dynamicTypeSystem}).
22805
- It is not guaranteed that \code{identical(\VOID, Object)} evaluates to true .
22806
+ It is not guaranteed that those two reified types are identical .
22806
22807
In fact, it is not recommended that implementations strive to achieve this,
22807
22808
because it may be more important to ensure that diagnostic messages
22808
22809
(including stack traces and dynamic error messages)
@@ -22814,7 +22815,7 @@ \subsection{Type Void}
22814
22815
In support of the notion
22815
22816
that the value of an expression with static type \VOID{} should be discarded,
22816
22817
such objects can only be used in specific situations:
22817
- The occurrence of an expression of type \VOID{} is a compile-time error
22818
+ The occurrence of an expression of type \VOID{} is a \Error{ compile-time error}
22818
22819
unless it is permitted according to one of the following rules.
22819
22820
22820
22821
\begin{itemize}
@@ -22844,6 +22845,7 @@ \subsection{Type Void}
22844
22845
where it is not an error to have it.%
22845
22846
}
22846
22847
\item
22848
+ %% This relies on \IsMoreTopType{\VOID}{$T$} = \VOID.
22847
22849
In a conditional expression \code{$e$\,?\,$e_1$\,:\,$e_2$},
22848
22850
$e_1$ and $e_2$ may have type \VOID.
22849
22851
\rationale{%
@@ -22853,20 +22855,13 @@ \subsection{Type Void}
22853
22855
in some context where it is not an error to have it.%
22854
22856
}
22855
22857
\item
22858
+ %% This relies on \IsMoreTopType{\VOID}{$T$} = \VOID.
22856
22859
In a null coalescing expression \code{$e_1$\,??\,$e_2$},
22857
22860
$e_2$ may have type \VOID.
22858
22861
\rationale{%
22859
22862
The static type of the null coalescing expression is then \VOID,
22860
22863
which in turn restricts where it can occur.%
22861
22864
}
22862
- \item
22863
- In an expression of the form \code{\AWAIT\,\,$e$}, $e$ may have type \VOID.
22864
- \rationale{%
22865
- This rule was adopted because it was a substantial breaking change
22866
- to turn this situation into an error
22867
- at the time where the treatment of \VOID{} was changed.
22868
- Tools may choose to give a hint in such cases.%
22869
- }
22870
22865
\item
22871
22866
\commentary{%
22872
22867
In a return statement \code{\RETURN\,$e$;},
@@ -22934,13 +22929,13 @@ \subsection{Type Void}
22934
22929
Finally, we need to address situations involving implicit usage of
22935
22930
an object whose static type can be \VOID.
22936
22931
%
22937
- It is a compile-time error for a for-in statement to have an iterator
22932
+ It is a \Error{ compile-time error} for a for-in statement to have an iterator
22938
22933
expression of type $T$ such that \code{Iterator<\VOID{}>}
22939
22934
is the most specific instantiation of \code{Iterator}
22940
22935
that is a superinterface of $T$, unless the
22941
22936
iteration variable has type \VOID.
22942
22937
%
22943
- It is a compile-time error for an asynchronous for-in statement
22938
+ It is a \Error{ compile-time error} for an asynchronous for-in statement
22944
22939
to have a stream expression of type $T$
22945
22940
such that \code{Stream<\VOID{}>} is the most specific
22946
22941
instantiation of \code{Stream} that is a superinterface of $T$,
@@ -22949,7 +22944,7 @@ \subsection{Type Void}
22949
22944
\commentary{Here are some examples:}
22950
22945
22951
22946
\begin{dartCode}
22952
- \FOR{} (Object x in <\VOID>[]) \{\} // \comment{Error.}
22947
+ \FOR{} (Object? x in <\VOID>[]) \{\} // \comment{Error.}
22953
22948
\AWAIT{} \FOR{} (int x \IN{} new Stream<\VOID{}>.empty()) \{\} // \comment{Error.}
22954
22949
\FOR{} (\VOID{} x \IN{} <\VOID{}>[]) \{\ldots\} // \comment{OK.}
22955
22950
\FOR (\VAR{} x \IN{} <\VOID{}>[]) \{\ldots\} // \comment{OK, type of x inferred.}
@@ -22997,22 +22992,22 @@ \subsubsection{Void Soundness}
22997
22992
\ABSTRACT{} \CLASS A<X> \{
22998
22993
final X x;
22999
22994
A(this.x);
23000
- Object foo(X x);
22995
+ Object? foo(X x);
23001
22996
\}
23002
22997
\\
23003
22998
\CLASS{} B<X> \EXTENDS{} A<X> \{
23004
22999
B(X x): super(x);
23005
- Object foo(Object x) => x;
23000
+ Object? foo(Object? x) => x;
23006
23001
\}
23007
23002
\\
23008
- Object f<X>(X x) => x;
23003
+ Object? f<X>(X x) => x;
23009
23004
\\
23010
23005
\VOID{} main() \{
23011
23006
\VOID x = 42;
23012
23007
print(f(x)); // \comment{(1)}
23013
23008
\\
23014
23009
A<\VOID{}> a = B<\VOID{}>(x);
23015
- A<Object> aObject = a;
23010
+ A<Object? > aObject = a;
23016
23011
print(aObject.x); // \comment{(2)}
23017
23012
print(a.foo(x)); // \comment{(3)}
23018
23013
\}
@@ -23029,25 +23024,25 @@ \subsubsection{Void Soundness}
23029
23024
which is or contains a type variable whose value could be \VOID,
23030
23025
so we are allowed to return \code{x} in the body of \code{f},
23031
23026
even though this means that we indirectly get access to the value
23032
- of an expression of type \VOID, under the static type \code{Object}.
23027
+ of an expression of type \VOID, under the static type \code{Object? }.
23033
23028
23034
23029
At (2), we indirectly obtain access to the value of
23035
23030
the variable \code{x} with type \VOID,
23036
23031
because we use an assignment to get access to the instance of \code{B}
23037
23032
which was created with type argument \VOID{} under the type
23038
- \code{A<Object>}.
23039
- Note that \code{A<Object>} and \code{A<\VOID{}>} are subtypes of each other,
23033
+ \code{A<Object? >}.
23034
+ Note that \code{A<Object? >} and \code{A<\VOID{}>} are subtypes of each other,
23040
23035
that is, they are equivalent according to the subtype rules,
23041
23036
so neither static nor dynamic type checks will fail.
23042
23037
23043
23038
At (3), we indirectly obtain access to the value of
23044
23039
the variable \code{x} with type \VOID{}
23045
- under the static type \code{Object},
23040
+ under the static type \code{Object? },
23046
23041
because the statically known method signature of \code{foo}
23047
23042
has parameter type \VOID,
23048
23043
but the actual implementation of \code{foo} which is invoked
23049
- is an override whose parameter type is \code{Object},
23050
- which is allowed because \code{Object} and \VOID{} are both top types.%
23044
+ is an override whose parameter type is \code{Object? },
23045
+ which is allowed because \code{Object? } and \VOID{} are both top types.%
23051
23046
}
23052
23047
23053
23048
\rationale{%
@@ -23068,7 +23063,7 @@ \subsubsection{Void Soundness}
23068
23063
from one variable or parameter to the next one, all with type \VOID,
23069
23064
explicitly, or as the value of a type parameter.
23070
23065
In particular, we could require that method overrides should
23071
- never override return type \code{Object} by return type \VOID,
23066
+ never override return type \code{Object? } by return type \VOID,
23072
23067
or parameter types in the opposite direction;
23073
23068
parameterized types with type argument \VOID{} could not be assigned
23074
23069
to variables where the corresponding type argument is anything other than
@@ -23116,7 +23111,7 @@ \subsection{Parameterized Types}
23116
23111
Let $T$ be a parameterized type \code{$G$<$S_1, \ldots,\ S_n$>}.
23117
23112
23118
23113
\LMHash{}%
23119
- It is a compile-time error if $G$ is not a generic type,
23114
+ It is a \Error{ compile-time error} if $G$ is not a generic type,
23120
23115
or $G$ is a generic type,
23121
23116
but the number of formal type parameters in the declaration of $G$ is not $n$.
23122
23117
Otherwise, let
@@ -23131,7 +23126,7 @@ \subsection{Parameterized Types}
23131
23126
or $T$ is not well-bounded (\ref{superBoundedTypes}).
23132
23127
23133
23128
\LMHash{}%
23134
- It is a compile-time error if $T$ is malbounded.
23129
+ It is a \Error{ compile-time error} if $T$ is malbounded.
23135
23130
23136
23131
\LMHash{}%
23137
23132
$T$ is evaluated as follows.
@@ -23155,7 +23150,8 @@ \subsection{Parameterized Types}
23155
23150
%% replaced by the bottom type (`Null`, for now) in locations of the member
23156
23151
%% type where it occurs contravariantly. For instance, `c.f` should have
23157
23152
%% static type `void Function(Null)` when `c` has static type `C<T>` for any
23158
- %% `T`, and we have `class C<X> { void Function(X) f; }`.
23153
+ %% `T`, and we have `class C<X> { void Function(X) f; }`. Cf. issue
23154
+ %% https://github.com/dart-lang/language/issues/297.
23159
23155
23160
23156
23161
23157
\subsubsection{Actual Types}
@@ -23336,7 +23332,7 @@ \subsubsection{Reserved Words}
23336
23332
\LMHash{}%
23337
23333
A \Index{reserved word} can only be used in the syntactic positions
23338
23334
specified by the grammar.
23339
- In particular, a compile-time error occurs if a reserved word is used
23335
+ In particular, a \Error{ compile-time error} occurs if a reserved word is used
23340
23336
where an identifier is expected.
23341
23337
23342
23338
\commentary{%
0 commit comments