Skip to content

Commit 8c2aecb

Browse files
committed
Require variable names to be globally unique
See unicode-org#310
1 parent 4a1e367 commit 8c2aecb

File tree

1 file changed

+52
-4
lines changed

1 file changed

+52
-4
lines changed

spec/formatting.md

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,15 @@ The resolution of a _text_ or _literal_ token MUST always succeed.
123123
To resolve the value of a _variable_,
124124
its _name_ is used to identify either a local variable,
125125
or a variable defined elsewhere.
126-
If a local variable and an externally defined one use the same name,
127-
the local variable takes precedence.
128126
129-
It is an error for a local variable definition to
130-
refer to a local variable that's defined after it in the message.
127+
It is an error for the right-hand side of a local variable declaration to
128+
refer to a local variable that's declared after it in the message.
129+
130+
Variable names are required to be globally unique. That is,
131+
for any local variable declaration of the form `let $v = e`:
132+
* It is an error if `v` is the left-hand side of a local variable declaration
133+
that appears before `let $v = e` in the message.
134+
* It is also an error if `v` is an externally defined variable.
131135
132136
The resolution of a _variable_ MAY fail if no value is identified for its _name_.
133137
If this happens, an Unresolved Variable error MUST be emitted.
@@ -230,6 +234,24 @@ rather than the _expression_ in the _selector_ or _pattern_.
230234
231235
_Pattern selection_ is not supported for _fallback values_.
232236
237+
When there are multiple _declarations_ for the same _variable_,
238+
the fallback string is formatted based on the _expression_ of
239+
the first declaration of that _variable_.
240+
241+
> For example, attempting to format the following message:
242+
>
243+
> ```
244+
> let $var = {|cart|}
245+
> let $var = {|horse|}
246+
> {The value is {$var}.}
247+
> ```
248+
>
249+
> would result in this formatted string representation:
250+
>
251+
> ```
252+
> The value is {|cart|}.
253+
> ```
254+
233255
## Pattern Selection
234256
235257
When a _message_ contains a _match_ construct with one or more _expressions_,
@@ -704,6 +726,32 @@ These are divided into the following categories:
704726
> when * {The value is not one.}
705727
> ```
706728
729+
- **Variable Redefinition errors** occur when
730+
the left-hand side of a variable declaration is already defined,
731+
either by a previous local variable declaration,
732+
or by an external definition.
733+
734+
> For example, attempting to format the following message
735+
> must result in a Variable Redefinition error,
736+
> because there is another declaration for `var`
737+
> that textually precedes
738+
> the declaration of `var` to be `{|horse|}`.
739+
>
740+
> ```
741+
> let $var = {|cart|}
742+
> let $var = {|horse|}
743+
> {The value is {$var}.}
744+
> ```
745+
>
746+
> Attempting to format the following message in a context
747+
> where `var` is externally defined
748+
> should also result in a Variable Redefinition error.
749+
>
750+
> ```
751+
> let $var = {|horse|}
752+
> {The value is {$var}.}
753+
> ```
754+
707755
- **Unknown Function errors** occur when an _expression_ includes
708756
a reference to a function which cannot be resolved.
709757

0 commit comments

Comments
 (0)