Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(551)

Unified Diff: docs/language/dartLangSpec.tex

Issue 483873002: Enums. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: docs/language/dartLangSpec.tex
===================================================================
--- docs/language/dartLangSpec.tex (revision 39350)
+++ docs/language/dartLangSpec.tex (working copy)
@@ -1206,7 +1206,7 @@
Then, the initializer list of the constructor $S$ (respectively $S.id$) is executed with respect to the bindings that resulted from the evaluation of the argument list, with \THIS{} bound to the current binding of \THIS{}, and the type parameters (if any) of class $S$ bound to the current bindings of $U_1, , \ldots, U_m$.
-It is a compile-time error if class $S$ does not declare a generative constructor named $S$ (respectively $S.id$)
+It is a compile-time error if class $S$ does not declare a generative constructor named $S$ (respectively $S.id$).
\subsubsection{Factories}
\label{factories}
@@ -1510,7 +1510,7 @@
%}
%It is a compile-time error if the \EXTENDS{} clause of a class $C$ includes a type expression that does not denote a class available in the lexical scope of $C$.
-It is a compile-time error if the \EXTENDS{} clause of a class $C$ specifies a malformed type or a deferred type (\ref{staticTypes}) as a superclass.
+It is a compile-time error if the \EXTENDS{} clause of a class $C$ specifies an enumerated type (\ref{enums}), a malformed type or a deferred type (\ref{staticTypes}) as a superclass.
% too strict? Do we e want extends List<Undeclared> to work as List<dynamic>?
\commentary{ The type parameters of a generic class are available in the lexical scope of the superclass clause, potentially shadowing classes in the surrounding scope. The following code is therefore illegal and should cause a compile-time error:
@@ -1633,7 +1633,7 @@
.
\end{grammar}
-It is a compile-time error if the \IMPLEMENTS{} clause of a class $C$ specifies a type variable as a superinterface. It is a compile-time error if the \IMPLEMENTS{} clause of a class $C$ specifies a malformed type or deferred type (\ref{staticTypes}) as a superinterface It is a compile-time error if the \IMPLEMENTS{} clause of a class $C$ specifies type \DYNAMIC{} as a superinterface. It is a compile-time error if the \IMPLEMENTS{} clause of a class $C$ specifies a type $T$ as a superinterface more than once.
+It is a compile-time error if the \IMPLEMENTS{} clause of a class $C$ specifies a type variable as a superinterface. It is a compile-time error if the \IMPLEMENTS{} clause of a class $C$ specifies an enumerated type (\ref{enums}), a malformed type or deferred type (\ref{staticTypes}) as a superinterface It is a compile-time error if the \IMPLEMENTS{} clause of a class $C$ specifies type \DYNAMIC{} as a superinterface. It is a compile-time error if the \IMPLEMENTS{} clause of a class $C$ specifies a type $T$ as a superinterface more than once.
It is a compile-time error if the superclass of a class $C$ is specified as a superinterface of $C$.
\rationale{
@@ -1824,7 +1824,7 @@
If the mixin application declares support for interfaces, the resulting class implements those interfaces.
-It is a compile-time error if $S$ is a malformed type. It is a compile-time error if $M$ (respectively, any of $M_1, \ldots, M_k$) is a malformed type. It is a compile time error if a well formed mixin cannot be derived from $M$ (respectively, from each of $M_1, \ldots, M_k$).
+It is a compile-time error if $S$ is an enumerated type (\ref{enums}) or a malformed type. It is a compile-time error if $M$ (respectively, any of $M_1, \ldots, M_k$) is an enumerated type (\ref{enums}) or a malformed type. It is a compile time error if a well formed mixin cannot be derived from $M$ (respectively, from each of $M_1, \ldots, M_k$).
Let $K$ be a class declaration with the same constructors, superclass and interfaces as $C$, and the instance members declared by $M$ (respectively $M_1, \ldots, M_k$). It is a static warning if the declaration of $K$ would cause a static warning. It is a compile-time error if the declaration of $K$ would cause a compile-time error.
@@ -1876,6 +1876,47 @@
}
+\section{Enums}
+\label{enums}
+
+An {\em enumerated type}, or {\em enum}, is used to represent a fixed number of constant values.
+
+\begin{grammar}
+{\bf enumType:}
+metadata \ENUM{} id `\{' id [`,' id]* [`,'] `\}'
+ .
+\end{grammar}
+
+The declaration of an enum of the form \code{metadata \ENUM{} E \{ id$_1$, \ldots id$_n$\};}
kasperl 2014/08/19 05:04:35 You could consider calling these id$_0$ to id$_{n-
gbracha 2014/08/19 17:54:40 Done.
+has the same effect as a class declaration
+
+\begin{dartCode}
+metadata \CLASS{} E \{
+ \FINAL{} int index;
+ \FINAL{} String \_name;
+ \CONST{} E(\THIS{}.index,\THIS{}.\_name);
+ \STATIC{} \CONST{} E id$_1$ = \CONST{} E(0, `id$_1$');
+ $\ldots$
+ \STATIC{} \CONST{} E id$_n$ = const E(n - 1, `id$_{n-1}$');
kasperl 2014/08/19 05:04:35 `id$_{n-1}$' should be `id$_n$'.
gbracha 2014/08/19 17:54:40 Not anymore.
+
+ \STATIC{} \CONST{} List$<$E$>$ values = const $<$E$>$[id$_1 \ldots $ id$_n$];
+ String toString() =$>$ `E.\$\_name';
+\}
+\end{dartCode}
+
+
+
+It is compile-time error to access the private fields of an enumerated type anywhere outside its definition.
kasperl 2014/08/19 05:04:35 How can we tell statically? Is there any way we c
gbracha 2014/08/19 17:54:41 The problem is that the surrounding library would
+
+\commentary {
+It is also a compile-time error to subclass, mix-in or implement an enum or to explicitly instantiate an enum. These restrictions are given in normative form in sections \ref{superclasses}, \ref{superinterfaces}, \ref{mixinApplication} and \ref{instanceCreation} as appropriate.
+
+All of these restrictions should be enforced by the implementation even in the case of reflection.
+}
+
+% should this be rephrased so that these rules go elsewhere (i.e., in the rules for new/const/extends/implements/with?)
kasperl 2014/08/19 05:04:35 Haven't you already done so?
gbracha 2014/08/19 17:54:41 Yes, I have. This is just an old comment. I'll get
+
+
\section{Generics}
\label{generics}
@@ -2777,6 +2818,18 @@
\CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$,
\CONST{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ is malformed (\ref{dynamicTypeSystem}) or malbounded (\ref{parameterizedTypes}).
+
+It is a compile-time error if the type $T$ in an instance creation expression of one of the forms
kasperl 2014/08/19 05:04:35 one of the forms -> one of the forms (I know it w
gbracha 2014/08/19 17:54:40 Done.
+
+\NEW{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$,
+
+\NEW{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$,
+
+\CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$,
+
+\CONST{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$
+
+is an enumerated type (\ref{enums}).
%any of the type arguments to a constructor of a generic type $G$ invoked by a new expression or a constant object expression are not subtypes of the bounds of the corresponding formal type parameters of $G$.
@@ -4659,6 +4712,17 @@
Very elaborate code in a case clause is probably bad style in any case, and such code can always be refactored.
}
+ It is a static warning if all of the following conditions hold:
+ \begin{itemize}
+\item The switch statement does not have a default clause.
+ \item The static type of $e$ is an enumerated typed with elements $id_1, \ldots, id_n$.
+\item The sets $\{e_1, \ldots, e_k\} $ and $\{id_1, \ldots, id_n\}$ are not the same.
+\end{itemize}
+
+\commentary{
+In other words, a warning will be issued if a switch statement over an enum is not exhaustive.
+}
+
\subsection{ Rethrow}
\label{rethrow}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698