dart-sdk/docs
Lasse R.H. Nielsen 0808d29b4e Update spec of potentially constant and compile-time constant expressions.
The existing specification was underspecifying potentially constant expressions,
effectively relying on evaluation to determine whether an expression was
potentially constant.

This change specifies potentially constant recursively using only the syntax
of the expressions.

Adds short-circuting to `?:`, `??`, `||` and `&&` expressions,
so for `String x`, the expression `x != null && x.length > 0`
is compile-time constant.
The original specification requred evaluation of the latter half
even when `x` is null. We can now avoid this because we can require that the
unused expression is a potentially constant expression without having to
check if it, or any part of it, is a compile-time constant expression.

Allows `x == null` and `x != null` as compile-time constant expression
independently of the type of `x`.

Allows `e as T` as a compile-time constant expression. Types are more
important in Dart 2, so you need a way to adjust typing in some cases,
even in compile-time constant expressions.

Change-Id: I02bf0b77013c3b3ced8cd46334db378787cc2d57
Reviewed-on: https://dart-review.googlesource.com/36220
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
2018-09-26 14:17:39 +00:00
..
language Update spec of potentially constant and compile-time constant expressions. 2018-09-26 14:17:39 +00:00
newsletter Newsletter 2017-11-24. 2017-11-24 16:27:00 +00:00