mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-10-25 14:32:16 +02:00
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:
@@ -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* = (doesn’t 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,
|
||||
|
||||
Reference in New Issue
Block a user