[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] pkl: Fix promotion of initializer in structs
From: |
Mohammad-Reza Nabipoor |
Subject: |
[PATCH] pkl: Fix promotion of initializer in structs |
Date: |
Sun, 13 Dec 2020 21:32:24 +0330 |
The promotion shouldn't be attempted if initializer has the same type
as the field.
2020-12-13 Mohammad-Reza Nabipoor <m.nabipoor@yahoo.com>
* libpoke/pkl-promo.c (pkl_promo_ps_struct_type_field): Skip
promotion of initializer if it has the same type as the field.
* testsuite/poke.pkl/struct-types-7.pk: New test.
* testsuite/Makefile.am (EXTRA_DIST): Update.
---
ChangeLog | 7 +++++++
libpoke/pkl-promo.c | 4 +++-
testsuite/Makefile.am | 1 +
testsuite/poke.pkl/struct-types-7.pk | 9 +++++++++
4 files changed, 20 insertions(+), 1 deletion(-)
create mode 100644 testsuite/poke.pkl/struct-types-7.pk
diff --git a/ChangeLog b/ChangeLog
index 26b3b3b8..146dde90 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2020-12-13 Mohammad-Reza Nabipoor <m.nabipoor@yahoo.com>
+
+ * libpoke/pkl-promo.c (pkl_promo_ps_struct_type_field): Skip
+ promotion of initializer if it has the same type as the field.
+ * testsuite/poke.pkl/struct-types-7.pk: New test.
+ * testsuite/Makefile.am (EXTRA_DIST): Update.
+
2020-12-13 Jose E. Marchesi <jemarch@gnu.org>
* libpoke/pvm-val.h (struct pvm_mapinfo): New type.
diff --git a/libpoke/pkl-promo.c b/libpoke/pkl-promo.c
index 3dee6081..cdd890bf 100644
--- a/libpoke/pkl-promo.c
+++ b/libpoke/pkl-promo.c
@@ -1499,7 +1499,9 @@ PKL_PHASE_BEGIN_HANDLER (pkl_promo_ps_struct_type_field)
PKL_PASS_RESTART = restart;
}
- if (elem_initializer)
+ if (elem_initializer &&
+ !pkl_ast_type_equal_p (PKL_AST_STRUCT_TYPE_FIELD_TYPE (elem),
+ PKL_AST_TYPE (elem_initializer)))
{
int restart = 0;
pkl_ast_node elem_type = PKL_AST_STRUCT_TYPE_FIELD_TYPE (elem);
diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am
index 34598128..56252b20 100644
--- a/testsuite/Makefile.am
+++ b/testsuite/Makefile.am
@@ -1645,6 +1645,7 @@ EXTRA_DIST = \
poke.pkl/struct-types-4.pk \
poke.pkl/struct-types-5.pk \
poke.pkl/struct-types-6.pk \
+ poke.pkl/struct-types-7.pk \
poke.pkl/struct-types-defun-1.pk \
poke.pkl/struct-types-defun-2.pk \
poke.pkl/struct-types-defun-3.pk \
diff --git a/testsuite/poke.pkl/struct-types-7.pk
b/testsuite/poke.pkl/struct-types-7.pk
new file mode 100644
index 00000000..d997c097
--- /dev/null
+++ b/testsuite/poke.pkl/struct-types-7.pk
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+
+/* This was a bug in promotion of initializer. */
+
+type S =
+ struct
+ {
+ string s = "";
+ };
--
2.29.2
- [PATCH] pkl: Fix promotion of initializer in structs,
Mohammad-Reza Nabipoor <=