@@ -22308,16 +22308,17 @@ \subsection{Function Types}
22308
22308
22309
22309
\LMHash{}%
22310
22310
A function object is always an instance of some class $C$ that implements
22311
- the class \FUNCTION{} (\ref{functionType}),
22312
- and which has a method named \CALL,
22313
- whose signature is the function type $C$ itself.
22311
+ a function type $F$ which is a subtype of the class \FUNCTION{}
22312
+ (\ref{functionType}).
22313
+ The function object has a method named \CALL,
22314
+ whose signature is said function type $F$.
22314
22315
\commentary{%
22315
22316
Consequently, all function types are subtypes of \FUNCTION{}
22316
22317
(\ref{subtypes}).%
22317
22318
}
22318
22319
22319
22320
22320
- \subsection{Type \FUNCTION }
22321
+ \subsection{Type Function }
22321
22322
\LMLabel{functionType}
22322
22323
22323
22324
\LMHash{}%
@@ -22339,11 +22340,14 @@ \subsection{Type \FUNCTION}
22339
22340
\LMHash{}%
22340
22341
If a mixin application mixes \FUNCTION{} onto a superclass, it follows the
22341
22342
normal rules for mixin-application, but since the result of that mixin
22342
- application is equivalent to a class with \code{implements Function }, and
22343
+ application is equivalent to a class with \code{implements \FUNCTION }, and
22343
22344
that clause has no effect, the resulting class also does not
22344
- implement \FUNCTION. \commentary{The \FUNCTION{} class declares no
22345
- concrete instance members, so the mixin application creates a sub-class
22346
- of the superclass with no new members and no new interfaces.}
22345
+ implement \FUNCTION.
22346
+ \commentary{%
22347
+ The \FUNCTION{} class declares no concrete instance members,
22348
+ so the mixin application creates a sub-class
22349
+ of the superclass with no new members and no new interfaces.%
22350
+ }
22347
22351
22348
22352
\rationale{%
22349
22353
Since using \FUNCTION{} in these ways has no effect, it would be
@@ -22355,7 +22359,7 @@ \subsection{Type \FUNCTION}
22355
22359
}
22356
22360
22357
22361
22358
- \subsection{Type \DYNAMIC }
22362
+ \subsection{Type dynamic }
22359
22363
\LMLabel{typeDynamic}
22360
22364
22361
22365
\LMHash{}%
@@ -22494,7 +22498,7 @@ \subsection{Type \DYNAMIC}
22494
22498
\metavar{typeArguments} is a list of actual
22495
22499
type arguments derived from \synt{typeArguments}, and
22496
22500
\metavar{arguments} is an actual argument list derived from \synt{arguments}.
22497
- It is a compile-time error if \id{} is the name of
22501
+ It is a \Error{ compile-time error} if \id{} is the name of
22498
22502
a non-generic method declared in \code{Object}.
22499
22503
\commentary{%
22500
22504
No generic methods are declared in \code{Object}.
@@ -22568,7 +22572,7 @@ \subsection{Type FutureOr}
22568
22572
That is, \code{FutureOr} is in a sense
22569
22573
the union of $T$ and the corresponding future type.
22570
22574
The last point guarantees that
22571
- \code{FutureOr<$T$>} <: \code{Object},
22575
+ \code{FutureOr<$T$>} <: \code{Object? },
22572
22576
and also that \code{FutureOr} is covariant in its type parameter,
22573
22577
just like class types:
22574
22578
if $S$ <: $T$ then \code{FutureOr<$S$>} <: \code{FutureOr<$T$>}.%
@@ -22577,7 +22581,7 @@ \subsection{Type FutureOr}
22577
22581
\LMHash{}%
22578
22582
If the type arguments passed to \code{FutureOr} would incur compile-time errors
22579
22583
if applied to a normal generic class with one type parameter,
22580
- the same compile-time errors are issued for \code{FutureOr}.
22584
+ the same \Error{ compile-time errors} are issued for \code{FutureOr}.
22581
22585
The name \code{FutureOr} as an expression
22582
22586
denotes a \code{Type} object representing the type \code{FutureOr<dynamic>}.
22583
22587
@@ -22621,7 +22625,7 @@ \subsection{Type FutureOr}
22621
22625
\end{itemize}
22622
22626
22623
22627
22624
- \subsection{Type Void }
22628
+ \subsection{Type void }
22625
22629
\LMLabel{typeVoid}
22626
22630
22627
22631
\LMHash{}%
@@ -22651,28 +22655,17 @@ \subsection{Type Void}
22651
22655
\commentary{%
22652
22656
The type \VOID{} is a top type
22653
22657
(\ref{superBoundedTypes}),
22654
- so \VOID{} and \code{Object} are subtypes of each other
22658
+ so \VOID{} and \code{Object? } are subtypes of each other
22655
22659
(\ref{subtypes}),
22656
22660
which also implies that any object can be
22657
- the value of an expression of type \VOID.
22658
- %
22659
- Consequently, any instance of type \code{Type} which reifies the type \VOID{}
22660
- must compare equal (according to the \lit{==} operator \ref{equality})
22661
- to any instance of \code{Type} which reifies the type \code{Object}
22662
- (\ref{dynamicTypeSystem}).
22663
- It is not guaranteed that \code{identical(\VOID, Object)} evaluates to true.
22664
- In fact, it is not recommended that implementations strive to achieve this,
22665
- because it may be more important to ensure that diagnostic messages
22666
- (including stack traces and dynamic error messages)
22667
- preserve enough information to use the word `void' when referring to types
22668
- which are specified as such in source code.%
22661
+ the value of an expression of type \VOID.%
22669
22662
}
22670
22663
22671
22664
\LMHash{}%
22672
22665
In support of the notion
22673
22666
that the value of an expression with static type \VOID{} should be discarded,
22674
22667
such objects can only be used in specific situations:
22675
- The occurrence of an expression of type \VOID{} is a compile-time error
22668
+ The occurrence of an expression of type \VOID{} is a \Error{ compile-time error}
22676
22669
unless it is permitted according to one of the following rules.
22677
22670
22678
22671
\begin{itemize}
@@ -22702,6 +22695,7 @@ \subsection{Type Void}
22702
22695
where it is not an error to have it.%
22703
22696
}
22704
22697
\item
22698
+ %% This relies on \IsMoreTopType{\VOID}{$T$} = \VOID.
22705
22699
In a conditional expression \code{$e$\,?\,$e_1$\,:\,$e_2$},
22706
22700
$e_1$ and $e_2$ may have type \VOID.
22707
22701
\rationale{%
@@ -22711,20 +22705,13 @@ \subsection{Type Void}
22711
22705
in some context where it is not an error to have it.%
22712
22706
}
22713
22707
\item
22708
+ %% This relies on \IsMoreTopType{\VOID}{$T$} = \VOID.
22714
22709
In a null coalescing expression \code{$e_1$\,??\,$e_2$},
22715
22710
$e_2$ may have type \VOID.
22716
22711
\rationale{%
22717
22712
The static type of the null coalescing expression is then \VOID,
22718
22713
which in turn restricts where it can occur.%
22719
22714
}
22720
- \item
22721
- In an expression of the form \code{\AWAIT\,\,$e$}, $e$ may have type \VOID.
22722
- \rationale{%
22723
- This rule was adopted because it was a substantial breaking change
22724
- to turn this situation into an error
22725
- at the time where the treatment of \VOID{} was changed.
22726
- Tools may choose to give a hint in such cases.%
22727
- }
22728
22715
\item
22729
22716
\commentary{%
22730
22717
In a return statement \code{\RETURN\,$e$;},
@@ -22792,13 +22779,13 @@ \subsection{Type Void}
22792
22779
Finally, we need to address situations involving implicit usage of
22793
22780
an object whose static type can be \VOID.
22794
22781
%
22795
- It is a compile-time error for a for-in statement to have an iterator
22782
+ It is a \Error{ compile-time error} for a for-in statement to have an iterator
22796
22783
expression of type $T$ such that \code{Iterator<\VOID{}>}
22797
22784
is the most specific instantiation of \code{Iterator}
22798
22785
that is a superinterface of $T$, unless the
22799
22786
iteration variable has type \VOID.
22800
22787
%
22801
- It is a compile-time error for an asynchronous for-in statement
22788
+ It is a \Error{ compile-time error} for an asynchronous for-in statement
22802
22789
to have a stream expression of type $T$
22803
22790
such that \code{Stream<\VOID{}>} is the most specific
22804
22791
instantiation of \code{Stream} that is a superinterface of $T$,
@@ -22809,7 +22796,7 @@ \subsection{Type Void}
22809
22796
}
22810
22797
22811
22798
\begin{dartCode}
22812
- \FOR{} (Object x in <\VOID>[]) \{\} // \comment{Error.}
22799
+ \FOR{} (Object? x in <\VOID>[]) \{\} // \comment{Error.}
22813
22800
\AWAIT{} \FOR{} (int x \IN{} new Stream<\VOID{}>.empty()) \{\} // \comment{Error.}
22814
22801
\FOR{} (\VOID{} x \IN{} <\VOID{}>[]) \{\ldots\} // \comment{OK.}
22815
22802
\FOR (\VAR{} x \IN{} <\VOID{}>[]) \{\ldots\} // \comment{OK, type of x inferred.}
@@ -22857,22 +22844,22 @@ \subsubsection{Void Soundness}
22857
22844
\ABSTRACT{} \CLASS A<X> \{
22858
22845
final X x;
22859
22846
A(this.x);
22860
- Object foo(X x);
22847
+ Object? foo(X x);
22861
22848
\}
22862
22849
\\
22863
22850
\CLASS{} B<X> \EXTENDS{} A<X> \{
22864
22851
B(X x): super(x);
22865
- Object foo(Object x) => x;
22852
+ Object? foo(Object? x) => x;
22866
22853
\}
22867
22854
\\
22868
- Object f<X>(X x) => x;
22855
+ Object? f<X>(X x) => x;
22869
22856
\\
22870
22857
\VOID{} main() \{
22871
22858
\VOID x = 42;
22872
22859
print(f(x)); // \comment{(1)}
22873
22860
\\
22874
22861
A<\VOID{}> a = B<\VOID{}>(x);
22875
- A<Object> aObject = a;
22862
+ A<Object? > aObject = a;
22876
22863
print(aObject.x); // \comment{(2)}
22877
22864
print(a.foo(x)); // \comment{(3)}
22878
22865
\}
@@ -22889,25 +22876,25 @@ \subsubsection{Void Soundness}
22889
22876
which is or contains a type variable whose value could be \VOID,
22890
22877
so we are allowed to return \code{x} in the body of \code{f},
22891
22878
even though this means that we indirectly get access to the value
22892
- of an expression of type \VOID, under the static type \code{Object}.
22879
+ of an expression of type \VOID, under the static type \code{Object? }.
22893
22880
22894
22881
At (2), we indirectly obtain access to the value of
22895
22882
the variable \code{x} with type \VOID,
22896
22883
because we use an assignment to get access to the instance of \code{B}
22897
22884
which was created with type argument \VOID{} under the type
22898
- \code{A<Object>}.
22899
- Note that \code{A<Object>} and \code{A<\VOID{}>} are subtypes of each other,
22885
+ \code{A<Object? >}.
22886
+ Note that \code{A<Object? >} and \code{A<\VOID{}>} are subtypes of each other,
22900
22887
that is, they are equivalent according to the subtype rules,
22901
22888
so neither static nor dynamic type checks will fail.
22902
22889
22903
22890
At (3), we indirectly obtain access to the value of
22904
22891
the variable \code{x} with type \VOID{}
22905
- under the static type \code{Object},
22892
+ under the static type \code{Object? },
22906
22893
because the statically known method signature of \code{foo}
22907
22894
has parameter type \VOID,
22908
22895
but the actual implementation of \code{foo} which is invoked
22909
- is an override whose parameter type is \code{Object},
22910
- which is allowed because \code{Object} and \VOID{} are both top types.%
22896
+ is an override whose parameter type is \code{Object? },
22897
+ which is allowed because \code{Object? } and \VOID{} are both top types.%
22911
22898
}
22912
22899
22913
22900
\rationale{%
@@ -22928,7 +22915,7 @@ \subsubsection{Void Soundness}
22928
22915
from one variable or parameter to the next one, all with type \VOID,
22929
22916
explicitly, or as the value of a type parameter.
22930
22917
In particular, we could require that method overrides should
22931
- never override return type \code{Object} by return type \VOID,
22918
+ never override return type \code{Object? } by return type \VOID,
22932
22919
or parameter types in the opposite direction;
22933
22920
parameterized types with type argument \VOID{} could not be assigned
22934
22921
to variables where the corresponding type argument is anything other than
@@ -22976,7 +22963,7 @@ \subsection{Parameterized Types}
22976
22963
Let $T$ be a parameterized type \code{$G$<$S_1, \ldots,\ S_n$>}.
22977
22964
22978
22965
\LMHash{}%
22979
- It is a compile-time error if $G$ is not a generic type,
22966
+ It is a \Error{ compile-time error} if $G$ is not a generic type,
22980
22967
or $G$ is a generic type,
22981
22968
but the number of formal type parameters in the declaration of $G$ is not $n$.
22982
22969
Otherwise, let
@@ -22991,7 +22978,7 @@ \subsection{Parameterized Types}
22991
22978
or $T$ is not well-bounded (\ref{superBoundedTypes}).
22992
22979
22993
22980
\LMHash{}%
22994
- It is a compile-time error if $T$ is malbounded.
22981
+ It is a \Error{ compile-time error} if $T$ is malbounded.
22995
22982
22996
22983
\LMHash{}%
22997
22984
$T$ is evaluated as follows.
@@ -23015,7 +23002,8 @@ \subsection{Parameterized Types}
23015
23002
%% replaced by the bottom type (`Null`, for now) in locations of the member
23016
23003
%% type where it occurs contravariantly. For instance, `c.f` should have
23017
23004
%% static type `void Function(Null)` when `c` has static type `C<T>` for any
23018
- %% `T`, and we have `class C<X> { void Function(X) f; }`.
23005
+ %% `T`, and we have `class C<X> { void Function(X) f; }`. Cf. issue
23006
+ %% https://github.com/dart-lang/language/issues/297.
23019
23007
23020
23008
23021
23009
\subsubsection{Actual Types}
@@ -23195,7 +23183,7 @@ \subsubsection{Reserved Words}
23195
23183
\LMHash{}%
23196
23184
A \Index{reserved word} can only be used in the syntactic positions
23197
23185
specified by the grammar.
23198
- In particular, a compile-time error occurs if a reserved word is used
23186
+ In particular, a \Error{ compile-time error} occurs if a reserved word is used
23199
23187
where an identifier is expected.
23200
23188
23201
23189
\commentary{%
0 commit comments