Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5612f3b

Browse files
eemeliaphillips
andauthored
Add Duplicate Variant error (#853)
* Add Duplicate Variant error * Apply suggestions from code review Co-authored-by: Addison Phillips <[email protected]> * List, not set, of keys --------- Co-authored-by: Addison Phillips <[email protected]>
1 parent 20653d7 commit 5612f3b

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

spec/errors.md

Lines changed: 21 additions & 0 deletions
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
184+
same list of _keys_ is 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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,9 @@ satisfied:
375375
- At least one _variant_ MUST exist whose _keys_ are all equal to the "catch-all" key `*`.
376376
- Each _selector_ MUST have an _annotation_,
377377
or contain a _variable_ that directly or indirectly references a _declaration_ with an _annotation_.
378+
- Each _variant_ MUST use a list of _keys_ that is unique from that
379+
of all other _variants_ in the _message_.
380+
_Literal_ _keys_ are compared by their contents, not their syntactical appearance.
378381

379382
```abnf
380383
matcher = match-statement 1*([s] variant)
@@ -440,7 +443,7 @@ There MAY be any number of additional _selectors_.
440443
441444
### Variant
442445
443-
A **_<dfn>variant</dfn>_** is a _quoted pattern_ associated with a set of _keys_ in a _matcher_.
446+
A **_<dfn>variant</dfn>_** is a _quoted pattern_ associated with a list of _keys_ in a _matcher_.
444447
Each _variant_ MUST begin with a sequence of _keys_,
445448
and terminate with a valid _quoted pattern_.
446449
The number of _keys_ in each _variant_ MUST match the number of _selectors_ in the _matcher_.

test/schemas/v0/tests.schema.json

Lines changed: 1 addition & 0 deletions
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

Lines changed: 16 additions & 0 deletions
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)