Skip to content

Commit

Permalink
Add Duplicate Variant error (#853)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
eemeli and aphillips authored Aug 12, 2024
1 parent 20653d7 commit 5612f3b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
21 changes: 21 additions & 0 deletions spec/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,27 @@ appears on the left-hand side of more than one _option_ in the same _expression_
> {{This is {$foo}}}
> ```
### Duplicate Variant
A **_<dfn>Duplicate Variant</dfn>_** error occurs when the
same list of _keys_ is used for more than one _variant_.
> Examples of invalid messages resulting in a _Duplicate Variant_ error:
>
> ```
> .match {$var :string}
> * {{The first default}}
> * {{The second default}}
> ```
>
> ```
> .match {$x :string} {$y :string}
> * foo {{The first "foo" variant}}
> bar * {{The "bar" variant}}
> * |foo| {{The second "foo" variant}}
> * * {{The default variant}}
> ```
## Resolution Errors
**_<dfn>Resolution Errors</dfn>_** occur when the runtime value of a part of a message
Expand Down
5 changes: 4 additions & 1 deletion spec/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,9 @@ satisfied:
- At least one _variant_ MUST exist whose _keys_ are all equal to the "catch-all" key `*`.
- Each _selector_ MUST have an _annotation_,
or contain a _variable_ that directly or indirectly references a _declaration_ with an _annotation_.
- Each _variant_ MUST use a list of _keys_ that is unique from that
of all other _variants_ in the _message_.
_Literal_ _keys_ are compared by their contents, not their syntactical appearance.

```abnf
matcher = match-statement 1*([s] variant)
Expand Down Expand Up @@ -440,7 +443,7 @@ There MAY be any number of additional _selectors_.
### Variant
A **_<dfn>variant</dfn>_** is a _quoted pattern_ associated with a set of _keys_ in a _matcher_.
A **_<dfn>variant</dfn>_** is a _quoted pattern_ associated with a list of _keys_ in a _matcher_.
Each _variant_ MUST begin with a sequence of _keys_,
and terminate with a valid _quoted pattern_.
The number of _keys_ in each _variant_ MUST match the number of _selectors_ in the _matcher_.
Expand Down
1 change: 1 addition & 0 deletions test/schemas/v0/tests.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@
"missing-selector-annotation",
"duplicate-declaration",
"duplicate-option-name",
"duplicate-variant",
"unresolved-variable",
"unknown-function",
"unsupported-expression",
Expand Down
16 changes: 16 additions & 0 deletions test/tests/data-model-errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,22 @@
"type": "duplicate-option-name"
}
]
},
{
"src": ".match {$var :string} * {{The first default}} * {{The second default}}",
"expErrors": [
{
"type": "duplicate-variant"
}
]
},
{
"src": ".match {$x :string} {$y :string} * foo {{The first foo variant}} bar * {{The bar variant}} * |foo| {{The second foo variant}} * * {{The default variant}}",
"expErrors": [
{
"type": "duplicate-variant"
}
]
}
]
}

0 comments on commit 5612f3b

Please sign in to comment.