qapi script: add check for duplicated key
It is bad that same key was specified twice, especially when a union has two branches with same condition. This patch can prevent it. Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
This commit is contained in:
parent
dad1fcab91
commit
4b35991a3b
@ -116,6 +116,8 @@ class QAPISchema:
|
|||||||
if self.tok != ':':
|
if self.tok != ':':
|
||||||
raise QAPISchemaError(self, 'Expected ":"')
|
raise QAPISchemaError(self, 'Expected ":"')
|
||||||
self.accept()
|
self.accept()
|
||||||
|
if key in expr:
|
||||||
|
raise QAPISchemaError(self, 'Duplicate key "%s"' % key)
|
||||||
expr[key] = self.get_expr(True)
|
expr[key] = self.get_expr(True)
|
||||||
if self.tok == '}':
|
if self.tok == '}':
|
||||||
self.accept()
|
self.accept()
|
||||||
|
@ -142,7 +142,8 @@ check-qapi-schema-y := $(addprefix tests/qapi-schema/, \
|
|||||||
missing-comma-object.json non-objects.json \
|
missing-comma-object.json non-objects.json \
|
||||||
qapi-schema-test.json quoted-structural-chars.json \
|
qapi-schema-test.json quoted-structural-chars.json \
|
||||||
trailing-comma-list.json trailing-comma-object.json \
|
trailing-comma-list.json trailing-comma-object.json \
|
||||||
unclosed-list.json unclosed-object.json unclosed-string.json)
|
unclosed-list.json unclosed-object.json unclosed-string.json \
|
||||||
|
duplicate-key.json)
|
||||||
|
|
||||||
GENERATED_HEADERS += tests/test-qapi-types.h tests/test-qapi-visit.h tests/test-qmp-commands.h
|
GENERATED_HEADERS += tests/test-qapi-types.h tests/test-qapi-visit.h tests/test-qmp-commands.h
|
||||||
|
|
||||||
|
1
tests/qapi-schema/duplicate-key.err
Normal file
1
tests/qapi-schema/duplicate-key.err
Normal file
@ -0,0 +1 @@
|
|||||||
|
<stdin>:2:10: Duplicate key "key"
|
1
tests/qapi-schema/duplicate-key.exit
Normal file
1
tests/qapi-schema/duplicate-key.exit
Normal file
@ -0,0 +1 @@
|
|||||||
|
1
|
2
tests/qapi-schema/duplicate-key.json
Normal file
2
tests/qapi-schema/duplicate-key.json
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
{ 'key': 'value',
|
||||||
|
'key': 'value' }
|
0
tests/qapi-schema/duplicate-key.out
Normal file
0
tests/qapi-schema/duplicate-key.out
Normal file
Loading…
x
Reference in New Issue
Block a user