[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] pkl: Disallow labels in unions
From: |
Mohammad-Reza Nabipoor |
Subject: |
[PATCH] pkl: Disallow labels in unions |
Date: |
Wed, 19 Jan 2022 19:09:16 +0330 |
2022-01-19 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
* libpoke/pkl-typify.c (pkl_typify1_ps_type_struct): Disallow
labels in unions.
* doc/poke.texi (Unions): Update.
* testsuite/poke.pkl/union-diag-9.pk: New test.
* testsuite/Makefile.am (EXTRA_DIST): Update.
---
ChangeLog | 8 ++++++++
doc/poke.texi | 3 ++-
libpoke/pkl-typify.c | 10 +++++++---
testsuite/Makefile.am | 1 +
testsuite/poke.pkl/union-diag-9.pk | 9 +++++++++
5 files changed, 27 insertions(+), 4 deletions(-)
create mode 100644 testsuite/poke.pkl/union-diag-9.pk
diff --git a/ChangeLog b/ChangeLog
index edff6c0a..bc0eed90 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2022-01-19 Mohammad-Reza Nabipoor <mnabipoor@gnu.org>
+
+ * libpoke/pkl-typify.c (pkl_typify1_ps_type_struct): Disallow
+ labels in unions.
+ * doc/poke.texi (Unions): Update.
+ * testsuite/poke.pkl/union-diag-9.pk: New test.
+ * testsuite/Makefile.am (EXTRA_DIST): Update.
+
2022-01-19 Jose E. Marchesi <jemarch@gnu.org>
* libpoke/std.pk (openproc): New function.
diff --git a/doc/poke.texi b/doc/poke.texi
index d074c5a8..a4a98f54 100644
--- a/doc/poke.texi
+++ b/doc/poke.texi
@@ -11185,7 +11185,8 @@ means. Alternatives are considered in turn, in written
order, and the
first alternative that can be used without triggering a constraint
violation exception is selected.
-Note that, unlike structs, unions cannot be pinned.
+Note that, unlike structs, unions cannot be pinned. And, like pinned
+structs, they cannot have labels.
@node Union Constructors
@subsection Union Constructors
diff --git a/libpoke/pkl-typify.c b/libpoke/pkl-typify.c
index 411e6392..cf0a96bc 100644
--- a/libpoke/pkl-typify.c
+++ b/libpoke/pkl-typify.c
@@ -1786,7 +1786,7 @@ PKL_PHASE_END_HANDLER
Pinned unions are not allowed.
- Labels are not allowed in integral structs and pinned structs.
+ Labels are not allowed in integral structs, pinned structs and unions.
Optional fields are not allowed in integral structs. */
PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_type_struct)
@@ -1877,7 +1877,8 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_type_struct)
PKL_PASS_ERROR;
}
- if (PKL_AST_TYPE_S_PINNED_P (struct_type))
+ if (PKL_AST_TYPE_S_PINNED_P (struct_type)
+ || PKL_AST_TYPE_S_UNION_P (struct_type))
{
for (field = PKL_AST_TYPE_S_ELEMS (struct_type);
field;
@@ -1889,7 +1890,10 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_type_struct)
if (PKL_AST_STRUCT_TYPE_FIELD_LABEL (field))
{
PKL_ERROR (PKL_AST_LOC (field),
- "labels are not allowed in pinned structs");
+ "labels are not allowed in %s",
+ PKL_AST_TYPE_S_PINNED_P (struct_type)
+ ? "pinned structs"
+ : "unions");
PKL_TYPIFY_PAYLOAD->errors++;
PKL_PASS_ERROR;
}
diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am
index 709cc89c..876cda66 100644
--- a/testsuite/Makefile.am
+++ b/testsuite/Makefile.am
@@ -2057,6 +2057,7 @@ EXTRA_DIST = \
poke.pkl/union-diag-6.pk \
poke.pkl/union-diag-7.pk \
poke.pkl/union-diag-8.pk \
+ poke.pkl/union-diag-9.pk \
poke.pkl/union-pretty-print-1.pk \
poke.pkl/units-1.pk \
poke.pkl/units-2.pk \
diff --git a/testsuite/poke.pkl/union-diag-9.pk
b/testsuite/poke.pkl/union-diag-9.pk
new file mode 100644
index 00000000..cbddc810
--- /dev/null
+++ b/testsuite/poke.pkl/union-diag-9.pk
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+
+/* Labels are now allowed in unions. */
+
+type Foo = union
+ {
+ int a : a != 10;
+ int b @ 1#B; /* { dg-error "" } */
+ };
--
2.34.1
- [PATCH] pkl: Disallow labels in unions,
Mohammad-Reza Nabipoor <=