poke-devel
[Top][All Lists]
Advanced

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

[COMMITTED] pkl: do not validate _print* functions as if they were metho


From: Jose E. Marchesi
Subject: [COMMITTED] pkl: do not validate _print* functions as if they were methods
Date: Fri, 27 Jan 2023 01:38:04 +0100
User-agent: Gnus/5.13 (Gnus v5.13)


Functions called _print* are not pretty-printing methods.  This patch
fixes a bug in the compiler, that was (incorrectly) validating them as
such.

I have installed this in master, and a suitable modified version in
poke/maint-3.

2023-01-27  Jose E. Marchesi  <jemarch@gnu.org>

        * libpoke/pkl-typify.c (pkl_typify1_ps_decl): Do not validate
        signature of _print* functions, as opposed to methods.
        * testsuite/poke.pkl/struct-types-defun-4.pk: New test.
        * testsuite/poke.pkl/struct-field-pretty-print-diag-1.pk: Fix
        test.
        * testsuite/poke.pkl/struct-field-pretty-print-diag-2.pk: Likewise.
        * testsuite/poke.pkl/struct-pretty-print-diag-1.pk: Likewise.
        * testsuite/poke.pkl/struct-pretty-print-diag-2.pk: Likewise.
---
 ChangeLog                                            | 11 +++++++++++
 libpoke/pkl-typify.c                                 |  3 ++-
 testsuite/Makefile.am                                |  1 +
 .../poke.pkl/struct-field-pretty-print-diag-1.pk     |  2 +-
 .../poke.pkl/struct-field-pretty-print-diag-2.pk     |  2 +-
 testsuite/poke.pkl/struct-pretty-print-diag-1.pk     |  2 +-
 testsuite/poke.pkl/struct-pretty-print-diag-2.pk     |  2 +-
 testsuite/poke.pkl/struct-types-defun-4.pk           | 12 ++++++++++++
 8 files changed, 30 insertions(+), 5 deletions(-)
 create mode 100644 testsuite/poke.pkl/struct-types-defun-4.pk

diff --git a/ChangeLog b/ChangeLog
index 845b31de..9dea9f1f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2023-01-27  Jose E. Marchesi  <jemarch@gnu.org>
+
+       * libpoke/pkl-typify.c (pkl_typify1_ps_decl): Do not validate
+       signature of _print* functions, as opposed to methods.
+       * testsuite/poke.pkl/struct-types-defun-4.pk: New test.
+       * testsuite/poke.pkl/struct-field-pretty-print-diag-1.pk: Fix
+       test.
+       * testsuite/poke.pkl/struct-field-pretty-print-diag-2.pk: Likewise.
+       * testsuite/poke.pkl/struct-pretty-print-diag-1.pk: Likewise.
+       * testsuite/poke.pkl/struct-pretty-print-diag-2.pk: Likewise.
+
 2023-01-27  Jose E. Marchesi  <jemarch@gnu.org>
 
        * libpoke/pkl-typify.c (pkl_typify1_ps_decl): Check field
diff --git a/libpoke/pkl-typify.c b/libpoke/pkl-typify.c
index d0cc76c7..cd1e4cbc 100644
--- a/libpoke/pkl-typify.c
+++ b/libpoke/pkl-typify.c
@@ -2715,7 +2715,8 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_decl)
   if (PKL_PASS_PARENT
       && PKL_AST_CODE (PKL_PASS_PARENT) == PKL_AST_TYPE
       && PKL_AST_TYPE_CODE (PKL_PASS_PARENT) == PKL_TYPE_STRUCT
-      && PKL_AST_DECL_KIND (decl) == PKL_AST_DECL_KIND_FUNC)
+      && PKL_AST_DECL_KIND (decl) == PKL_AST_DECL_KIND_FUNC
+      && PKL_AST_FUNC_METHOD_P (PKL_AST_DECL_INITIAL (decl)))
     {
       pkl_ast_node decl_name = PKL_AST_DECL_NAME (decl);
       const char *decl_name_str = PKL_AST_IDENTIFIER_POINTER (decl_name);
diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am
index 92bd58f6..ca89b579 100644
--- a/testsuite/Makefile.am
+++ b/testsuite/Makefile.am
@@ -2449,6 +2449,7 @@ EXTRA_DIST = \
   poke.pkl/struct-types-defun-1.pk \
   poke.pkl/struct-types-defun-2.pk \
   poke.pkl/struct-types-defun-3.pk \
+  poke.pkl/struct-types-defun-4.pk \
   poke.pkl/struct-types-defun-diag-1.pk \
   poke.pkl/struct-types-defun-diag-2.pk \
   poke.pkl/struct-types-diag-2.pk \
diff --git a/testsuite/poke.pkl/struct-field-pretty-print-diag-1.pk 
b/testsuite/poke.pkl/struct-field-pretty-print-diag-1.pk
index 7ae50756..cba9d930 100644
--- a/testsuite/poke.pkl/struct-field-pretty-print-diag-1.pk
+++ b/testsuite/poke.pkl/struct-field-pretty-print-diag-1.pk
@@ -4,5 +4,5 @@ type Foo =
   struct
   {
     int lala;
-    fun _print_lala = int: { return 0; } /* { dg-error "should be of type" } */
+    method _print_lala = int: { return 0; } /* { dg-error "should be of type" 
} */
   };
diff --git a/testsuite/poke.pkl/struct-field-pretty-print-diag-2.pk 
b/testsuite/poke.pkl/struct-field-pretty-print-diag-2.pk
index 9ed1fe51..ae34ab8f 100644
--- a/testsuite/poke.pkl/struct-field-pretty-print-diag-2.pk
+++ b/testsuite/poke.pkl/struct-field-pretty-print-diag-2.pk
@@ -4,5 +4,5 @@ type Foo =
   struct
   {
     int lala;
-    fun _print_lala = (int a) void: { print "foo"; } /* { dg-error "should be 
of type" } */
+    method _print_lala = (int a) void: { print "foo"; } /* { dg-error "should 
be of type" } */
   };
diff --git a/testsuite/poke.pkl/struct-pretty-print-diag-1.pk 
b/testsuite/poke.pkl/struct-pretty-print-diag-1.pk
index c74221eb..1c2371a2 100644
--- a/testsuite/poke.pkl/struct-pretty-print-diag-1.pk
+++ b/testsuite/poke.pkl/struct-pretty-print-diag-1.pk
@@ -3,5 +3,5 @@
 type Foo =
   struct
   {
-    fun _print = int: { return 0; } /* { dg-error "should be of type" } */
+    method _print = int: { return 0; } /* { dg-error "should be of type" } */
   };
diff --git a/testsuite/poke.pkl/struct-pretty-print-diag-2.pk 
b/testsuite/poke.pkl/struct-pretty-print-diag-2.pk
index 66406d65..c0af07ba 100644
--- a/testsuite/poke.pkl/struct-pretty-print-diag-2.pk
+++ b/testsuite/poke.pkl/struct-pretty-print-diag-2.pk
@@ -3,5 +3,5 @@
 type Foo =
   struct
   {
-    fun _print = (int a) void: { print "foo"; } /* { dg-error "should be of 
type" } */
+    method _print = (int a) void: { print "foo"; } /* { dg-error "should be of 
type" } */
   };
diff --git a/testsuite/poke.pkl/struct-types-defun-4.pk 
b/testsuite/poke.pkl/struct-types-defun-4.pk
new file mode 100644
index 00000000..541bcf8d
--- /dev/null
+++ b/testsuite/poke.pkl/struct-types-defun-4.pk
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+
+/* Functions called _print* shall not be validated
+   as if they were pretty-printer methods.  */
+
+type Foo =
+  struct
+  {
+    int i;
+    fun _print = int: { return 0; }
+    fun _print_i = (int a) void: { print "jorl"; }
+  };
-- 
2.30.2




reply via email to

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