Skip to content

Commit 77f2e6c

Browse files
committed
Require variable names to be globally unique
See unicode-org#310
1 parent e56a408 commit 77f2e6c

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
@@ -23,11 +23,15 @@ are treated as identical.
2323
To resolve the value of a _variable_,
2424
its _name_ is used to identify either a local variable,
2525
or a variable defined elsewhere.
26-
If a local variable and an externally defined one use the same name,
27-
the local variable takes precedence.
2826

29-
It is an error for a local variable definition to
30-
refer to a local variable that's defined after it in the message.
27+
It is an error for the right-hand side of a local variable declaration to
28+
refer to a local variable that's declared after it in the message.
29+
30+
Variable names are required to be globally unique. That is,
31+
for any local variable declaration of the form `let $v = e`:
32+
* It is an error if `v` is the left-hand side of a local variable declaration
33+
that appears before `let $v = e` in the message.
34+
* It is also an error if `v` is an externally defined variable.
3135

3236
## Pattern Selection
3337

@@ -428,6 +432,32 @@ These are divided into the following categories:
428432
> when * {The value is not one.}
429433
> ```
430434
435+
- **Variable Redefinition errors** occur when
436+
the left-hand side of a variable declaration is already defined,
437+
either by a previous local variable declaration,
438+
or by an external definition.
439+
440+
> For example, attempting to format the following message
441+
> must result in a Variable Redefinition error,
442+
> because there is another declaration for `var`
443+
> that textually precedes
444+
> the declaration of `var` to be `{|horse|}`.
445+
>
446+
> ```
447+
> let $var = {|cart|}
448+
> let $var = {|horse|}
449+
> {The value is {$var}.}
450+
> ```
451+
>
452+
> Attempting to format the following message in a context
453+
> where `var` is externally defined
454+
> should also result in a Variable Redefinition error.
455+
>
456+
> ```
457+
> let $var = {|horse|}
458+
> {The value is {$var}.}
459+
> ```
460+
431461
- **Unknown Function errors** occur when an _expression_ includes
432462
a reference to a function which cannot be resolved.
433463
@@ -590,3 +620,21 @@ rather than the _expression_ in the _selector_ or _pattern_.
590620
> ```
591621
> The value is {|horse|}.
592622
> ```
623+
624+
When there are multiple _declarations_ for the same _variable_,
625+
the fallback string is formatted based on the _expression_ of
626+
the first declaration of that _variable_.
627+
628+
> For example, attempting to format the following message:
629+
>
630+
> ```
631+
> let $var = {|cart|}
632+
> let $var = {|horse|}
633+
> {The value is {$var}.}
634+
> ```
635+
>
636+
> would result in this formatted string representation:
637+
>
638+
> ```
639+
> The value is {|cart|}.
640+
> ```

0 commit comments

Comments
 (0)