qapi: Improve reporting of redefinition
authorMarkus Armbruster <armbru@redhat.com>
Fri, 27 Sep 2019 13:46:38 +0000 (15:46 +0200)
committerMarkus Armbruster <armbru@redhat.com>
Sat, 28 Sep 2019 15:17:48 +0000 (17:17 +0200)
Point to the previous definition, unless it's a built-in.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20190927134639.4284-26-armbru@redhat.com>

scripts/qapi/common.py
tests/qapi-schema/redefined-command.err
tests/qapi-schema/redefined-event.err
tests/qapi-schema/redefined-type.err

index bd834270f8841bef0cbbaf9cc5c059eb5f46fdae..a74cd957d4723cb27d071ab98c7639f702835543 100644 (file)
@@ -1759,6 +1759,11 @@ class QAPISchema(object):
         # because they're liable to clash in generated C.
         other_ent = self._entity_dict.get(ent.name)
         if other_ent:
+            if other_ent.info:
+                where = QAPIError(other_ent.info, None, "previous definition")
+                raise QAPISemError(
+                    ent.info,
+                    "'%s' is already defined\n%s" % (ent.name, where))
             raise QAPISemError(
                 ent.info, "%s is already defined" % other_ent.describe())
         self._entity_dict[ent.name] = ent
index b77a05d354fe2b08275fb951fc2a1d00bca8ec28..54e366bbf3557c974106252661c462998fab7da5 100644 (file)
@@ -1,2 +1,4 @@
 tests/qapi-schema/redefined-command.json: In command 'foo':
-tests/qapi-schema/redefined-command.json:3: command 'foo' is already defined
+tests/qapi-schema/redefined-command.json:3: 'foo' is already defined
+tests/qapi-schema/redefined-command.json: In command 'foo':
+tests/qapi-schema/redefined-command.json:2: previous definition
index fd02d38157706b142548651f8c85ca4eb6235e10..606c6e4497bd5127c763bcd07bcd39a65dc48436 100644 (file)
@@ -1,2 +1,4 @@
 tests/qapi-schema/redefined-event.json: In event 'EVENT_A':
-tests/qapi-schema/redefined-event.json:3: event 'EVENT_A' is already defined
+tests/qapi-schema/redefined-event.json:3: 'EVENT_A' is already defined
+tests/qapi-schema/redefined-event.json: In event 'EVENT_A':
+tests/qapi-schema/redefined-event.json:2: previous definition
index 39f51c14ea2bb18c22c4a2c8c9a61d60a168a84d..77786f98ae8ca4fba6377eb61691296cfe3fe52f 100644 (file)
@@ -1,2 +1,4 @@
 tests/qapi-schema/redefined-type.json: In enum 'foo':
-tests/qapi-schema/redefined-type.json:3: struct type 'foo' is already defined
+tests/qapi-schema/redefined-type.json:3: 'foo' is already defined
+tests/qapi-schema/redefined-type.json: In struct 'foo':
+tests/qapi-schema/redefined-type.json:2: previous definition