Skip to content

Commit 7478c2b

Browse files
committed
Add Duplicate Variant error
1 parent 4514e88 commit 7478c2b

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

spec/errors.md

+21
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,27 @@ appears on the left-hand side of more than one _option_ in the same _expression_
178178
> {{This is {$foo}}}
179179
> ```
180180
181+
### Duplicate Variant
182+
183+
A **_<dfn>Duplicate Variant</dfn>_** error occurs when the same _keys_
184+
are used for more than one _variant_.
185+
186+
> Examples of invalid messages resulting in a _Duplicate Variant_ error:
187+
>
188+
> ```
189+
> .match {$var :string}
190+
> * {{The first default}}
191+
> * {{The second default}}
192+
> ```
193+
>
194+
> ```
195+
> .match {$x :string} {$y :string}
196+
> * foo {{The first "foo" variant}}
197+
> bar * {{The "bar" variant}}
198+
> * |foo| {{The second "foo" variant}}
199+
> * * {{The default variant}}
200+
> ```
201+
181202
## Resolution Errors
182203
183204
**_<dfn>Resolution Errors</dfn>_** occur when the runtime value of a part of a message

spec/syntax.md

+2
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,8 @@ satisfied:
369369
- At least one _variant_ MUST exist whose _keys_ are all equal to the "catch-all" key `*`.
370370
- Each _selector_ MUST have an _annotation_,
371371
or contain a _variable_ that directly or indirectly references a _declaration_ with an _annotation_.
372+
- Every _variant_ MUST NOT use the same set of _keys_ in the same order as another _variant_.
373+
_Literal_ _keys_ are compared by their contents, not their syntactical appearance.
372374

373375
```abnf
374376
matcher = match-statement 1*([s] variant)

test/schemas/v0/tests.schema.json

+1
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@
342342
"missing-selector-annotation",
343343
"duplicate-declaration",
344344
"duplicate-option-name",
345+
"duplicate-variant",
345346
"unresolved-variable",
346347
"unknown-function",
347348
"unsupported-expression",

test/tests/data-model-errors.json

+16
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,22 @@
164164
"type": "duplicate-option-name"
165165
}
166166
]
167+
},
168+
{
169+
"src": ".match {$var :string} * {{The first default}} * {{The second default}}",
170+
"expErrors": [
171+
{
172+
"type": "duplicate-variant"
173+
}
174+
]
175+
},
176+
{
177+
"src": ".match {$x :string} {$y :string} * foo {{The first foo variant}} bar * {{The bar variant}} * |foo| {{The second foo variant}} * * {{The default variant}}",
178+
"expErrors": [
179+
{
180+
"type": "duplicate-variant"
181+
}
182+
]
167183
}
168184
]
169185
}

0 commit comments

Comments
 (0)