inConstantContext property

bool inConstantContext

Whether this expression is in a constant context.

An expression e is said to occur in a constant context,

  • if e is an element of a constant list literal, or a key or value of an entry of a constant map literal.
  • if e is an actual argument of a constant object expression or of a metadata annotation.
  • if e is the initializing expression of a constant variable declaration.
  • if e is a switch case expression.
  • if e is an immediate subexpression of an expression e1 which occurs in a constant context, unless e1 is a throw expression or a function literal.

This roughly means that everything which is inside a syntactically constant expression is in a constant context. A throw expression is currently not allowed in a constant expression, but extensions affecting that status might be considered. A similar situation arises for function literals.

Note that the default value of an optional formal parameter is not a constant context. This choice reserves some freedom to modify the semantics of default values.


bool get inConstantContext;