diff --git a/tests/qapi-schema/flat-union-allow-flat.err b/tests/qapi-schema/flat-union-allow-flat.err
new file mode 100644
index 0000000000..f3f3d2384b
--- /dev/null
+++ b/tests/qapi-schema/flat-union-allow-flat.err
@@ -0,0 +1,2 @@
+flat-union-allow-flat.json: In union 'MyUnion':
+flat-union-allow-flat.json:6: 'allow-flat' requires simple union
diff --git a/tests/qapi-schema/flat-union-allow-flat.json b/tests/qapi-schema/flat-union-allow-flat.json
new file mode 100644
index 0000000000..114acaad86
--- /dev/null
+++ b/tests/qapi-schema/flat-union-allow-flat.json
@@ -0,0 +1,10 @@
+# Flat unions must not use allow-flat
+{ 'enum': 'Enum', 'data': [ 'one', 'two' ] }
+{ 'struct': 'Base',
+  'data': { 'switch': 'Enum' } }
+{ 'struct': 'Branch', 'data': { 'name': 'str' } }
+{ 'union': 'MyUnion',
+  'base': 'Base',
+  'discriminator': 'switch',
+  'data': { 'one': { 'type': 'Branch', 'allow-flat': true },
+            'two': 'Branch' } }
diff --git a/tests/qapi-schema/flat-union-allow-flat.out b/tests/qapi-schema/flat-union-allow-flat.out
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/tests/qapi-schema/meson.build b/tests/qapi-schema/meson.build
index 304ef939bd..a5138d0c0f 100644
--- a/tests/qapi-schema/meson.build
+++ b/tests/qapi-schema/meson.build
@@ -103,6 +103,7 @@ schemas = [
   'features-name-bad-type.json',
   'features-no-list.json',
   'features-unknown-key.json',
+  'flat-union-allow-flat.json',
   'flat-union-array-branch.json',
   'flat-union-bad-base.json',
   'flat-union-bad-discriminator.json',
@@ -184,12 +185,16 @@ schemas = [
   'unclosed-list.json',
   'unclosed-object.json',
   'unclosed-string.json',
+  'union-allow-flat-bad.json',
+  'union-allow-flat-builtin-type.json',
   'union-base-empty.json',
   'union-base-no-discriminator.json',
   'union-branch-case.json',
   'union-branch-if-invalid.json',
   'union-branch-invalid-dict.json',
   'union-clash-branches.json',
+  'union-clash-member-data.json',
+  'union-clash-member-type.json',
   'union-empty.json',
   'union-invalid-base.json',
   'union-optional-branch.json',
diff --git a/tests/qapi-schema/qapi-schema-test.json b/tests/qapi-schema/qapi-schema-test.json
index 63f92adf68..1c29576ae9 100644
--- a/tests/qapi-schema/qapi-schema-test.json
+++ b/tests/qapi-schema/qapi-schema-test.json
@@ -110,6 +110,16 @@
 { 'struct': 'UserDefC',
   'data': { 'string1': 'str', 'string2': 'str' } }
 
+{ 'struct': 'UserDefD',
+  'data': { 'type': 'str' } }
+
+{ 'union': 'UserDefSimpleUnion',
+  'data': { 'value1' : {'type': 'UserDefA'},
+            'value2' : 'UserDefB',
+            'value3' : 'UserDefB',
+            'value4' : { 'type': 'UserDefD', 'allow-flat': false }
+  } }
+
 # for testing use of 'number' within alternates
 { 'alternate': 'AltEnumBool', 'data': { 'e': 'EnumOne', 'b': 'bool' } }
 { 'alternate': 'AltEnumNum', 'data': { 'e': 'EnumOne', 'n': 'number' } }
diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qapi-schema-test.out
index a4e4051c61..7521e86e9f 100644
--- a/tests/qapi-schema/qapi-schema-test.out
+++ b/tests/qapi-schema/qapi-schema-test.out
@@ -105,6 +105,20 @@ alternate UserDefAlternate
 object UserDefC
     member string1: str optional=False
     member string2: str optional=False
+object UserDefD
+    member type: str optional=False
+enum UserDefSimpleUnionKind
+    member value1
+    member value2
+    member value3
+    member value4
+object UserDefSimpleUnion
+    member type: UserDefSimpleUnionKind optional=False
+    tag type
+    case value1: UserDefA
+    case value2: UserDefB
+    case value3: UserDefB
+    case value4: UserDefD
 alternate AltEnumBool
     tag type
     case e: EnumOne
diff --git a/tests/qapi-schema/union-allow-flat-bad.err b/tests/qapi-schema/union-allow-flat-bad.err
new file mode 100644
index 0000000000..561fd338e1
--- /dev/null
+++ b/tests/qapi-schema/union-allow-flat-bad.err
@@ -0,0 +1,2 @@
+union-allow-flat-bad.json: In union 'MyUnion':
+union-allow-flat-bad.json:3: 'allow-flat' must be a boolean
diff --git a/tests/qapi-schema/union-allow-flat-bad.json b/tests/qapi-schema/union-allow-flat-bad.json
new file mode 100644
index 0000000000..6e02e8312b
--- /dev/null
+++ b/tests/qapi-schema/union-allow-flat-bad.json
@@ -0,0 +1,5 @@
+# allow-flat must be a boolean
+{ 'struct': 'Branch', 'data': { 'name': 'str' } }
+{ 'union': 'MyUnion',
+  'data': { 'one': { 'type': 'Branch', 'allow-flat': 'maybe' },
+            'two': 'Branch' } }
diff --git a/tests/qapi-schema/union-allow-flat-bad.out b/tests/qapi-schema/union-allow-flat-bad.out
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/tests/qapi-schema/union-allow-flat-builtin-type.err b/tests/qapi-schema/union-allow-flat-builtin-type.err
new file mode 100644
index 0000000000..4163d2426e
--- /dev/null
+++ b/tests/qapi-schema/union-allow-flat-builtin-type.err
@@ -0,0 +1,2 @@
+union-allow-flat-builtin-type.json: In union 'MyUnion':
+union-allow-flat-builtin-type.json:3: branch 'one' cannot use built-in type 'int'
diff --git a/tests/qapi-schema/union-allow-flat-builtin-type.json b/tests/qapi-schema/union-allow-flat-builtin-type.json
new file mode 100644
index 0000000000..21eb25c48a
--- /dev/null
+++ b/tests/qapi-schema/union-allow-flat-builtin-type.json
@@ -0,0 +1,5 @@
+# Can't use built-in types for branches with 'allow-flat': true
+{ 'struct': 'Branch', 'data': { 'name': 'str' } }
+{ 'union': 'MyUnion',
+  'data': { 'one': { 'type': 'int', 'allow-flat': true },
+            'two': 'Branch' } }
diff --git a/tests/qapi-schema/union-allow-flat-builtin-type.out b/tests/qapi-schema/union-allow-flat-builtin-type.out
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/tests/qapi-schema/union-clash-member-data.err b/tests/qapi-schema/union-clash-member-data.err
new file mode 100644
index 0000000000..316003e1b8
--- /dev/null
+++ b/tests/qapi-schema/union-clash-member-data.err
@@ -0,0 +1,2 @@
+union-clash-member-data.json: In union 'MyUnion':
+union-clash-member-data.json:4: member 'data' of type 'Branch' collides with flat representation of branch 'one'
diff --git a/tests/qapi-schema/union-clash-member-data.json b/tests/qapi-schema/union-clash-member-data.json
new file mode 100644
index 0000000000..b908d44372
--- /dev/null
+++ b/tests/qapi-schema/union-clash-member-data.json
@@ -0,0 +1,6 @@
+# For simple union branches, a 'data' member would prevent conversion
+# to flat representation, so we don't want to allow it
+{ 'struct': 'Branch', 'data': { 'data': 'str' } }
+{ 'union': 'MyUnion',
+  'data': { 'one': 'Branch',
+            'two': 'Branch' } }
diff --git a/tests/qapi-schema/union-clash-member-data.out b/tests/qapi-schema/union-clash-member-data.out
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/tests/qapi-schema/union-clash-member-type.err b/tests/qapi-schema/union-clash-member-type.err
new file mode 100644
index 0000000000..34e4b135ec
--- /dev/null
+++ b/tests/qapi-schema/union-clash-member-type.err
@@ -0,0 +1,2 @@
+union-clash-member-type.json: In union 'MyUnion':
+union-clash-member-type.json:4: member 'type' of type 'Branch' collides with member 'type'
diff --git a/tests/qapi-schema/union-clash-member-type.json b/tests/qapi-schema/union-clash-member-type.json
new file mode 100644
index 0000000000..cb09cd7d89
--- /dev/null
+++ b/tests/qapi-schema/union-clash-member-type.json
@@ -0,0 +1,6 @@
+# 'type' is in the implicit base type and clashes with a 'type' member
+# in branches if flat representation is not disabled
+{ 'struct': 'Branch', 'data': { 'type': 'str' } }
+{ 'union': 'MyUnion',
+  'data': { 'one': 'Branch',
+            'two': 'Branch' } }
