gvariant-parser: Fix pattern coalesce of M and *

Previously pattern_coalesce incorrectly concluded that maybe type is not
present when one pattern starts with `M` and other pattern with anything
else than `M` or `m`. This is false when the other pattern is `*`, since
it includes the maybe type.
This commit is contained in:
Tomasz Miąsko
2019-02-26 00:00:00 +00:00
parent 5c97cf666d
commit 153f63d13e
2 changed files with 19 additions and 18 deletions

View File

@@ -418,6 +418,8 @@ pattern_copy (gchar **out,
while (brackets);
}
/* Returns the most general pattern that is subpattern of left and subpattern
* of right, or NULL if there is no such pattern. */
static gchar *
pattern_coalesce (const gchar *left,
const gchar *right)
@@ -458,7 +460,7 @@ pattern_coalesce (const gchar *left,
*out++ = *(*the_other)++;
}
else if (**one == 'M' && **the_other != 'm')
else if (**one == 'M' && **the_other != 'm' && **the_other != '*')
{
(*one)++;
}
@@ -672,18 +674,7 @@ ast_array_get_pattern (AST **array,
gint i;
/* Find the pattern which applies to all children in the array, by l-folding a
* coalesce operation. This will not always work: for example, the GVariant:
* [[0], [], [nothing]]
* has patterns:
* MaMN, Ma*, Mam*
* which pairwise coalesce as:
* MaMN + Ma* = MaN
* MaN + Mam* = (doesnt coalesce)
*
* However, the pattern MamN coalesces with all three child patterns. Finding
* this pattern would require trying all O(n_items^2) pairs, though, which is
* expensive. Just let it fail, and require the user to provide type
* annotations.
* coalesce operation.
*/
pattern = ast_get_pattern (array[0], error);
@@ -719,10 +710,10 @@ ast_array_get_pattern (AST **array,
gchar *tmp2;
gchar *m;
/* if 'j' reaches 'i' then we failed to find the pair, which can
* happen due to only trying pairwise coalesces in order rather
* than between all pairs (see above). so just report an error
* for i. */
/* if 'j' reaches 'i' then we didn't find the pair that failed
* to coalesce. This shouldn't happen (see above), but just in
* case report an error:
*/
if (j >= i)
{
ast_set_error (array[i], error, NULL,