Skip to content

Commit 9a1e73a

Browse files
committed
WIP
1 parent db661fa commit 9a1e73a

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
@@ -22443,16 +22443,17 @@ \subsection{Function Types}
2244322443

2244422444
\LMHash{}%
2244522445
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$.
2244922450
\commentary{%
2245022451
Consequently, all function types are subtypes of \FUNCTION{}
2245122452
(\ref{subtypes}).%
2245222453
}
2245322454

2245422455

22455-
\subsection{Type \FUNCTION}
22456+
\subsection{Type Function}
2245622457
\LMLabel{functionType}
2245722458

2245822459
\LMHash{}%
@@ -22474,13 +22475,13 @@ \subsection{Type \FUNCTION}
2247422475
\LMHash{}%
2247522476
If a mixin application mixes \FUNCTION{} onto a superclass, it follows the
2247622477
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
2247822479
that clause has no effect, the resulting class also does not
2247922480
implement \FUNCTION.
2248022481
\commentary{%
2248122482
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.%
2248422485
}
2248522486

2248622487
\rationale{%
@@ -22493,7 +22494,7 @@ \subsection{Type \FUNCTION}
2249322494
}
2249422495

2249522496

22496-
\subsection{Type \DYNAMIC}
22497+
\subsection{Type dynamic}
2249722498
\LMLabel{typeDynamic}
2249822499

2249922500
\LMHash{}%
@@ -22634,7 +22635,7 @@ \subsection{Type \DYNAMIC}
2263422635
\metavar{typeArguments} is a list of actual
2263522636
type arguments derived from \synt{typeArguments}, and
2263622637
\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
2263822639
a non-generic method declared in \code{Object}.
2263922640
\commentary{%
2264022641
No generic methods are declared in \code{Object}.
@@ -22709,7 +22710,7 @@ \subsection{Type FutureOr}
2270922710
That is, \code{FutureOr} is in a sense
2271022711
the union of $T$ and the corresponding future type.
2271122712
The last point guarantees that
22712-
\code{FutureOr<$T$>} <: \code{Object},
22713+
\code{FutureOr<$T$>} <: \code{Object?},
2271322714
and also that \code{FutureOr} is covariant in its type parameter,
2271422715
just like class types:
2271522716
if $S$ <: $T$ then \code{FutureOr<$S$>} <: \code{FutureOr<$T$>}.%
@@ -22718,7 +22719,7 @@ \subsection{Type FutureOr}
2271822719
\LMHash{}%
2271922720
If the type arguments passed to \code{FutureOr} would incur compile-time errors
2272022721
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}.
2272222723
The name \code{FutureOr} as an expression
2272322724
denotes a \code{Type} object representing the type \code{FutureOr<dynamic>}.
2272422725

@@ -22763,7 +22764,7 @@ \subsection{Type FutureOr}
2276322764
\end{itemize}
2276422765

2276522766

22766-
\subsection{Type Void}
22767+
\subsection{Type void}
2276722768
\LMLabel{typeVoid}
2276822769

2276922770
\LMHash{}%
@@ -22793,16 +22794,16 @@ \subsection{Type Void}
2279322794
\commentary{%
2279422795
The type \VOID{} is a top type
2279522796
(\ref{superBoundedTypes}),
22796-
so \VOID{} and \code{Object} are subtypes of each other
22797+
so \VOID{} and \code{Object?} are subtypes of each other
2279722798
(\ref{subtypes}),
2279822799
which also implies that any object can be
2279922800
the value of an expression of type \VOID.
2280022801
%
2280122802
Consequently, any instance of type \code{Type} which reifies the type \VOID{}
2280222803
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?}
2280422805
(\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.
2280622807
In fact, it is not recommended that implementations strive to achieve this,
2280722808
because it may be more important to ensure that diagnostic messages
2280822809
(including stack traces and dynamic error messages)
@@ -22814,7 +22815,7 @@ \subsection{Type Void}
2281422815
In support of the notion
2281522816
that the value of an expression with static type \VOID{} should be discarded,
2281622817
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}
2281822819
unless it is permitted according to one of the following rules.
2281922820

2282022821
\begin{itemize}
@@ -22844,6 +22845,7 @@ \subsection{Type Void}
2284422845
where it is not an error to have it.%
2284522846
}
2284622847
\item
22848+
%% This relies on \IsMoreTopType{\VOID}{$T$} = \VOID.
2284722849
In a conditional expression \code{$e$\,?\,$e_1$\,:\,$e_2$},
2284822850
$e_1$ and $e_2$ may have type \VOID.
2284922851
\rationale{%
@@ -22853,20 +22855,13 @@ \subsection{Type Void}
2285322855
in some context where it is not an error to have it.%
2285422856
}
2285522857
\item
22858+
%% This relies on \IsMoreTopType{\VOID}{$T$} = \VOID.
2285622859
In a null coalescing expression \code{$e_1$\,??\,$e_2$},
2285722860
$e_2$ may have type \VOID.
2285822861
\rationale{%
2285922862
The static type of the null coalescing expression is then \VOID,
2286022863
which in turn restricts where it can occur.%
2286122864
}
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-
}
2287022865
\item
2287122866
\commentary{%
2287222867
In a return statement \code{\RETURN\,$e$;},
@@ -22934,13 +22929,13 @@ \subsection{Type Void}
2293422929
Finally, we need to address situations involving implicit usage of
2293522930
an object whose static type can be \VOID.
2293622931
%
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
2293822933
expression of type $T$ such that \code{Iterator<\VOID{}>}
2293922934
is the most specific instantiation of \code{Iterator}
2294022935
that is a superinterface of $T$, unless the
2294122936
iteration variable has type \VOID.
2294222937
%
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
2294422939
to have a stream expression of type $T$
2294522940
such that \code{Stream<\VOID{}>} is the most specific
2294622941
instantiation of \code{Stream} that is a superinterface of $T$,
@@ -22949,7 +22944,7 @@ \subsection{Type Void}
2294922944
\commentary{Here are some examples:}
2295022945

2295122946
\begin{dartCode}
22952-
\FOR{} (Object x in <\VOID>[]) \{\} // \comment{Error.}
22947+
\FOR{} (Object? x in <\VOID>[]) \{\} // \comment{Error.}
2295322948
\AWAIT{} \FOR{} (int x \IN{} new Stream<\VOID{}>.empty()) \{\} // \comment{Error.}
2295422949
\FOR{} (\VOID{} x \IN{} <\VOID{}>[]) \{\ldots\} // \comment{OK.}
2295522950
\FOR (\VAR{} x \IN{} <\VOID{}>[]) \{\ldots\} // \comment{OK, type of x inferred.}
@@ -22997,22 +22992,22 @@ \subsubsection{Void Soundness}
2299722992
\ABSTRACT{} \CLASS A<X> \{
2299822993
final X x;
2299922994
A(this.x);
23000-
Object foo(X x);
22995+
Object? foo(X x);
2300122996
\}
2300222997
\\
2300322998
\CLASS{} B<X> \EXTENDS{} A<X> \{
2300422999
B(X x): super(x);
23005-
Object foo(Object x) => x;
23000+
Object? foo(Object? x) => x;
2300623001
\}
2300723002
\\
23008-
Object f<X>(X x) => x;
23003+
Object? f<X>(X x) => x;
2300923004
\\
2301023005
\VOID{} main() \{
2301123006
\VOID x = 42;
2301223007
print(f(x)); // \comment{(1)}
2301323008
\\
2301423009
A<\VOID{}> a = B<\VOID{}>(x);
23015-
A<Object> aObject = a;
23010+
A<Object?> aObject = a;
2301623011
print(aObject.x); // \comment{(2)}
2301723012
print(a.foo(x)); // \comment{(3)}
2301823013
\}
@@ -23029,25 +23024,25 @@ \subsubsection{Void Soundness}
2302923024
which is or contains a type variable whose value could be \VOID,
2303023025
so we are allowed to return \code{x} in the body of \code{f},
2303123026
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?}.
2303323028

2303423029
At (2), we indirectly obtain access to the value of
2303523030
the variable \code{x} with type \VOID,
2303623031
because we use an assignment to get access to the instance of \code{B}
2303723032
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,
2304023035
that is, they are equivalent according to the subtype rules,
2304123036
so neither static nor dynamic type checks will fail.
2304223037

2304323038
At (3), we indirectly obtain access to the value of
2304423039
the variable \code{x} with type \VOID{}
23045-
under the static type \code{Object},
23040+
under the static type \code{Object?},
2304623041
because the statically known method signature of \code{foo}
2304723042
has parameter type \VOID,
2304823043
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.%
2305123046
}
2305223047

2305323048
\rationale{%
@@ -23068,7 +23063,7 @@ \subsubsection{Void Soundness}
2306823063
from one variable or parameter to the next one, all with type \VOID,
2306923064
explicitly, or as the value of a type parameter.
2307023065
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,
2307223067
or parameter types in the opposite direction;
2307323068
parameterized types with type argument \VOID{} could not be assigned
2307423069
to variables where the corresponding type argument is anything other than
@@ -23116,7 +23111,7 @@ \subsection{Parameterized Types}
2311623111
Let $T$ be a parameterized type \code{$G$<$S_1, \ldots,\ S_n$>}.
2311723112

2311823113
\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,
2312023115
or $G$ is a generic type,
2312123116
but the number of formal type parameters in the declaration of $G$ is not $n$.
2312223117
Otherwise, let
@@ -23131,7 +23126,7 @@ \subsection{Parameterized Types}
2313123126
or $T$ is not well-bounded (\ref{superBoundedTypes}).
2313223127

2313323128
\LMHash{}%
23134-
It is a compile-time error if $T$ is malbounded.
23129+
It is a \Error{compile-time error} if $T$ is malbounded.
2313523130

2313623131
\LMHash{}%
2313723132
$T$ is evaluated as follows.
@@ -23155,7 +23150,8 @@ \subsection{Parameterized Types}
2315523150
%% replaced by the bottom type (`Null`, for now) in locations of the member
2315623151
%% type where it occurs contravariantly. For instance, `c.f` should have
2315723152
%% 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.
2315923155

2316023156

2316123157
\subsubsection{Actual Types}
@@ -23336,7 +23332,7 @@ \subsubsection{Reserved Words}
2333623332
\LMHash{}%
2333723333
A \Index{reserved word} can only be used in the syntactic positions
2333823334
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
2334023336
where an identifier is expected.
2334123337

2334223338
\commentary{%

0 commit comments

Comments
 (0)