Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Duplicate Variant error #853

Merged
merged 3 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}}
aphillips marked this conversation as resolved.
Show resolved Hide resolved
> * * {{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 @@ -369,6 +369,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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_Literal_ _keys_ are compared by their contents, not their syntactical appearance.
_Literal_ _keys_ are compared by their contents, not their syntactical appearance.
Keys are considered the same if they are canonically equivalent.
See [Canonical and Compatibility Equivalence](https://unicode.org/reports/tr15/#Canon_Compat_Equivalence)

Unicode conformance allows (and encourages) implementations to normalize canonically equivalent characters. This is a very common operation when text is input and/or processed. Without this step, there are cases where one implementation would return this error and another would not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Canonical equivalence looks like a pretty good idea, but we should apply it to all the places where we do such comparisons. But I think that's a separate change from this PR that I explicitly left out:

This does not address the questions about identifier normalization also raised in the parent issue; that should be done in a separate PR.


```abnf
matcher = match-statement 1*([s] variant)
Expand Down Expand Up @@ -434,7 +437,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"
}
]
}
]
}