Skip to content

Commit a3076fa

Browse files
authored
Revert "Adjusted spec of For-In to insist on Iterable (#291)"
This reverts commit 20087c8.
1 parent 20087c8 commit a3076fa

File tree

1 file changed

+13
-26
lines changed

1 file changed

+13
-26
lines changed

specification/dartLangSpec.tex

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424

2525
% CHANGES
2626
% =======
27-
%
2827
% Significant changes to the specification.
29-
%
3028
% 2.2
3129
% - Specify whether the values of literal expressions override Object.==.
3230
% - Allow Type objects as case expressions and const map keys.
@@ -38,8 +36,6 @@
3836
% Function.
3937
% - Generalize specification of type aliases such that they can denote any
4038
% type, not just function types.
41-
% - Added requirement that the iterator of a for-in statement must have
42-
% type `Iterator`.
4339
%
4440
% 2.1
4541
% - Remove 64-bit constraint on integer literals compiled to JavaScript numbers.
@@ -12291,33 +12287,24 @@ \subsubsection{For-in}
1229112287
\LMLabel{for-in}
1229212288

1229312289
\LMHash{}%
12294-
Let $D$ be derived from \syntax{<finalConstVarOrType>?}.
12295-
A for statement of the form \code{\FOR{} ($D$ \id{} \IN{} $e$)\,\,$S$}
12296-
is then treated as the following code,
12297-
where $\id_1$ and $\id_2$ are fresh identifiers:
12290+
Let $D$ be derived from \syntax{<finalConstVarOrType>?}
12291+
and let $n0$ be an identifier that does not occur anywhere in the program.
12292+
A for statement of the form \code{\FOR{} ($D$ \id{} \IN{} $e$) $s$} is equivalent to the following code:
1229812293

1229912294
\begin{normativeDartCode}
12300-
$T$ $\id_1$ = $e$;
12301-
\VAR{} $\id_2$ = $id_1$.iterator;
12302-
\WHILE{} ($\id_2$.moveNext()) \{
12303-
\ \ $D$ \id{} = $\id_2$.current;
12304-
\ \ $S$
12295+
\VAR{} $n0$ = $e$.iterator;
12296+
\WHILE{} ($n0$.moveNext()) \{
12297+
\ \ $D$ \id{} = $n0$.current;
12298+
\ \ $s$
1230512299
\}
1230612300
\end{normativeDartCode}
1230712301

12308-
\noindent
12309-
If the static type of $e$ is a top type
12310-
(\ref{superBoundedTypes})
12311-
then $T$ is \code{Iterable<dynamic>},
12312-
otherwise $T$ is the static type of $e$.
12313-
It is a compile-time error if $T$ is not assignable to \code{Iterable<dynamic>}.
12314-
12315-
\commentary{
12316-
It follows that it is a compile-time error
12317-
if $D$ is empty and \id{} is a final variable;
12318-
and it is a dynamic error if $e$ has a top type,
12319-
but $e$ evaluates to an instance of a type
12320-
which is not a subtype of \code{Iterable<dynamic>}.
12302+
For purposes of static typechecking,
12303+
this code is checked under the assumption that $n0$ is declared to be of type $T$,
12304+
where $T$ is the static type of \code{$e$.iterator}.
12305+
12306+
\commentary{
12307+
It follows that it is a compile-time error if $D$ is empty and \id{} is a final variable.
1232112308
}
1232212309

1232312310

0 commit comments

Comments
 (0)