diff --git a/spec/formatting.md b/spec/formatting.md index 6d956bdc1e..16072adedd 100644 --- a/spec/formatting.md +++ b/spec/formatting.md @@ -123,11 +123,32 @@ The resolution of a _text_ or _literal_ token MUST always succeed. To resolve the value of a _variable_, its _name_ is used to identify either a local variable, or a variable defined elsewhere. -If a local variable and an externally defined one use the same name, -the local variable takes precedence. -It is an error for a local variable definition to -refer to a local variable that's defined after it in the message. +When a _variable_is used as an _operand_, +the _name_ of this variable MUST either be: +1. The _name_ of a _variable_ of a _declaration_ that occurs before the +_operand_, or: +1. An externally defined variable. + +In case 1, the `entire` _declaration_ MUST appear before the _operand_. +For example, resolution of the following declaration should fail: + +``` +let $var = {$var} +``` + +because although a _variable_ with _name_ `var` occurs before +the expression `{$var}`, the entire declaration `let $var = {$var}` +does not occur before the expression `{$var}`. + +Any _name_ MUST NOT appear as the _name_ of the _variable_ +in more than one _declaration_ within the same message. +If the _variable_ in a _declaration_ also appears +as the _variable_ in a previous _declaration_, +a Variable Redefinition error MUST be emitted. +If the _variable_ in a declaration is also +an externally defined variable, +a Formatting error MUST be emitted. The resolution of a _variable_ MAY fail if no value is identified for its _name_. If this happens, an Unresolved Variable error MUST be emitted. @@ -230,6 +251,39 @@ rather than the _expression_ in the _selector_ or _pattern_. _Pattern selection_ is not supported for _fallback values_. +When there are multiple _declarations_ for the same _variable_, +or when a _declaration_ redefines a _variable_ +that is externally defined, +the fallback string is formatted based on the _expression_ of +the first local declaration of that _variable_. + +> For example, attempting to format the following message: +> +> ``` +> let $var = {|cart|} +> let $var = {|horse|} +> {The value is {$var}.} +> ``` +> +> would result in this formatted string representation: +> +> ``` +> The value is {|cart|}. +> ``` +> +> Also, attempting to format the following message: +> ``` +> let $var = {|cart|} +> {The value is {$var}.} +> ``` +> +> in a context where `var` is externally defined +> would result in the same formatted string representation: +> +> ``` +> The value is {|cart|}. +> ``` + ## Pattern Selection When a _message_ contains a _match_ construct with one or more _expressions_, @@ -704,6 +758,32 @@ These are divided into the following categories: > when * {The value is not one.} > ``` + - **Variable Redefinition errors** occur when +a `declaration` contains a `variable` that is already defined + either by a previous local variable declaration, + or by an external definition. + + > For example, attempting to format the following message + > results in a Variable Redefinition error, + > because there is another declaration for `var` + > that textually precedes + > the declaration of `var` to be `{|horse|}`. + > + > ``` + > let $var = {|cart|} + > let $var = {|horse|} + > {The value is {$var}.} + > ``` + > + > Attempting to format the following message in a context + > where `var` is externally defined + > also results in a Variable Redefinition error. + > + > ``` + > let $var = {|horse|} + > {The value is {$var}.} + > ``` + - **Unknown Function errors** occur when an _expression_ includes a reference to a function which cannot be resolved.