Skip to content

Commit f80aceb

Browse files
authored
Adjust the constant expression rules for lists, maps, and conditional expressions (#4313)
Adjust the constant expression rules for lists, sets, maps, constant object expressions, and conditional expressions. For the latter, it is specified that a conditional expression which is not potentially constant is also not constant. For the others, the rules in section 'Constants' are simplified (it's redundant with the same rule as stated in other sections). There is no breaking change and no implementation effort, because the newly specified behavior is the already implemented behavior (for the analyzer as well as the CFE).
1 parent 5dd44e1 commit f80aceb

File tree

1 file changed

+15
-37
lines changed

1 file changed

+15
-37
lines changed

specification/dartLangSpec.tex

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
% version of the language which will actually be specified by the next stable
4242
% release of this document.
4343
%
44+
% Apr 2025
45+
% - Change the rules about constants to be more consistent: Every constant
46+
% expression is also a potentially constant expression. Also, eliminate
47+
% redundancies in the rules about constant collection literals and constant
48+
% object expressions (they are now defined just once, outside 'Constants').
49+
%
4450
% Sep 2024
4551
% - Clarify the extension applicability rule to explicitly state that it
4652
% is concerned with an instance member with the same basename, not a
@@ -8653,48 +8659,20 @@ \subsection{Constants}
86538659
is a potentially constant expression.
86548660

86558661
\item
8656-
A constant object expression (\ref{const}),
8657-
\code{\CONST{} $C$<$T_1,\ \ldots,\ T_k$>(\metavar{arguments})} or
8658-
\code{\CONST{} $C$<$T_1,\ \ldots,\ T_k$>.\id(\metavar{arguments})},
8659-
or either expression without the leading \CONST{} that occurs in
8660-
a constant context,
8661-
is a potentially constant expression.
8662-
It is further a constant expression if the invocation evaluates to an object.
8663-
% \ref{const} requires each actual argument to be a constant expression,
8664-
% but here we also catch errors during evaluation, e.g., `C(1, 0)` where
8665-
% `C(double x, double y): z = x / y;`.
8666-
It is a compile-time error if a constant object expression is
8667-
not a constant expression (\ref{const}).
8662+
A constant object expression (\ref{const})
8663+
is a potentially constant and constant expression.
86688664

86698665
\item
8670-
A constant list literal (\ref{lists}),
8671-
\code{\CONST{} <$T$>[$e_1$, \ldots, $e_n$]}, or
8672-
\code{<$T$>[$e_1$, \ldots, $e_n$]}
8673-
that occurs in a constant context,
8674-
is a potentially constant expression if $T$ is a constant type expression,
8675-
and $e_1$, \ldots{} , $e_n$ are constant expressions.
8676-
It is further a constant expression
8677-
if the list literal evaluates to an object.
8666+
A constant list literal (\ref{lists})
8667+
is a potentially constant and constant expression.
86788668

86798669
\item
8680-
A constant set literal (\ref{sets}),
8681-
\code{\CONST{} <$T$>\{$e_1$, \ldots, $e_n$\}}, or
8682-
\code{<$T$>\{$e_1$, \ldots, $e_n$\}}
8683-
that occurs in a constant context,
8684-
is a potentially constant expression
8685-
if $T$ is a constant type expression,
8686-
and $e_1$, \ldots{} , $e_n$ are constant expressions.
8687-
It is further a constant expression
8688-
if the set literal evaluates to an object.
8670+
A constant set literal (\ref{sets})
8671+
is a potentially constant and constant expression.
86898672

86908673
\item
8691-
A constant map literal (\ref{maps}),
8692-
\code{\CONST{} <$K$, $V$>\{$k_1$: $v_1$, \ldots, $k_n$: $v_n$\}}, or
8693-
\code{<$K$, $V$>\{$k_1$: $v_1$, \ldots, $k_n$: $v_n$\}}
8694-
that occurs in a constant context,
8695-
is a potentially constant expression.
8696-
It is further a constant expression
8697-
if the map literal evaluates to an object.
8674+
A constant map literal (\ref{maps})
8675+
is a potentially constant and constant expression.
86988676

86998677
\item
87008678
A parenthesized expression \code{($e$)} is
@@ -8813,7 +8791,7 @@ \subsection{Constants}
88138791
\item An expression of the form \code{$e_1$\,?\,$e_2$\,:\,$e_3$}
88148792
is potentially constant if $e_1$, $e_2$, and $e_3$
88158793
are all potentially constant expressions.
8816-
It is constant if $e_1$ is a constant expression and either
8794+
It is further constant if $e_1$ is a constant expression and either
88178795
\begin{enumerate}
88188796
\item $e_1$ evaluates to \TRUE{} and $e_2$ is a constant expression, or
88198797
\item $e_1$ evaluates to \FALSE{} and $e_3$ is a constant expression.

0 commit comments

Comments
 (0)