poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[COMMITTED] pkl-gen: fix checking of E_elem in struct function bodies


From: Jose E. Marchesi
Subject: [COMMITTED] pkl-gen: fix checking of E_elem in struct function bodies
Date: Sat, 04 Nov 2023 15:00:48 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

2023-11-03  Jose E. Marchesi  <jemarch@gnu.org>

        * libpoke/pkl-gen.c (pkl_gen_ps_var): Fix detection of
        non-methods.
        * testsuite/poke.pkl/optcond-pre-13.pk: New test.
        * testsuite/poke.pkl/optcond-pre-14.pk: Likewise.
        * testsuite/Makefile.am (EXTRA_DIST): Add new tests.
---
 ChangeLog                            |  8 ++++++++
 libpoke/pkl-gen.c                    |  2 +-
 testsuite/Makefile.am                |  2 ++
 testsuite/poke.pkl/optcond-pre-13.pk | 13 +++++++++++++
 testsuite/poke.pkl/optcond-pre-14.pk | 14 ++++++++++++++
 5 files changed, 38 insertions(+), 1 deletion(-)
 create mode 100644 testsuite/poke.pkl/optcond-pre-13.pk
 create mode 100644 testsuite/poke.pkl/optcond-pre-14.pk

diff --git a/ChangeLog b/ChangeLog
index 3ba578df..8773120a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-11-03  Jose E. Marchesi  <jemarch@gnu.org>
+
+       * libpoke/pkl-gen.c (pkl_gen_ps_var): Fix detection of
+       non-methods.
+       * testsuite/poke.pkl/optcond-pre-13.pk: New test.
+       * testsuite/poke.pkl/optcond-pre-14.pk: Likewise.
+       * testsuite/Makefile.am (EXTRA_DIST): Add new tests.
+
 2023-11-03  Jose E. Marchesi  <jemarch@gnu.org>
 
        * poke/poke.pk (pk_exception_handler): Fix styling.
diff --git a/libpoke/pkl-gen.c b/libpoke/pkl-gen.c
index 9fddbb31..5fba0a6a 100644
--- a/libpoke/pkl-gen.c
+++ b/libpoke/pkl-gen.c
@@ -606,7 +606,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_ps_var)
          like a constraint expression or an optional field condition,
          then raise E_elem if the value is null.  */
       if (PKL_AST_DECL_STRUCT_FIELD_P (var_decl)
-          && !var_function)
+          && (!var_function || !PKL_AST_FUNC_METHOD_P (var_function)))
         {
           pvm_program_label label
             = pkl_asm_fresh_label (PKL_GEN_ASM);
diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am
index 7918dac0..d193e811 100644
--- a/testsuite/Makefile.am
+++ b/testsuite/Makefile.am
@@ -2041,6 +2041,8 @@ EXTRA_DIST = \
   poke.pkl/optcond-pre-10.pk \
   poke.pkl/optcond-pre-11.pk \
   poke.pkl/optcond-pre-12.pk \
+  poke.pkl/optcond-pre-13.pk \
+  poke.pkl/optcond-pre-14.pk \
   poke.pkl/optcond-pre-2.pk \
   poke.pkl/optcond-pre-3.pk \
   poke.pkl/optcond-pre-4.pk \
diff --git a/testsuite/poke.pkl/optcond-pre-13.pk 
b/testsuite/poke.pkl/optcond-pre-13.pk
new file mode 100644
index 00000000..424fe200
--- /dev/null
+++ b/testsuite/poke.pkl/optcond-pre-13.pk
@@ -0,0 +1,13 @@
+/* { dg-do run } */
+
+type Foo =
+  struct
+  {
+    int tag;
+    if (tag > 0)
+      int foo;
+    int bar = lambda int: { return foo; }();
+  };
+
+/* { dg-command {try Foo {}; catch if E_elem { print "caught\n"; } } } */
+/* { dg-output "caught" } */
diff --git a/testsuite/poke.pkl/optcond-pre-14.pk 
b/testsuite/poke.pkl/optcond-pre-14.pk
new file mode 100644
index 00000000..95f8c482
--- /dev/null
+++ b/testsuite/poke.pkl/optcond-pre-14.pk
@@ -0,0 +1,14 @@
+/* { dg-do run } */
+
+type Foo =
+  struct
+  {
+    int tag;
+    if (tag > 0)
+      int foo;
+    fun jaja = int: { return foo; }
+    int quux = jaja; 
+  };
+
+/* { dg-command {try Foo {}; catch if E_elem { print "caught\n"; } } } */
+/* { dg-output "caught" } */
-- 
2.30.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]