OLD | NEW |
1 \documentclass{article} | 1 \documentclass{article} |
2 \usepackage{epsfig} | 2 \usepackage{epsfig} |
3 \usepackage{dart} | 3 \usepackage{dart} |
4 \usepackage{bnf} | 4 \usepackage{bnf} |
5 \usepackage{hyperref} | 5 \usepackage{hyperref} |
6 \newcommand{\code}[1]{{\sf #1}} | 6 \newcommand{\code}[1]{{\sf #1}} |
7 \title{Dart Programming Language Specification \\ | 7 \title{Dart Programming Language Specification \\ |
8 {\large Version 1.4}} | 8 {\large Version 1.6}} |
9 %\author{The Dart Team} | 9 %\author{The Dart Team} |
10 \begin{document} | 10 \begin{document} |
11 \maketitle | 11 \maketitle |
12 \tableofcontents | 12 \tableofcontents |
13 | 13 |
14 | 14 |
15 \newpage | 15 \newpage |
16 | 16 |
17 \pagestyle{myheadings} | 17 \pagestyle{myheadings} |
18 \markright{Dart Programming Language Specification} | 18 \markright{Dart Programming Language Specification} |
(...skipping 1227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1246 Calling a redirecting factory constructor $k$ causes the constructor $k^\prime$
denoted by $type$ (respectively, $type.identifier$) to be called with the actual
arguments passed to $k$, and returns the result of $k^\prime$ as the result of
$k$. The resulting constructor call is governed by the same rules as an instanc
e creation expression using \NEW{} (\ref{instanceCreation}). | 1246 Calling a redirecting factory constructor $k$ causes the constructor $k^\prime$
denoted by $type$ (respectively, $type.identifier$) to be called with the actual
arguments passed to $k$, and returns the result of $k^\prime$ as the result of
$k$. The resulting constructor call is governed by the same rules as an instanc
e creation expression using \NEW{} (\ref{instanceCreation}). |
1247 | 1247 |
1248 \commentary{ | 1248 \commentary{ |
1249 It follows that if $type$ or $type.id$ are not defined, or do not refer to a cla
ss or constructor, a dynamic error occurs, as with any other undefined construct
or call. The same holds if $k$ is called with fewer required parameters or more
positional parameters than $k^\prime$ expects, or if $k$ is called with a named
parameter that is not declared by $k^\prime$. | 1249 It follows that if $type$ or $type.id$ are not defined, or do not refer to a cla
ss or constructor, a dynamic error occurs, as with any other undefined construct
or call. The same holds if $k$ is called with fewer required parameters or more
positional parameters than $k^\prime$ expects, or if $k$ is called with a named
parameter that is not declared by $k^\prime$. |
1250 } | 1250 } |
1251 | 1251 |
1252 It is a compile-time error if $k$ explicitly specifies a default value for an op
tional parameter.\commentary{ | 1252 It is a compile-time error if $k$ explicitly specifies a default value for an op
tional parameter.\commentary{ |
1253 Default values specified in $k$ would be ignored, since it is the {\em actual} p
arameters that are passed to $k^\prime$. Hence, default values are disallowed. | 1253 Default values specified in $k$ would be ignored, since it is the {\em actual} p
arameters that are passed to $k^\prime$. Hence, default values are disallowed. |
1254 } | 1254 } |
1255 | 1255 |
1256 It is a compile-time error if a redirecting factory constructor redirects to its
elf, either directly or indirectly via a sequence of redirections. %does not red
irect to a non-redirecting factory constructor or to a generative constructor in
a finite number of steps. | 1256 It is a run-time error if a redirecting factory constructor redirects to itself,
either directly or indirectly via a sequence of redirections. %does not redirec
t to a non-redirecting factory constructor or to a generative constructor in a f
inite number of steps. |
1257 | 1257 |
1258 % Make this a runtime error so deferred loading works | 1258 % Make this a runtime error so deferred loading works |
1259 | 1259 |
1260 \rationale{ | 1260 \rationale{ |
1261 If a redirecting factory $F_1$ redirects to another redirecting factory $F_2$ an
d $F_2$ then redirects to $F_1$, then both $F_1$ and $F_2$ are ill-defined. Such
cycles are therefore illegal. | 1261 If a redirecting factory $F_1$ redirects to another redirecting factory $F_2$ an
d $F_2$ then redirects to $F_1$, then both $F_1$ and $F_2$ are ill-defined. Such
cycles are therefore illegal. |
1262 } | 1262 } |
1263 | 1263 |
1264 | 1264 |
1265 It is a static warning if $type$ does not denote a class accessible in the curre
nt scope; if $type$ does denote such a class $C$ it is a static warning if the r
eferenced constructor (be it $type$ or $type.id$) is not a constructor of $C$. | 1265 It is a static warning if $type$ does not denote a class accessible in the curre
nt scope; if $type$ does denote such a class $C$ it is a static warning if the r
eferenced constructor (be it $type$ or $type.id$) is not a constructor of $C$. |
1266 | 1266 |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1492 \EXTENDS{} type | 1492 \EXTENDS{} type |
1493 . | 1493 . |
1494 \end{grammar} | 1494 \end{grammar} |
1495 | 1495 |
1496 %The superclass clause of a class C is processed within the enclosing scope of t
he static scope of C. | 1496 %The superclass clause of a class C is processed within the enclosing scope of t
he static scope of C. |
1497 %\commentary{ | 1497 %\commentary{ |
1498 %This means that in a generic class, the type parameters of the generic are avai
lable in the superclass clause. | 1498 %This means that in a generic class, the type parameters of the generic are avai
lable in the superclass clause. |
1499 %} | 1499 %} |
1500 | 1500 |
1501 %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$. | 1501 %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$. |
1502 It is a compile-time error if the \EXTENDS{} clause of a class $C$ specifies a
malformed type as a superclass. | 1502 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. |
1503 % too strict? Do we e want extends List<Undeclared> to work as List<dynamic>? | 1503 % too strict? Do we e want extends List<Undeclared> to work as List<dynamic>? |
1504 | 1504 |
1505 \commentary{ The type parameters of a generic class are available in the lexical
scope of the superclass clause, potentially shadowing classes in the surroundin
g scope. The following code is therefore illegal and should cause a compile-time
error: | 1505 \commentary{ The type parameters of a generic class are available in the lexical
scope of the superclass clause, potentially shadowing classes in the surroundin
g scope. The following code is therefore illegal and should cause a compile-time
error: |
1506 } | 1506 } |
1507 | 1507 |
1508 \begin{dartCode} | 1508 \begin{dartCode} |
1509 class T \{\} | 1509 class T \{\} |
1510 | 1510 |
1511 /* Compilation error: Attempt to subclass a type parameter */ | 1511 /* Compilation error: Attempt to subclass a type parameter */ |
1512 class G$<$T$>$ extends T \{\} | 1512 class G$<$T$>$ extends T \{\} |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1615 | 1615 |
1616 A class has a set of direct superinterfaces. This set includes the interface of
its superclass and the interfaces specified in the the \IMPLEMENTS{} clause of
the class. | 1616 A class has a set of direct superinterfaces. This set includes the interface of
its superclass and the interfaces specified in the the \IMPLEMENTS{} clause of
the class. |
1617 % and any superinterfaces specified by interface injection (\ref{interfaceInject
ion}). \Q{The latter needs to be worded carefully - when do interface injection
clauses execute and in what scope?} | 1617 % and any superinterfaces specified by interface injection (\ref{interfaceInject
ion}). \Q{The latter needs to be worded carefully - when do interface injection
clauses execute and in what scope?} |
1618 | 1618 |
1619 \begin{grammar} | 1619 \begin{grammar} |
1620 {\bf interfaces:} | 1620 {\bf interfaces:} |
1621 \IMPLEMENTS{} typeList | 1621 \IMPLEMENTS{} typeList |
1622 . | 1622 . |
1623 \end{grammar} | 1623 \end{grammar} |
1624 | 1624 |
1625 It is a compile-time error if the \IMPLEMENTS{} clause of a class $C$ specifie
s a type variable as a superinterface. It is a compile-time error if the \IMPL
EMENTS{} clause of a class $C$ specifies a malformed type 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 \IMPLEM
ENTS{} clause of a class $C$ specifies a type $T$ as a superinterface more than
once. | 1625 It is a compile-time error if the \IMPLEMENTS{} clause of a class $C$ specifie
s a type variable as a superinterface. It is a compile-time error if the \IMPL
EMENTS{} clause of a class $C$ specifies a malformed type or deferred type (\re
f{staticTypes}) as a superinterface It is a compile-time error if the \IMPLEMEN
TS{} 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 t
ype $T$ as a superinterface more than once. |
1626 It is a compile-time error if the superclass of a class $C$ is specified as a su
perinterface of $C$. | 1626 It is a compile-time error if the superclass of a class $C$ is specified as a su
perinterface of $C$. |
1627 | 1627 |
1628 \rationale{ | 1628 \rationale{ |
1629 One might argue that it is harmless to repeat a type in the superinterface list,
so why make it an error? The issue is not so much that the situation described
in program source is erroneous, but that it is pointless. As such, it is an indi
cation that the programmer may very well have meant to say something else - and
that is a mistake that should be called to her or his attention. Nevertheless,
we could simply issue a warning; and perhaps we should and will. That said, prob
lems like these are local and easily corrected on the spot, so we feel justified
in taking a harder line. | 1629 One might argue that it is harmless to repeat a type in the superinterface list,
so why make it an error? The issue is not so much that the situation described
in program source is erroneous, but that it is pointless. As such, it is an indi
cation that the programmer may very well have meant to say something else - and
that is a mistake that should be called to her or his attention. Nevertheless,
we could simply issue a warning; and perhaps we should and will. That said, prob
lems like these are local and easily corrected on the spot, so we feel justified
in taking a harder line. |
1630 } | 1630 } |
1631 | 1631 |
1632 It is a compile-time error if the interface of a class $C$ is a superinterface o
f itself. | 1632 It is a compile-time error if the interface of a class $C$ is a superinterface o
f itself. |
1633 | 1633 |
1634 Let $C$ be a concrete class that does not declare its own \code{noSuchMethod()}
method. | 1634 Let $C$ be a concrete class that does not declare its own \code{noSuchMethod()}
method. |
1635 It is a static warning if the implicit interface of $C$ includes an instance me
mber $m$ of type $F$ and $C$ does not declare or inherit a corresponding non-abs
tract instance member $m$ of type $F'$ such that $F' <: F$. | 1635 It is a static warning if the implicit interface of $C$ includes an instance me
mber $m$ of type $F$ and $C$ does not declare or inherit a corresponding non-abs
tract instance member $m$ of type $F'$ such that $F' <: F$. |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1781 The restriction on constructors simplifies the construction of mixin application
s because the process of creating instances is simpler. | 1781 The restriction on constructors simplifies the construction of mixin application
s because the process of creating instances is simpler. |
1782 | 1782 |
1783 The restriction on the superclass means that the type of a class from which a m
ixin is derived is always implemented by any class that mixes it in. This allows
us to defer the question of whether and how to express the type of the mixin in
dependently of its superclass and super interface types. | 1783 The restriction on the superclass means that the type of a class from which a m
ixin is derived is always implemented by any class that mixes it in. This allows
us to defer the question of whether and how to express the type of the mixin in
dependently of its superclass and super interface types. |
1784 | 1784 |
1785 Reasonable answers exist for all these issues, but their implementation is non-t
rivial. | 1785 Reasonable answers exist for all these issues, but their implementation is non-t
rivial. |
1786 } | 1786 } |
1787 | 1787 |
1788 \subsection{Mixin Application} | 1788 \subsection{Mixin Application} |
1789 \label{mixinApplication} | 1789 \label{mixinApplication} |
1790 | 1790 |
1791 A mixin may be applied to a superclass, yielding a new class. Mixin application
occurs when a mixin is mixed into a class declaration via its \WITH{} clause. T
he mixin application may be used to extend a class per section (\ref{classes});
alternately, a class may be defined as a mixin application as described in this
section. | 1791 A mixin may be applied to a superclass, yielding a new class. Mixin application
occurs when a mixin is mixed into a class declaration via its \WITH{} clause. T
he mixin application may be used to extend a class per section (\ref{classes});
alternately, a class may be defined as a mixin application as described in this
section. It is a compile-time error if the \WITH{} clause of a mixin applicati
on $C$ includes a deferred type expression. |
| 1792 |
1792 | 1793 |
1793 \begin{grammar} | 1794 \begin{grammar} |
1794 {\bf mixinApplicationClass:} | 1795 {\bf mixinApplicationClass:} |
1795 identifier typeParameters? `=' mixinApplication `{\escapegrammar ;}' . | 1796 identifier typeParameters? `=' mixinApplication `{\escapegrammar ;}' . |
1796 | 1797 |
1797 {\bf mixinApplication:} | 1798 {\bf mixinApplication:} |
1798 type mixins interfaces? | 1799 type mixins interfaces? |
1799 . | 1800 . |
1800 \end{grammar} | 1801 \end{grammar} |
1801 | 1802 |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2105 A {\em constant expression} is an expression whose value can never change, and t
hat can be evaluated entirely at compile time. | 2106 A {\em constant expression} is an expression whose value can never change, and t
hat can be evaluated entirely at compile time. |
2106 | 2107 |
2107 A constant expression is one of the following: | 2108 A constant expression is one of the following: |
2108 \begin{itemize} | 2109 \begin{itemize} |
2109 \item A literal number (\ref{numbers}). | 2110 \item A literal number (\ref{numbers}). |
2110 \item A literal boolean (\ref{booleans}). | 2111 \item A literal boolean (\ref{booleans}). |
2111 \item A literal string (\ref{strings}) where any interpolated expression (\ref{
stringInterpolation}) is a compile-time constant that evaluates to a numeric, st
ring or boolean value or to \NULL{}. | 2112 \item A literal string (\ref{strings}) where any interpolated expression (\ref{
stringInterpolation}) is a compile-time constant that evaluates to a numeric, st
ring or boolean value or to \NULL{}. |
2112 \rationale{It would be tempting to allow string interpolation where the interpol
ated value is any compile-time constant. However, this would require running th
e \code{toString()} method for constant objects, which could contain arbitrary c
ode.} | 2113 \rationale{It would be tempting to allow string interpolation where the interpol
ated value is any compile-time constant. However, this would require running th
e \code{toString()} method for constant objects, which could contain arbitrary c
ode.} |
2113 \item A literal symbol (\ref{symbols}). | 2114 \item A literal symbol (\ref{symbols}). |
2114 \item \NULL{} (\ref{null}). | 2115 \item \NULL{} (\ref{null}). |
2115 \item A qualified reference to a static constant variable (\ref{variables}). | 2116 \item A qualified reference to a static constant variable (\ref{variables}) that
is not qualified by a deferred prefix. |
2116 \commentary {For example, If class C declares a constant static variable v, C.v
is a constant. The same is true if C is accessed via a prefix p; p.C.v is a cons
tant. | 2117 \commentary {For example, If class C declares a constant static variable v, C.v
is a constant. The same is true if C is accessed via a prefix p; p.C.v is a cons
tant unless p is a deferred prefix. |
2117 } | 2118 } |
2118 \item An identifier expression that denotes a constant variable. %CHANGE in goog
ledoc | 2119 \item An identifier expression that denotes a constant variable. %CHANGE in goog
ledoc |
2119 \item A simple or qualified identifier denoting a class or a type alias. | 2120 \item A simple or qualified identifier denoting a class or a type alias. |
2120 \commentary {For example, if C is a class or typedef C is a constant, and if C i
s imported with a prefix p, p.C is a constant. | 2121 \commentary {For example, if C is a class or typedef C is a constant, and if C i
s imported with a prefix p, p.C is a constant. |
2121 } | 2122 } |
2122 \item A constant constructor invocation (\ref{const}). | 2123 \item A constant constructor invocation (\ref{const}) that is not qualified by a
deferred prefix. |
2123 \item A constant list literal (\ref{lists}). | 2124 \item A constant list literal (\ref{lists}). |
2124 \item A constant map literal (\ref{maps}). | 2125 \item A constant map literal (\ref{maps}). |
2125 \item A simple or qualified identifier denoting a top-level function (\ref{funct
ions}) or a static method (\ref{staticMethods}). | 2126 \item A simple or qualified identifier denoting a top-level function (\ref{funct
ions}) or a static method (\ref{staticMethods}) that is not qualified by a defer
red prefix. |
2126 \item A parenthesized expression \code{($e$)} where $e$ is a constant expression
. | 2127 \item A parenthesized expression \code{($e$)} where $e$ is a constant expression
. |
2127 \item An expression of the form \code{identical($e_1$, $e_2$)} where $e_1$ and $
e_2$ are constant expressions and \code{identical()} is statically bound to the
predefined dart function \code{identical()} discussed above (\ref{objectIdent
ity}). | 2128 \item An expression of the form \code{identical($e_1$, $e_2$)} where $e_1$ and $
e_2$ are constant expressions and \code{identical()} is statically bound to the
predefined dart function \code{identical()} discussed above (\ref{objectIdent
ity}). |
2128 \item An expression of one of the forms \code{$e_1$ == $e_2$} or \code{$e_1$ !
= $e_2$} where $e_1$ and $e_2$ are constant expressions that evaluate to a numer
ic, string or boolean value or to \NULL{}. | 2129 \item An expression of one of the forms \code{$e_1$ == $e_2$} or \code{$e_1$ !
= $e_2$} where $e_1$ and $e_2$ are constant expressions that evaluate to a numer
ic, string or boolean value or to \NULL{}. |
2129 \item An expression of one of the forms \code{!$e$}, \code{$e_1$ \&\& $e_2$} or
\code{$e_1 || e_2$}, where $e$, $e_1$ and $e_2$ are constant expressions that e
valuate to a boolean value. | 2130 \item An expression of one of the forms \code{!$e$}, \code{$e_1$ \&\& $e_2$} or
\code{$e_1 || e_2$}, where $e$, $e_1$ and $e_2$ are constant expressions that e
valuate to a boolean value. |
2130 \item An expression of one of the forms \~{}$e$, $e_1$ \^{} $e_2$, \code{$e_1$ \
& $e_2$}, $e_1 | e_2$, $e_1 >> e_2$ or $e_1 << e_2$, where $e$, $e_1$ and $e_2
$ are constant expressions that evaluate to an integer value or to \NULL{}. | 2131 \item An expression of one of the forms \~{}$e$, $e_1$ \^{} $e_2$, \code{$e_1$ \
& $e_2$}, $e_1 | e_2$, $e_1 >> e_2$ or $e_1 << e_2$, where $e$, $e_1$ and $e_2
$ are constant expressions that evaluate to an integer value or to \NULL{}. |
2131 \item An expression of one of the forms \code{$-e$}, \code{$e_1 + e_2$}, \code{
$e_1$ - $e_2$}, \code{$e_1$ * $e_2$}, \code{$e_1$ / $e_2$,} \code{$e_1$ \~{}/ $e
_2$}, \code{$e_1 > e_2$}, \code{$e_1 < e_2$}, \code{$e_1$ $>$= $e_2$}, \cod
e{$e_1$ $<$= $e_2$} or \code{$e_1$ \% $e_2$}, where $e$, $e_1$ and $e_2$ are co
nstant expressions that evaluate to a numeric value or to \NULL{}. | 2132 \item An expression of one of the forms \code{$-e$}, \code{$e_1 + e_2$}, \code{
$e_1$ - $e_2$}, \code{$e_1$ * $e_2$}, \code{$e_1$ / $e_2$,} \code{$e_1$ \~{}/ $e
_2$}, \code{$e_1 > e_2$}, \code{$e_1 < e_2$}, \code{$e_1$ $>$= $e_2$}, \cod
e{$e_1$ $<$= $e_2$} or \code{$e_1$ \% $e_2$}, where $e$, $e_1$ and $e_2$ are co
nstant expressions that evaluate to a numeric value or to \NULL{}. |
2132 \item An expression of the form \code{$e_1$?$e_2$:$e3$} where where $e_1$, $e_2$
and $e_3$ are constant expressions and $e_1$ evaluates to a boolean value. | 2133 \item An expression of the form \code{$e_1$?$e_2$:$e3$} where where $e_1$, $e_2$
and $e_3$ are constant expressions and $e_1$ evaluates to a boolean value. |
2133 \end{itemize} | 2134 \end{itemize} |
2134 | 2135 |
2135 % null in all the expressions | 2136 % null in all the expressions |
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2810 \item $T$ is not a parameterized type, then for $ i \in 1 .. l$, let $V_i = \D
YNAMIC{}$. | 2811 \item $T$ is not a parameterized type, then for $ i \in 1 .. l$, let $V_i = \D
YNAMIC{}$. |
2811 \item If $T$ is a parameterized type then let $V_i = U_i$ for $ i \in 1 .. m$.
| 2812 \item If $T$ is a parameterized type then let $V_i = U_i$ for $ i \in 1 .. m$.
|
2812 \end{itemize} | 2813 \end{itemize} |
2813 | 2814 |
2814 If $R$ is a generic with $l \ne m$ type parameters then for $ i \in 1 .. l$, let
$V_i = \DYNAMIC{}$. In any other case, let $V_i = U_i$ for $ i \in 1 .. m$. | 2815 If $R$ is a generic with $l \ne m$ type parameters then for $ i \in 1 .. l$, let
$V_i = \DYNAMIC{}$. In any other case, let $V_i = U_i$ for $ i \in 1 .. m$. |
2815 | 2816 |
2816 Evaluation of $e$ proceeds as follows: | 2817 Evaluation of $e$ proceeds as follows: |
2817 | 2818 |
2818 First, the argument list $(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}
: a_{n+k})$ is evaluated. | 2819 First, the argument list $(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}
: a_{n+k})$ is evaluated. |
2819 | 2820 |
| 2821 If $T$ is a deferred type with prefix $p$, then if $p$ has not been successfully
loaded, a dynamic error occurs. |
| 2822 |
2820 Then, if $q$ is a non-factory constructor of an abstract class then an \code{Abs
tractClassInstantiationError} is thrown. | 2823 Then, if $q$ is a non-factory constructor of an abstract class then an \code{Abs
tractClassInstantiationError} is thrown. |
2821 | 2824 |
2822 If $T$ is malformed or if $T$ is a type variable a dynamic error occurs. In che
cked mode, if $T$ or any of its superclasses is malbounded a dynamic error occur
s. | 2825 If $T$ is malformed or if $T$ is a type variable a dynamic error occurs. In che
cked mode, if $T$ or any of its superclasses is malbounded a dynamic error occur
s. |
2823 Otherwise, if $q$ is not defined or not accessible, a \code{NoSuchMethodError}
is thrown. If $q$ has less than $n$ positional parameters or more than $n$ req
uired parameters, or if $q$ lacks any of the keyword parameters $\{ x_{n+1}, \ld
ots, x_{n+k}\}$ a \code{NoSuchMethodError} is thrown. | 2826 Otherwise, if $q$ is not defined or not accessible, a \code{NoSuchMethodError}
is thrown. If $q$ has less than $n$ positional parameters or more than $n$ req
uired parameters, or if $q$ lacks any of the keyword parameters $\{ x_{n+1}, \ld
ots, x_{n+k}\}$ a \code{NoSuchMethodError} is thrown. |
2824 | 2827 |
2825 Otherwise, if $q$ is a generative constructor (\ref{generativeConstructors}), th
en: | 2828 Otherwise, if $q$ is a generative constructor (\ref{generativeConstructors}), th
en: |
2826 | 2829 |
2827 \commentary{Note that it this point we are assured that the number of actual typ
e arguments match the number of formal type parameters.} | 2830 \commentary{Note that it this point we are assured that the number of actual typ
e arguments match the number of formal type parameters.} |
2828 | 2831 |
2829 A fresh instance (\ref{generativeConstructors}), $i$, of class $R$ is allocated
. For each instance variable $f$ of $i$, if the variable declaration of $f$ has
an initializer expression $e_f$, then $e_f$ is evaluated to an object $o_f$ and
$f$ is bound to $o_f$. Otherwise $f$ is bound to \NULL{}. | 2832 A fresh instance (\ref{generativeConstructors}), $i$, of class $R$ is allocated
. For each instance variable $f$ of $i$, if the variable declaration of $f$ has
an initializer expression $e_f$, then $e_f$ is evaluated to an object $o_f$ and
$f$ is bound to $o_f$. Otherwise $f$ is bound to \NULL{}. |
2830 | 2833 |
2831 \commentary{ | 2834 \commentary{ |
2832 Observe that \THIS{} is not in scope in $e_f$. Hence, the initialization cannot
depend on other properties of the object being instantiated. | 2835 Observe that \THIS{} is not in scope in $e_f$. Hence, the initialization cannot
depend on other properties of the object being instantiated. |
2833 } | 2836 } |
2834 | 2837 |
2835 Next, $q$ is executed with \THIS{} bound to $i$, the type parameters (if any)
of $R$ bound to the actual type arguments $V_1, \ldots, V_l$ and the formal par
ameter bindings that resulted from the evaluation of the argument list. The resu
lt of the evaluation of $e$ is $i$. | 2838 Next, $q$ is executed with \THIS{} bound to $i$, the type parameters (if any)
of $R$ bound to the actual type arguments $V_1, \ldots, V_l$ and the formal par
ameter bindings that resulted from the evaluation of the argument list. The resu
lt of the evaluation of $e$ is $i$. |
2836 | 2839 |
2837 Otherwise, $q$ is a factory constructor (\ref{factories}). Then: | 2840 Otherwise, $q$ is a factory constructor (\ref{factories}). Then: |
2838 | 2841 |
2839 If $q$ is a redirecting factory constructor of the form $T(p_1, \ldots, p_{n+k})
= c;$ or of the form $T.id(p_1, \ldots, p_{n+k}) = c;$ then the result of the
evaluation of $e$ is equivalent to evaluating the expression | 2842 If $q$ is a redirecting factory constructor of the form $T(p_1, \ldots, p_{n+k})
= c;$ or of the form $T.id(p_1, \ldots, p_{n+k}) = c;$ then the result of the
evaluation of $e$ is equivalent to evaluating the expression |
2840 | 2843 |
2841 $[V_1, \ldots, V_m/T_1, \ldots, T_m]($\code{\NEW{} $c(a_1, \ldots, a_n, x_{n+1
}: a_{n+1}, \ldots, x_{n+k}: a_{n+k}))$}. | 2844 $[V_1, \ldots, V_m/T_1, \ldots, T_m]($\code{\NEW{} $c(a_1, \ldots, a_n, x_{n+1
}: a_{n+1}, \ldots, x_{n+k}: a_{n+k}))$}. If evaluation of $q$ causes $q$ to be
re-evaluated cyclically, a runtime error occurs. |
| 2845 |
2842 | 2846 |
2843 Otherwise, the body of $q$ is executed with respect to the bindings that resulte
d from the evaluation of the argument list and the type parameters (if any) of $
q$ bound to the actual type arguments $V_1, \ldots, V_l$ resulting in an object
$i$. The result of the evaluation of $e$ is $i$. | 2847 Otherwise, the body of $q$ is executed with respect to the bindings that resulte
d from the evaluation of the argument list and the type parameters (if any) of $
q$ bound to the actual type arguments $V_1, \ldots, V_l$ resulting in an object
$i$. The result of the evaluation of $e$ is $i$. |
2844 | 2848 |
2845 It is a static warning if $q$ is a constructor of an abstract class and $q$ is n
ot a factory constructor. | 2849 It is a static warning if $q$ is a constructor of an abstract class and $q$ is n
ot a factory constructor. |
2846 | 2850 |
2847 \commentary{The above gives precise meaning to the idea that instantiating an ab
stract class leads to a warning. | 2851 \commentary{The above gives precise meaning to the idea that instantiating an ab
stract class leads to a warning. |
2848 A similar clause applies to constant object creation in the next section. | 2852 A similar clause applies to constant object creation in the next section. |
2849 } | 2853 } |
2850 | 2854 |
2851 \rationale{In particular, a factory constructor can be declared in an abstract c
lass and used safely, as it will either produce a valid instance or lead to a wa
rning inside its own declaration. | 2855 \rationale{In particular, a factory constructor can be declared in an abstract c
lass and used safely, as it will either produce a valid instance or lead to a wa
rning inside its own declaration. |
(...skipping 20 matching lines...) Expand all Loading... |
2872 \begin{grammar} | 2876 \begin{grammar} |
2873 {\bf constObjectExpression:} | 2877 {\bf constObjectExpression:} |
2874 \CONST{} type ('{\escapegrammar .}' identifier)? arguments | 2878 \CONST{} type ('{\escapegrammar .}' identifier)? arguments |
2875 . | 2879 . |
2876 \end{grammar} | 2880 \end{grammar} |
2877 | 2881 |
2878 Let $e$ be a constant object expression of the form | 2882 Let $e$ be a constant object expression of the form |
2879 | 2883 |
2880 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ | 2884 \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ |
2881 | 2885 |
2882 or the form \CONST{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}:
a_{n+k})$. It is a compile-time error if $T$ does not denote a class accessible
in the current scope. | 2886 or the form \CONST{} $T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}:
a_{n+k})$. It is a compile-time error if $T$ does not denote a class accessible
in the current scope. It is a compile-time error if $T$ is a deferred type (\re
f{staticTypes}). |
2883 | 2887 |
2884 \commentary{In particular, $T$ may not be a type variable.} | 2888 \commentary{In particular, $T$ may not be a type variable.} |
2885 | 2889 |
2886 If $T$ is a parameterized type, it is a compile-time error if $T$ includes a typ
e variable among its type arguments. | 2890 If $T$ is a parameterized type, it is a compile-time error if $T$ includes a typ
e variable among its type arguments. |
2887 | 2891 |
2888 If $e$ is of the form \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots
, x_{n+k}: a_{n+k})$ it is a compile-time error if $T.id$ is not the name of a
constant constructor declared by the type $T$. If $e$ is of the form \CONST{} $
T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ it is a compi
le-time error if the type $T$ does not declare a constant constructor with the s
ame name as the declaration of $T$. | 2892 If $e$ is of the form \CONST{} $T.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots
, x_{n+k}: a_{n+k})$ it is a compile-time error if $T.id$ is not the name of a
constant constructor declared by the type $T$. If $e$ is of the form \CONST{} $
T(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ it is a compi
le-time error if the type $T$ does not declare a constant constructor with the s
ame name as the declaration of $T$. |
2889 | 2893 |
2890 In all of the above cases, it is a compile-time error if $a_i, i\in 1 .. n + k$
, is not a compile-time constant expression. | 2894 In all of the above cases, it is a compile-time error if $a_i, i\in 1 .. n + k$
, is not a compile-time constant expression. |
2891 | 2895 |
2892 %If $T$ is a parameterized type (\ref{parameterizedTypes}) $S<U_1, \ldots, U_m>
$, let $R = S$. It is a compile-time error if $T$ is is malformed. If $T$ is no
t a parameterized type, let $R = T$. | 2896 %If $T$ is a parameterized type (\ref{parameterizedTypes}) $S<U_1, \ldots, U_m>
$, let $R = S$. It is a compile-time error if $T$ is is malformed. If $T$ is no
t a parameterized type, let $R = T$. |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3141 | 3145 |
3142 \subsubsection{ Unqualified Invocation} | 3146 \subsubsection{ Unqualified Invocation} |
3143 \label{unqualifiedInvocation} | 3147 \label{unqualifiedInvocation} |
3144 | 3148 |
3145 An unqualified function invocation $i$ has the form | 3149 An unqualified function invocation $i$ has the form |
3146 | 3150 |
3147 $id(a_1, \ldots, a_n, x_{n+1}: a_{n+1}, \ldots, x_{n+k}: a_{n+k})$, | 3151 $id(a_1, \ldots, a_n, x_{n+1}: a_{n+1}, \ldots, x_{n+k}: a_{n+k})$, |
3148 | 3152 |
3149 where $id$ is an identifier or an identifier qualified with a library prefix. | 3153 where $id$ is an identifier or an identifier qualified with a library prefix. |
3150 | 3154 |
| 3155 If $id$ is qualified with a deferred prefix $p$ and $p$ has not been successfull
y loaded, then: |
| 3156 \begin{itemize} |
| 3157 \item |
| 3158 If the invocation has the form $p$\code{.loadLibrary()} then an attempt to load
the library represented by the prefix $p$ is initiated as discussed in section \
ref{imports}. |
| 3159 \item |
| 3160 Otherwise, a \code{NoSuchMethodError} is thrown. |
| 3161 \end{itemize} |
| 3162 |
3151 If there exists a lexically visible declaration named $id$, let $f_{id}$ be the
innermost such declaration. Then: | 3163 If there exists a lexically visible declaration named $id$, let $f_{id}$ be the
innermost such declaration. Then: |
3152 \begin{itemize} | 3164 \begin{itemize} |
3153 \item | 3165 \item |
3154 If $f_{id}$ is a local function, a library function, a library or static getter
or a variable then $i$ is interpreted as a function expression invocation (\ref
{functionExpressionInvocation}). | 3166 If $f_{id}$ is a local function, a library function, a library or static getter
or a variable then $i$ is interpreted as a function expression invocation (\ref
{functionExpressionInvocation}). |
3155 \item | 3167 \item |
3156 Otherwise, if $f_{id}$ is a static method of the enclosing class $C$, $i$ is equ
ivalent to $C.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})
$. | 3168 Otherwise, if $f_{id}$ is a static method of the enclosing class $C$, $i$ is equ
ivalent to $C.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})
$. |
3157 \item Otherwise, $f_{id}$ is considered equivalent to the ordinary method invoca
tion $\THIS{}.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})
$. | 3169 \item Otherwise, $f_{id}$ is considered equivalent to the ordinary method invoca
tion $\THIS{}.id(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})
$. |
3158 \end{itemize} | 3170 \end{itemize} |
3159 | 3171 |
3160 %Otherwise, if there is an accessible (\ref{privacy}) static method named $id$ d
eclared in a superclass $S$ of the immediately enclosing class $C$ then i is equ
ivalent to the static method invocation $S.id(a_1, \ldots, a_n, x_{n+1}: a_{n+1}
, \ldots, x_{n+k}: a_{n+k})$. | 3172 %Otherwise, if there is an accessible (\ref{privacy}) static method named $id$ d
eclared in a superclass $S$ of the immediately enclosing class $C$ then i is equ
ivalent to the static method invocation $S.id(a_1, \ldots, a_n, x_{n+1}: a_{n+1}
, \ldots, x_{n+k}: a_{n+k})$. |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3298 Note that the absence of $C.m$ is statically detectable. Nevertheless, we choose
not to define this situation as an error. The goal is to allow coding to proce
ed in the order that suits the developer rather than eagerly insisting on consis
tency. The warnings are given statically at compile-time to help developers catc
h errors. However, developers need not correct these problems immediately in ord
er to make progress. | 3310 Note that the absence of $C.m$ is statically detectable. Nevertheless, we choose
not to define this situation as an error. The goal is to allow coding to proce
ed in the order that suits the developer rather than eagerly insisting on consis
tency. The warnings are given statically at compile-time to help developers catc
h errors. However, developers need not correct these problems immediately in ord
er to make progress. |
3299 } | 3311 } |
3300 | 3312 |
3301 \commentary{ | 3313 \commentary{ |
3302 Note the requirement that $C$ {\em declare} the method. This means that static m
ethods declared in superclasses of $C$ cannot be invoked via $C$. | 3314 Note the requirement that $C$ {\em declare} the method. This means that static m
ethods declared in superclasses of $C$ cannot be invoked via $C$. |
3303 } | 3315 } |
3304 | 3316 |
3305 | 3317 |
3306 Evaluation of $i$ proceeds as follows: | 3318 Evaluation of $i$ proceeds as follows: |
3307 | 3319 |
3308 If $C$ does not declare a static method or getter $m$ then the argument list $(a
_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ is evaluated, af
ter which a \code{NoSuchMethodError} is thrown. | 3320 If $C$ is a deferred type (\ref{staticTypes}) with prefix $p$, and $p$ has not
been successfully loaded, or |
| 3321 if $C$ does not declare a static method or getter $m$ then the argument list $(a
_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$ is evaluated, af
ter which a \code{NoSuchMethodError} is thrown. |
3309 | 3322 |
3310 Otherwise, evaluation proceeds as follows: | 3323 Otherwise, evaluation proceeds as follows: |
3311 \begin{itemize} | 3324 \begin{itemize} |
3312 \item | 3325 \item |
3313 If the member $m$ declared by $C$ is a getter, then $i$ is equivalent to the exp
ression $(C.m)(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$.
| 3326 If the member $m$ declared by $C$ is a getter, then $i$ is equivalent to the exp
ression $(C.m)(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$.
|
3314 \item Otherwise, let $f$ be the the method $m$ declared in class $C$. Next, the
argument list $(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$
is evaluated. | 3327 \item Otherwise, let $f$ be the the method $m$ declared in class $C$. Next, the
argument list $(a_1, \ldots , a_n, x_{n+1}: a_{n+1}, \ldots , x_{n+k}: a_{n+k})$
is evaluated. |
3315 The body of $f$ is then executed with respect to the bindings that resulted from
the evaluation of the argument list. The value of $i$ is the value returned aft
er the body of $f$ is executed. | 3328 The body of $f$ is then executed with respect to the bindings that resulted from
the evaluation of the argument list. The value of $i$ is the value returned aft
er the body of $f$ is executed. |
3316 \end{itemize} | 3329 \end{itemize} |
3317 | 3330 |
3318 It is a static type warning if the type $F$ of $C.m$ may not be assigned to a fu
nction type. If $F$ is not a function type, or if $C.m$ does not exist, the sta
tic type of $i$ is \DYNAMIC{}. Otherwise | 3331 It is a static type warning if the type $F$ of $C.m$ may not be assigned to a fu
nction type. If $F$ is not a function type, or if $C.m$ does not exist, the sta
tic type of $i$ is \DYNAMIC{}. Otherwise |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3424 | 3437 |
3425 If the getter lookup has failed, then a new instance $im$ of the predefined cla
ss \code{Invocation} is created, such that : | 3438 If the getter lookup has failed, then a new instance $im$ of the predefined cla
ss \code{Invocation} is created, such that : |
3426 \begin{itemize} | 3439 \begin{itemize} |
3427 \item \code{im.isGetter} evaluates to \code{\TRUE{}}. | 3440 \item \code{im.isGetter} evaluates to \code{\TRUE{}}. |
3428 \item \code{im.memberName} evaluates to \code{'m'}. | 3441 \item \code{im.memberName} evaluates to \code{'m'}. |
3429 \item \code{im.positionalArguments} evaluates to the value of \code{\CONST{} []}
. | 3442 \item \code{im.positionalArguments} evaluates to the value of \code{\CONST{} []}
. |
3430 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}. | 3443 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}. |
3431 \end{itemize} | 3444 \end{itemize} |
3432 Then the method \code{noSuchMethod()} is looked up in $S$ and invoked with argu
ment $im$, and the result of this invocation is the result of evaluating $i$. | 3445 Then the method \code{noSuchMethod()} is looked up in $S$ and invoked with argu
ment $im$, and the result of this invocation is the result of evaluating $i$. |
3433 | 3446 |
| 3447 |
| 3448 |
3434 It is a static type warning if $S$ does not have a getter named $m$. The static
type of $i$ is the declared return type of $S.m$, if $S.m$ exists; otherwise th
e static type of $i$ is \DYNAMIC{}. | 3449 It is a static type warning if $S$ does not have a getter named $m$. The static
type of $i$ is the declared return type of $S.m$, if $S.m$ exists; otherwise th
e static type of $i$ is \DYNAMIC{}. |
3435 | 3450 |
| 3451 Evaluation of a getter invocation of the form $p.C.v$, where $p$ is a deferred p
refix, proceeds as follows: |
| 3452 |
| 3453 If $p$ has been successfully loaded, the assignment is evaluated exactly like th
e invocation $K.v$, where $K$ denotes the top level member $C$ of the library re
presented by $p$. Otherwise a \code{NoSuchMethodError} is thrown. |
| 3454 |
| 3455 |
| 3456 Evaluation of a top-level getter invocation $i$ of the form $p.m$, where $p$ is
a deferred prefix and $m$ is an identifier, proceeds as follows: |
| 3457 |
| 3458 If $p$ has been successfully loaded, the invocation is evaluated exactly like th
e invocation $w$, where $w$ denotes the top level member named $m$ of the librar
y represented by $p$. Otherwise a \code{NoSuchMethodError} is thrown. |
3436 | 3459 |
3437 | 3460 |
3438 | 3461 |
3439 \subsection{ Assignment} | 3462 \subsection{ Assignment} |
3440 \label{assignment} | 3463 \label{assignment} |
3441 | 3464 |
3442 An assignment changes the value associated with a mutable variable or property. | 3465 An assignment changes the value associated with a mutable variable or property. |
3443 | 3466 |
3444 \begin{grammar} | 3467 \begin{grammar} |
3445 {\bf assignmentOperator:}`=' ; | 3468 {\bf assignmentOperator:}`=' ; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3500 If the setter lookup has failed, then a new instance $im$ of the predefined cla
ss \code{Invocation} is created, such that : | 3523 If the setter lookup has failed, then a new instance $im$ of the predefined cla
ss \code{Invocation} is created, such that : |
3501 \begin{itemize} | 3524 \begin{itemize} |
3502 \item \code{im.isSetter} evaluates to \code{\TRUE{}}. | 3525 \item \code{im.isSetter} evaluates to \code{\TRUE{}}. |
3503 \item \code{im.memberName} evaluates to \code{'v='}. | 3526 \item \code{im.memberName} evaluates to \code{'v='}. |
3504 \item \code{im.positionalArguments} evaluates to an immutable list with the same
values as \code{[$o_2$]}. | 3527 \item \code{im.positionalArguments} evaluates to an immutable list with the same
values as \code{[$o_2$]}. |
3505 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}. | 3528 \item \code{im.namedArguments} evaluates to the value of \code{\CONST{} \{\}}. |
3506 \end{itemize} | 3529 \end{itemize} |
3507 | 3530 |
3508 Then the method \code{noSuchMethod()} is looked up in $o_1$ and invoked with ar
gument $im$. The value of the assignment expression is $o_2$ irrespective of whe
ther setter lookup has failed or succeeded. | 3531 Then the method \code{noSuchMethod()} is looked up in $o_1$ and invoked with ar
gument $im$. The value of the assignment expression is $o_2$ irrespective of whe
ther setter lookup has failed or succeeded. |
3509 | 3532 |
| 3533 Evaluation of an assignment of the form $p.v \code{=} e$, where $p$ is a deferre
d prefix, proceeds as follows: |
| 3534 |
| 3535 If $p$ has been successfully loaded, the assignment is evaluated exactly like th
e assignment $w \code{=} e$, where $w$ denotes the top level member named $v$ of
the library represented by $p$. Otherwise, $e$ is evaluated and then a \code{No
SuchMethodError} is thrown. |
| 3536 |
| 3537 Evaluation of an assignment of the form $p.C.v \code{=} e$, where $p$ is a defer
red prefix, proceeds as follows: |
| 3538 |
| 3539 If $p$ has been successfully loaded, the assignment is evaluated exactly like th
e assignment $K.v = e$, where $K$ denotes the top level member $C$ of the librar
y represented by $p$. Otherwise $e$ is evaluated and then a \code{NoSuchMethodEr
ror} is thrown. |
| 3540 |
3510 In checked mode, it is a dynamic type error if $o_2$ is not \NULL{} and the inte
rface of the class of $o_2$ is not a subtype of the actual type of $e_1.v$. | 3541 In checked mode, it is a dynamic type error if $o_2$ is not \NULL{} and the inte
rface of the class of $o_2$ is not a subtype of the actual type of $e_1.v$. |
3511 | 3542 |
3512 Let $T$ be the static type of $e_1$. It is a static type warning if $T$ does not
have an accessible instance setter named $v=$ unless $T$ or a superinterface of
$T$ is annotated with an annotation denoting a constant identical to the consta
nt \code{@proxy} defined in \code{dart:core}. It is a static type warning if the
static type of $e_2$ may not be assigned to $T$. The static type of the expre
ssion $e_1v$ \code{=} $e_2$ is the static type of $e_2$. | 3543 Let $T$ be the static type of $e_1$. It is a static type warning if $T$ does not
have an accessible instance setter named $v=$ unless $T$ or a superinterface of
$T$ is annotated with an annotation denoting a constant identical to the consta
nt \code{@proxy} defined in \code{dart:core}. It is a static type warning if the
static type of $e_2$ may not be assigned to $T$. The static type of the expre
ssion $e_1v$ \code{=} $e_2$ is the static type of $e_2$. |
3513 | 3544 |
3514 Evaluation of an assignment of the form $e_1[e_2]$ \code{=} $e_3$ is equivalent
to the evaluation of the expression \code{(a, i, e)\{a.[]=(i, e); \RETURN{} e; \
} ($e_1, e_2, e_3$)}. The static type of the expression $e_1[e_2]$ \code{=} $e_
3$ is the static type of $e_3$. | 3545 Evaluation of an assignment of the form $e_1[e_2]$ \code{=} $e_3$ is equivalent
to the evaluation of the expression \code{(a, i, e)\{a.[]=(i, e); \RETURN{} e; \
} ($e_1, e_2, e_3$)}. The static type of the expression $e_1[e_2]$ \code{=} $e_
3$ is the static type of $e_3$. |
3515 | 3546 |
3516 % Should we add: It is a dynamic error if $e_1$ evaluates to an constant list o
r map. | 3547 % Should we add: It is a dynamic error if $e_1$ evaluates to an constant list o
r map. |
3517 | 3548 |
3518 It is as static warning if an assignment of the form $v = e$ occurs inside a top
level or static function (be it function, method, getter, or setter) or variabl
e initializer and there is neither a local variable declaration with name $v$ n
or setter declaration with name $v=$ in the lexical scope enclosing the assignme
nt. | 3549 It is as static warning if an assignment of the form $v = e$ occurs inside a top
level or static function (be it function, method, getter, or setter) or variabl
e initializer and there is neither a local variable declaration with name $v$ n
or setter declaration with name $v=$ in the lexical scope enclosing the assignme
nt. |
3519 | 3550 |
3520 | 3551 |
3521 | 3552 |
3522 \subsubsection{Compound Assignment} | 3553 \subsubsection{Compound Assignment} |
3523 \label{compoundAssignment} | 3554 \label{compoundAssignment} |
3524 | 3555 |
3525 A compound assignment of the form $v$ $op\code{=} e$ is equivalent to $v \code{=
} v$ $op$ $e$. A compound assignment of the form $C.v$ $op \code{=} e$ is equiva
lent to $C.v \code{=} C.v$ $op$ $e$. A compound assignment of the form $e_1.v$ $
op = e_2$ is equivalent to \code{((x) $=>$ x.v = x.v $op$ $e_2$)($e_1$)} where $
x$ is a variable that is not used in $e_2$. A compound assignment of the form $
e_1[e_2]$ $op\code{=} e_3$ is equivalent to | 3556 A compound assignment of the form $v$ $op\code{=} e$ is equivalent to $v \code{=
} v$ $op$ $e$. A compound assignment of the form $C.v$ $op \code{=} e$ is equiva
lent to $C.v \code{=} C.v$ $op$ $e$. A compound assignment of the form $e_1.v$ $
op = e_2$ is equivalent to \code{((x) $=>$ x.v = x.v $op$ $e_2$)($e_1$)} where $
x$ is a variable that is not used in $e_2$. A compound assignment of the form $
e_1[e_2]$ $op\code{=} e_3$ is equivalent to |
3526 \code{((a, i) $=>$ a[i] = a[i] $op$ $e_3$)($e_1, e_2$)} where $a$ and $i$ are a
variables that are not used in $e_3$. | 3557 \code{((a, i) $=>$ a[i] = a[i] $op$ $e_3$)($e_1, e_2$)} where $a$ and $i$ are a
variables that are not used in $e_3$. A compound assignment of the form $p.v$ $o
p\code{=} e$, where $p$ is a deferred prefix, is equivalent to $p.v \code{=} p.
v$ $op$ $e$. A compound assignment of the form $p.C.v$ $op\code{=} e$, where $p$
is a deferred prefix, is equivalent to $p.C.v \code{=} p.C.v$ $op$ $e$. |
| 3558 |
3527 | 3559 |
3528 \begin{grammar} | 3560 \begin{grammar} |
3529 {\bf compoundAssignmentOperator:}`*='; | 3561 {\bf compoundAssignmentOperator:}`*='; |
3530 `/='; | 3562 `/='; |
3531 `\~{}/='; | 3563 `\~{}/='; |
3532 `\%='; | 3564 `\%='; |
3533 `+='; | 3565 `+='; |
3534 `-='; | 3566 `-='; |
3535 `{\escapegrammar \lt \lt}='; | 3567 `{\escapegrammar \lt \lt}='; |
3536 `{\escapegrammar \gt \gt}='; | 3568 `{\escapegrammar \gt \gt}='; |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4065 . | 4097 . |
4066 | 4098 |
4067 | 4099 |
4068 {\bf isOperator:} | 4100 {\bf isOperator:} |
4069 \IS{} `!'? | 4101 \IS{} `!'? |
4070 . | 4102 . |
4071 \end{grammar} | 4103 \end{grammar} |
4072 | 4104 |
4073 Evaluation of the is-expression \code{$e$ \IS{} $T$} proceeds as follows: | 4105 Evaluation of the is-expression \code{$e$ \IS{} $T$} proceeds as follows: |
4074 | 4106 |
4075 The expression $e$ is evaluated to a value $v$. Then, if $T$ is malformed, a dyn
amic error occurs. Otherwise, if the interface of the class of $v$ is a subtype
of $T$, the is-expression evaluates to true. Otherwise it evaluates to false. | 4107 The expression $e$ is evaluated to a value $v$. Then, if $T$ is a malformed or d
eferred type (\ref{staticTypes}), a dynamic error occurs. Otherwise, if the inte
rface of the class of $v$ is a subtype of $T$, the is-expression evaluates to tr
ue. Otherwise it evaluates to false. |
4076 | 4108 |
4077 \commentary{It follows that \code{$e$ \IS{} Object} is always true. This makes s
ense in a language where everything is an object. | 4109 \commentary{It follows that \code{$e$ \IS{} Object} is always true. This makes s
ense in a language where everything is an object. |
4078 | 4110 |
4079 Also note that \code{\NULL{} \IS{} $T$} is false unless $T = \code{Object}$, $T
= \code{\DYNAMIC{}}$ or $T = \code{Null}$. The former two are useless, as is an
ything of the form \code{$e$ \IS{} Object} or \code{$e$ \IS{} \DYNAMIC{}}. User
s should test for a null value directly rather than via type tests. | 4111 Also note that \code{\NULL{} \IS{} $T$} is false unless $T = \code{Object}$, $T
= \code{\DYNAMIC{}}$ or $T = \code{Null}$. The former two are useless, as is an
ything of the form \code{$e$ \IS{} Object} or \code{$e$ \IS{} \DYNAMIC{}}. User
s should test for a null value directly rather than via type tests. |
4080 } | 4112 } |
4081 | 4113 |
4082 The is-expression \code{$e$ \IS{}! $T$} is equivalent to \code{!($e$ \IS{} $T$)}
. | 4114 The is-expression \code{$e$ \IS{}! $T$} is equivalent to \code{!($e$ \IS{} $T$)}
. |
4083 | 4115 |
4084 % Add flow dependent types | 4116 % Add flow dependent types |
4085 | 4117 |
(...skipping 24 matching lines...) Expand all Loading... |
4110 . | 4142 . |
4111 | 4143 |
4112 | 4144 |
4113 {\bf asOperator:} | 4145 {\bf asOperator:} |
4114 \AS{} | 4146 \AS{} |
4115 . | 4147 . |
4116 \end{grammar} | 4148 \end{grammar} |
4117 | 4149 |
4118 Evaluation of the cast expression \code{$e$ \AS{} $T$} proceeds as follows: | 4150 Evaluation of the cast expression \code{$e$ \AS{} $T$} proceeds as follows: |
4119 | 4151 |
4120 The expression $e$ is evaluated to a value $v$. Then, if $T$ is malformed, a dyn
amic error occurs. Otherwise, if the interface of the class of $v$ is a subtype
of $T$, the cast expression evaluates to $v$. Otherwise, if $v$ is \NULL{}, the
cast expression evaluates to $v$. | 4152 The expression $e$ is evaluated to a value $v$. Then, if $T$ is a malformed or d
eferred type (\ref{staticTypes}), a dynamic error occurs. Otherwise, if the inte
rface of the class of $v$ is a subtype of $T$, the cast expression evaluates to
$v$. Otherwise, if $v$ is \NULL{}, the cast expression evaluates to $v$. |
4121 In all other cases, a \code{CastError} is thrown. | 4153 In all other cases, a \code{CastError} is thrown. |
4122 | 4154 |
4123 The static type of a cast expression \code{$e$ \AS{} $T$} is $T$. | 4155 The static type of a cast expression \code{$e$ \AS{} $T$} is $T$. |
4124 | 4156 |
4125 | 4157 |
4126 \section{Statements} | 4158 \section{Statements} |
4127 \label{statements} | 4159 \label{statements} |
4128 | 4160 |
4129 \begin{grammar} | 4161 \begin{grammar} |
4130 {\bf statements:} | 4162 {\bf statements:} |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4498 it is a compile-time error if the expressions $e_k$ are not compile-time consta
nts for all $k \in 1..n$. It is a compile-time error if the values of the expr
essions $e_k$ are not either: | 4530 it is a compile-time error if the expressions $e_k$ are not compile-time consta
nts for all $k \in 1..n$. It is a compile-time error if the values of the expr
essions $e_k$ are not either: |
4499 \begin{itemize} | 4531 \begin{itemize} |
4500 \item instances of the same class $C$, for all $k \in 1..n$, or | 4532 \item instances of the same class $C$, for all $k \in 1..n$, or |
4501 \item instances of a class that implements \cd{int}, for all $k \in 1..n$, or | 4533 \item instances of a class that implements \cd{int}, for all $k \in 1..n$, or |
4502 \item instances of a class that implements \cd{String}, for all $k \in 1..n$. | 4534 \item instances of a class that implements \cd{String}, for all $k \in 1..n$. |
4503 \end{itemize} | 4535 \end{itemize} |
4504 | 4536 |
4505 \commentary{In other words, all the expressions in the cases evaluate to consta
nts of the exact same user defined class or are of certain known types. Note th
at the values of the expressions are known at compile-time, and are independent
of any static type annotations. | 4537 \commentary{In other words, all the expressions in the cases evaluate to consta
nts of the exact same user defined class or are of certain known types. Note th
at the values of the expressions are known at compile-time, and are independent
of any static type annotations. |
4506 } | 4538 } |
4507 | 4539 |
4508 It is a compile-time error if the class $C$ has an implementation of the operato
r $==$ other than the one inherited from \code{Object} unless the value of the e
xpression is a string, an integer, literal symbol or the result of invoking a co
nstant constructor class \cd{Symbol}. | 4540 It is a compile-time error if the class $C$ has an implementation of the operato
r $==$ other than the one inherited from \code{Object} unless the value of the e
xpression is a string, an integer, literal symbol or the result of invoking a co
nstant constructor of class \cd{Symbol}. |
4509 | 4541 |
4510 \rationale{ | 4542 \rationale{ |
4511 The prohibition on user defined equality allows us to implement the switch effi
ciently for user defined types. We could formulate matching in terms of identity
instead with the same efficiency. However, if a type defines an equality operat
or, programmers would find it quite surprising that equal objects did not match. | 4543 The prohibition on user defined equality allows us to implement the switch effi
ciently for user defined types. We could formulate matching in terms of identity
instead with the same efficiency. However, if a type defines an equality operat
or, programmers would find it quite surprising that equal objects did not match. |
4512 | 4544 |
4513 } | 4545 } |
4514 | 4546 |
4515 \commentary{ | 4547 \commentary{ |
4516 The \SWITCH{} statement should only be used in very limited situations (e.g., i
nterpreters or scanners). | 4548 The \SWITCH{} statement should only be used in very limited situations (e.g., i
nterpreters or scanners). |
4517 } | 4549 } |
4518 | 4550 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4657 \item | 4689 \item |
4658 A set of \ON{}-\CATCH{} clauses, each of which specifies (either explicitly or
implicitly) the type of exception object to be handled, one or two exception par
ameters and a block statement. | 4690 A set of \ON{}-\CATCH{} clauses, each of which specifies (either explicitly or
implicitly) the type of exception object to be handled, one or two exception par
ameters and a block statement. |
4659 \item | 4691 \item |
4660 A \FINALLY{} clause, which consists of a block statement. | 4692 A \FINALLY{} clause, which consists of a block statement. |
4661 \end{enumerate} | 4693 \end{enumerate} |
4662 | 4694 |
4663 \rationale{ | 4695 \rationale{ |
4664 The syntax is designed to be upward compatible with existing Javascript programs
. The \ON{} clause can be omitted, leaving what looks like a Javascript catch cl
ause. | 4696 The syntax is designed to be upward compatible with existing Javascript programs
. The \ON{} clause can be omitted, leaving what looks like a Javascript catch cl
ause. |
4665 } | 4697 } |
4666 | 4698 |
4667 An \ON{}-\CATCH{} clause of the form \code{\ON{} $T$ \CATCH{} ($p_1, p_2$) $s$
} {\em matches} an object $o$ if the type of $o$ is a subtype of $T$. If $T$
is a malformed type, then performing a match causes a run time error. | 4699 An \ON{}-\CATCH{} clause of the form \code{\ON{} $T$ \CATCH{} ($p_1, p_2$) $s$
} {\em matches} an object $o$ if the type of $o$ is a subtype of $T$. If $T$
is a malformed or deferred type (\ref{staticTypes}), then performing a match ca
uses a run time error. |
4668 | 4700 |
4669 \commentary { | 4701 \commentary { |
4670 It is of course a static warning if $T$ is a malformed type (\ref{staticTypes}). | 4702 It is of course a static warning if $T$ is a deferred or malformed type. |
4671 } | 4703 } |
4672 | 4704 |
4673 An \ON{}-\CATCH{} clause of the form \code{\ON{} $T$ \CATCH{} ($p_1, p_2$) $s$
} introduces a new scope $CS$ in which local variables specified by $p_1$ and $p
_2$ are defined. The statement $s$ is enclosed within $CS$. | 4705 An \ON{}-\CATCH{} clause of the form \code{\ON{} $T$ \CATCH{} ($p_1, p_2$) $s$
} introduces a new scope $CS$ in which local variables specified by $p_1$ and $p
_2$ are defined. The statement $s$ is enclosed within $CS$. |
4674 | 4706 |
4675 | 4707 |
4676 An \ON{}-\CATCH{} clause of the form \code{\ON{} $T$ \CATCH{} ($p_1$) $s$} is e
quivalent to an \ON{}-\CATCH{} clause \code{\ON{} $T$ \CATCH{} ($p_1, p_2$) $s$
} where $p_2$ is an identifier that does not occur anywhere else in the program.
| 4708 An \ON{}-\CATCH{} clause of the form \code{\ON{} $T$ \CATCH{} ($p_1$) $s$} is e
quivalent to an \ON{}-\CATCH{} clause \code{\ON{} $T$ \CATCH{} ($p_1, p_2$) $s$
} where $p_2$ is an identifier that does not occur anywhere else in the program.
|
4677 | 4709 |
4678 | 4710 |
4679 An \ON{}-\CATCH{} clause of the form \code{\CATCH{} ($p$) $s$} is equivalent to
an \ON{}-\CATCH{} clause \code{\ON{} \DYNAMIC{} \CATCH{} ($p$) $s$}. An \ON{}-
\CATCH{} clause of the form \code{\CATCH{} ($p_1, p_2$) $s$} is equivalent to a
n \ON{}-\CATCH{} clause \code{\ON{} \DYNAMIC{} \CATCH{} ($p_1, p_2$) $s$} | 4711 An \ON{}-\CATCH{} clause of the form \code{\CATCH{} ($p$) $s$} is equivalent to
an \ON{}-\CATCH{} clause \code{\ON{} \DYNAMIC{} \CATCH{} ($p$) $s$}. An \ON{}-
\CATCH{} clause of the form \code{\CATCH{} ($p_1, p_2$) $s$} is equivalent to a
n \ON{}-\CATCH{} clause \code{\ON{} \DYNAMIC{} \CATCH{} ($p_1, p_2$) $s$} |
4680 | 4712 |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4995 The {\em public namespace} of library $L$ is the mapping that maps the simple na
me of each public top-level member $m$ of $L$ to $m$. | 5027 The {\em public namespace} of library $L$ is the mapping that maps the simple na
me of each public top-level member $m$ of $L$ to $m$. |
4996 The scope of a library $L$ consists of the names introduced by all top-level dec
larations declared in $L$, and the names added by $L$'s imports (\ref{imports}). | 5028 The scope of a library $L$ consists of the names introduced by all top-level dec
larations declared in $L$, and the names added by $L$'s imports (\ref{imports}). |
4997 | 5029 |
4998 | 5030 |
4999 \subsection{Imports} | 5031 \subsection{Imports} |
5000 \label{imports} | 5032 \label{imports} |
5001 | 5033 |
5002 An {\em import} specifies a library to be used in the scope of another library. | 5034 An {\em import} specifies a library to be used in the scope of another library. |
5003 \begin{grammar} | 5035 \begin{grammar} |
5004 {\bf libraryImport:} | 5036 {\bf libraryImport:} |
5005 metadata \IMPORT{} uri (\AS{} identifier)? combinator* `{\escapegrammar ;}' | 5037 metadata importSpecification |
5006 . | 5038 . |
5007 | 5039 |
| 5040 {\bf importSpecification:} |
| 5041 \IMPORT{} uri (\AS{} identifier)? combinator* `{\escapegrammar ;}'; |
| 5042 \IMPORT{} uri \DEFERRED{} \AS{} identifier combinator* `{\escapegrammar ;
}' |
| 5043 . |
| 5044 |
5008 {\bf combinator:}\SHOW{} identifierList; | 5045 {\bf combinator:}\SHOW{} identifierList; |
5009 \HIDE{} identifierList | 5046 \HIDE{} identifierList |
5010 . | 5047 . |
5011 | 5048 |
5012 {\bf identifierList:} | 5049 {\bf identifierList:} |
5013 identifier (, identifier)* | 5050 identifier (, identifier)* |
5014 \end{grammar} | 5051 \end{grammar} |
5015 | 5052 |
5016 | 5053 |
5017 An import specifies a URI $x$ where the declaration of an imported library is to
be found. It is a compile-time error if the specified URI does not refer to a
library declaration. The interpretation of URIs is described in section \ref{ur
is} below. | 5054 An import specifies a URI $x$ where the declaration of an imported library is to
be found. |
| 5055 |
| 5056 Imports may be {\em deferred} or {\em immediate}. A deferred import is distingui
shed by the appearance of the built-in identifier \DEFERRED{} after the URI. Any
import that is not deferred is immediate. |
| 5057 |
| 5058 It is a compile-time error if the specified URI of an immediate import does not
refer to a library declaration. The interpretation of URIs is described in sec
tion \ref{uris} below. |
| 5059 |
| 5060 It is a static warning if the specified URI of a deferred import does not refer
to a library declaration. |
| 5061 |
| 5062 \rationale{ |
| 5063 One cannot detect the problem at compile time because compilation often occurs
during execution and one does not know what the URI refers to. However the dev
elopment environment should detect the problem. |
| 5064 } |
| 5065 |
5018 | 5066 |
5019 The {\em current library} is the library currently being compiled. The import mo
difies the namespace of the current library in a manner that is determined by t
he imported library and by the optional elements of the import. | 5067 The {\em current library} is the library currently being compiled. The import mo
difies the namespace of the current library in a manner that is determined by t
he imported library and by the optional elements of the import. |
5020 | 5068 |
5021 An import directive $I$ may optionally include: | 5069 An immediate import directive $I$ may optionally include a prefix clause of the
form \AS{} \code{Id} used to prefix names imported by $I$. A deferred import mus
t include a prefix clause or a compile time error occurs. It is a compile-time e
rror if a prefix used in a deferred import is used in another import clause. |
5022 \begin{itemize} | 5070 |
5023 \item A prefix clause of the form \AS{} \code{Id} used to prefix names imported
by $I$. | 5071 An import directive $I$ may optionally include a namespace combinator clauses us
ed to restrict the set of names imported by $I$. Currently, two namespace combin
ators are supported: \HIDE{} and \SHOW{}. |
5024 \item Namespace combinator clauses used to restrict the set of names imported by
$I$. Currently, two namespace combinators are supported: \HIDE{} and \SHOW{}. | |
5025 \end{itemize} | |
5026 | 5072 |
5027 Let $I$ be an import directive that refers to a URI via the string $s_1$. Evalua
tion of $I$ proceeds as follows: | 5073 Let $I$ be an import directive that refers to a URI via the string $s_1$. Evalua
tion of $I$ proceeds as follows: |
5028 | 5074 |
5029 First, | 5075 If $I$ is a deferred import, no evaluation takes place. Instead, the following n
ames are added to the scope of $L$: |
| 5076 \begin{itemize} |
| 5077 \item |
| 5078 The name of the prefix, $p$ denoting a deferred prefix declaration. |
| 5079 \item |
| 5080 The name \code{$p$.loadLibrary}, denoting a top level function with no arguments
, whose semantics are described below. |
| 5081 \end{itemize} |
| 5082 |
| 5083 A deferred prefix $p$ may be loaded explicitly via the function call \code{$p$.l
oadLibrary}, which returns a future $f$. The effect of the call is to cause an i
mmediate import $IÕ$ to be executed at some future time, where $IÕ$ is is derive
d from $I$ by eliding the word \DEFERRED{} and adding a \HIDE{} \code{loadLibrar
y} combinator clause. When $IÕ$ executes without error, $f$ completes successfu
lly. If $IÕ$ executes without error, we say that the call to \code{$p$.loadLibra
ry} has succeeded, otherwise we say the call has failed. |
| 5084 |
| 5085 After a call succeeds, the names $p$ and \code{$p$.loadLibrary} remain in the to
p-level scope of $L$, and so it is possible to call \code{loadLibrary} again. If
a call fails, nothing happens, and one again has the option to call \code{loadL
ibrary} again. Whether a repeated call to \code{loadLibrary} succeeds will vary
as described below. |
| 5086 |
| 5087 The effect of a repeated call to \code{$p$.loadLibrary} is as follows: |
| 5088 \begin{itemize} |
| 5089 \item |
| 5090 If another call to \code{$p$.loadLibrary} has already succeeded, the repeated ca
ll also succeeds. |
| 5091 Otherwise, |
| 5092 \item |
| 5093 If another call to to \code{$p$.loadLibrary} has failed: |
| 5094 \begin{itemize} |
| 5095 \item |
| 5096 If the failure is due to a compilation error, the repeated call fails for the sa
me reason. |
| 5097 \item |
| 5098 If the failure is due to other causes, the repeated call behaves as if no previo
us call had been made. |
| 5099 \end{itemize} |
| 5100 \end{itemize} |
| 5101 |
| 5102 \commentary{ |
| 5103 In other words, one can retry a deferred load after a network failure or because
a file is absent, but once one finds some content and loads it, one can no long
er reload. |
| 5104 |
| 5105 We do not specify what value the future returned resolves to. |
| 5106 } |
| 5107 |
| 5108 If $I$ is an immediate import then, first |
5030 | 5109 |
5031 \begin{itemize} | 5110 \begin{itemize} |
5032 \item | 5111 \item |
5033 If the URI that is the value of $s_1$ has not yet been accessed by an import or
export (\ref{exports}) directive in the current isolate then the contents of t
he URI are compiled to yield a library $B$. \commentary{Because libraries may h
ave mutually recursive imports, care must be taken to avoid an infinite regress. | 5112 If the URI that is the value of $s_1$ has not yet been accessed by an import or
export (\ref{exports}) directive in the current isolate then the contents of t
he URI are compiled to yield a library $B$. \commentary{Because libraries may h
ave mutually recursive imports, care must be taken to avoid an infinite regress. |
5034 } | 5113 } |
5035 \item Otherwise, the contents of the URI denoted by $s_1$ have been compiled int
o a library $B$ within the current isolate. | 5114 \item Otherwise, the contents of the URI denoted by $s_1$ have been compiled int
o a library $B$ within the current isolate. |
5036 \end{itemize} | 5115 \end{itemize} |
5037 | 5116 |
5038 | 5117 |
5039 Let $NS_0$ be the exported namespace (\ref{exports}) of $B$. Then, for each comb
inator clause $C_i, i \in 1..n$ in $I$: | 5118 Let $NS_0$ be the exported namespace (\ref{exports}) of $B$. Then, for each comb
inator clause $C_i, i \in 1..n$ in $I$: |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5331 % \item Let $T_i$ be the type parameters of $G$ (if any) and let $B_i$ be the b
ound of $T_i, i \in 1.. n$, and $S_i$ is not a subtype of $[S_1, \ldots, S_n/T
_1, \ldots, T_n]B_i, i \in 1.. n$. | 5410 % \item Let $T_i$ be the type parameters of $G$ (if any) and let $B_i$ be the b
ound of $T_i, i \in 1.. n$, and $S_i$ is not a subtype of $[S_1, \ldots, S_n/T
_1, \ldots, T_n]B_i, i \in 1.. n$. |
5332 % \end{itemize} | 5411 % \end{itemize} |
5333 \end{itemize} | 5412 \end{itemize} |
5334 | 5413 |
5335 Any use of a malformed type gives rise to a static warning. A malformed type i
s then interpreted as \DYNAMIC{} by the static type checker and the runtime unle
ss explicitly specified otherwise. | 5414 Any use of a malformed type gives rise to a static warning. A malformed type i
s then interpreted as \DYNAMIC{} by the static type checker and the runtime unle
ss explicitly specified otherwise. |
5336 | 5415 |
5337 \rationale{ | 5416 \rationale{ |
5338 This ensures that the developer is spared a series of cascading warnings as the
malformed type interacts with other types. | 5417 This ensures that the developer is spared a series of cascading warnings as the
malformed type interacts with other types. |
5339 } | 5418 } |
5340 | 5419 |
| 5420 A type $T$ is deferred iff it is of the form $p.T$ where $p$ is a deferred prefi
x. |
| 5421 It is a static warning to use a deferred type in a type annotation, type test, t
ype cast or as a type parameter. However, all other static warnings must be issu
ed under the assumption that all deferred libraries have successfully been loade
d. |
| 5422 |
5341 | 5423 |
5342 \subsubsection{Type Promotion} | 5424 \subsubsection{Type Promotion} |
5343 \label{typePromotion} | 5425 \label{typePromotion} |
5344 | 5426 |
5345 The static type system ascribes a static type to every expression. In some case
s, the types of local variables and formal parameters may be promoted from their
declared types based on control flow. | 5427 The static type system ascribes a static type to every expression. In some case
s, the types of local variables and formal parameters may be promoted from their
declared types based on control flow. |
5346 | 5428 |
5347 We say that a variable $v$ is known to have type $T$ whenever we allow the type
of $v$ to be promoted. The exact circumstances when type promotion is allowed ar
e given in the relevant sections of the specification (\ref{logicalBooleanExpres
sions}, \ref{conditional} and \ref{if}). | 5429 We say that a variable $v$ is known to have type $T$ whenever we allow the type
of $v$ to be promoted. The exact circumstances when type promotion is allowed ar
e given in the relevant sections of the specification (\ref{logicalBooleanExpres
sions}, \ref{conditional} and \ref{if}). |
5348 | 5430 |
5349 Type promotion for a variable $v$ is allowed only when we can deduce that such p
romotion is valid based on an analysis of certain boolean expressions. In such c
ases, we say that the boolean expression $b$ shows that $v$ has type $T$. As a r
ule, for all variables $v$ and types $T$, a boolean expression does not show tha
t $v$ has type $T$. Those situations where an expression does show that a variab
le has a type are mentioned explicitly in the relevant sections of this specific
ation (\ref{typeTest} and \ref{logicalBooleanExpressions}). | 5431 Type promotion for a variable $v$ is allowed only when we can deduce that such p
romotion is valid based on an analysis of certain boolean expressions. In such c
ases, we say that the boolean expression $b$ shows that $v$ has type $T$. As a r
ule, for all variables $v$ and types $T$, a boolean expression does not show tha
t $v$ has type $T$. Those situations where an expression does show that a variab
le has a type are mentioned explicitly in the relevant sections of this specific
ation (\ref{typeTest} and \ref{logicalBooleanExpressions}). |
5350 | 5432 |
5351 | 5433 |
5352 \subsection{Dynamic Type System} | 5434 \subsection{Dynamic Type System} |
5353 \label{dynamicTypeSystem} | 5435 \label{dynamicTypeSystem} |
5354 | 5436 |
5355 A Dart implementation must support execution in both {\em production mode} and {
\em checked mode}. Those dynamic checks specified as occurring specifically in
checked mode must be performed iff the code is executed in checked mode. | 5437 A Dart implementation must support execution in both {\em production mode} and {
\em checked mode}. Those dynamic checks specified as occurring specifically in
checked mode must be performed iff the code is executed in checked mode. |
5356 | 5438 |
| 5439 \commentary{ |
| 5440 Note that this is the case even if the deferred type belongs to a prefix that ha
s already been loaded. This is regrettable, since it strongly discourages the us
e of type annotations that involve deferred types because Dart programmers use c
hecked mode much of the time. |
| 5441 |
| 5442 In practice, many scenarios involving deferred loading involve deferred loading
of classes that implement eagerly loaded interfaces, so the situation is often l
ess onerous than it seems. The current semantics were adopted based on considera
tions of ease of implementation. |
| 5443 |
| 5444 Clearly, if a deferred type has not yet been loaded, it is impossible to do a co
rrect subtype test involving it, and one would expect a dynamic failure, as is t
he case with type tests and casts. By the same token, one would expect checked m
ode to work seamlessly once a type had been loaded. We hope to adopt these seman
tics in the future; such a change would be upwardly compatible. |
| 5445 |
| 5446 } |
| 5447 |
5357 %It is a run-time type error to access an undeclared type outside . | 5448 %It is a run-time type error to access an undeclared type outside . |
5358 | 5449 |
5359 %It is a dynamic type error if a malformed type is used in a subtype test. | 5450 %It is a dynamic type error if a malformed type is used in a subtype test. |
5360 In checked mode, it is a dynamic type error if a malformed or malbounded (\ref{p
arameterizedTypes}) | 5451 In checked mode, it is a dynamic type error if a deferred, malformed or malbound
ed (\ref{parameterizedTypes}) |
5361 type is used in a subtype test. | 5452 type is used in a subtype test. |
5362 | 5453 |
5363 %In production mode, an undeclared type is treated as an instance of type \DYNAM
IC{}. | 5454 %In production mode, an undeclared type is treated as an instance of type \DYNAM
IC{}. |
5364 | 5455 |
5365 \commentary{Consider the following program} | 5456 \commentary{Consider the following program} |
5366 | 5457 |
5367 \begin{dartCode} | 5458 \begin{dartCode} |
5368 \TYPEDEF{} F(bool x); | 5459 \TYPEDEF{} F(bool x); |
5369 f(foo x) $=>$ x; | 5460 f(foo x) $=>$ x; |
5370 main() \{ | 5461 main() \{ |
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5936 \item The names of compile time constant variables never use lower case letters.
If they consist of multiple words, those words are separated by underscores. Ex
amples: PI, I\_AM\_A\_CONSTANT. | 6027 \item The names of compile time constant variables never use lower case letters.
If they consist of multiple words, those words are separated by underscores. Ex
amples: PI, I\_AM\_A\_CONSTANT. |
5937 \item The names of functions (including getters, setters, methods and local or l
ibrary functions) and non-constant variables begin with a lowercase letter. If t
he name consists of multiple words, each word (except the first) begins with an
uppercase letter. No other uppercase letters are used. Examples: camlCase, dar
t4TheWorld | 6028 \item The names of functions (including getters, setters, methods and local or l
ibrary functions) and non-constant variables begin with a lowercase letter. If t
he name consists of multiple words, each word (except the first) begins with an
uppercase letter. No other uppercase letters are used. Examples: camlCase, dar
t4TheWorld |
5938 \item The names of types (including classes and type aliases) begin with an uppe
r case letter. If the name consists of multiple words, each word begins with
an uppercase letter. No other uppercase letters are used. Examples: CamlCase, D
art4TheWorld. | 6029 \item The names of types (including classes and type aliases) begin with an uppe
r case letter. If the name consists of multiple words, each word begins with
an uppercase letter. No other uppercase letters are used. Examples: CamlCase, D
art4TheWorld. |
5939 \item The names of type variables are short (preferably single letter). Examples
: T, S, K, V , E. | 6030 \item The names of type variables are short (preferably single letter). Examples
: T, S, K, V , E. |
5940 \item The names of libraries or library prefixes never use upper case letters. I
f they consist of multiple words, those words are separated by underscores. Exam
ple: my\_favorite\_library. | 6031 \item The names of libraries or library prefixes never use upper case letters. I
f they consist of multiple words, those words are separated by underscores. Exam
ple: my\_favorite\_library. |
5941 \end{itemize} | 6032 \end{itemize} |
5942 } | 6033 } |
5943 | 6034 |
5944 | 6035 |
5945 \end{document} | 6036 \end{document} |
OLD | NEW |