Clarify ambiguous definition of constant interpolated string expressions.

The previous phrasing ("A constant expression is ... a literal string
where any interpolated expression is a compile-time constant ...") was
ambiguous: did it mean "... where at least one interpolated expression
is a compile-time constant ..." or did it mean "... where every
interpolated expression (if there are any) is a compile-time constant
..."?

Clearly the intended meaning is that all interpolated expressions are
required to be compile-time constants, otherwise we would allow
nonsense like this:

  void f(int i) {
    const x = 0;
    const s = "$x $i"; // Ok because x is const (!)
  }

Changing the word to "every" avoids the ambiguity.

Change-Id: I3a1dd38a8bc0dc9cddc7b504ea8e7de5afdf8990
Reviewed-on: https://dart-review.googlesource.com/74321
Reviewed-by: Leaf Petersen <leafp@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
This commit is contained in:
Paul Berry 2018-09-10 22:56:10 +00:00 committed by commit-bot@chromium.org
parent 24493c2f54
commit e2fdd57664

View file

@ -3679,7 +3679,7 @@ A constant expression is one of the following:
\begin{itemize}
\item A literal number (\ref{numbers}).
\item A literal boolean (\ref{booleans}).
\item A literal string (\ref{strings}) where any interpolated expression (\ref{stringInterpolation}) is a compile-time constant that evaluates to a numeric, string or boolean value or to the null object (\ref{null}).
\item A literal string (\ref{strings}) where every interpolated expression (\ref{stringInterpolation}) is a compile-time constant that evaluates to a numeric, string or boolean value or to the null object (\ref{null}).
\rationale{
It would be tempting to allow string interpolation where the interpolated value is any compile-time constant.
However, this would require running the \code{toString()} method for constant objects, which could contain arbitrary code.