poke-devel
[Top][All Lists]
Advanced

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

[COMMITTED] pkl: fix check for varargs in anal1


From: Jose E. Marchesi
Subject: [COMMITTED] pkl: fix check for varargs in anal1
Date: Thu, 23 Dec 2021 14:36:50 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

2021-12-23  Jose E. Marchesi  <jemarch@gnu.org>

        * libpoke/pkl-typify.c (pkl_typify1_pr_func): Do not set location
        information in generated type.
        * libpoke/pkl-anal.c (pkl_anal1_pr_func): Fix checking for vararg
        arguments.
---
 ChangeLog                                   |  7 +++++++
 libpoke/pkl-anal.c                          | 14 +++++++++-----
 libpoke/pkl-typify.c                        |  3 ---
 testsuite/poke.pkl/funcall-vararg-diag-2.pk |  2 +-
 4 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 7a15281a..01df1fef 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2021-12-23  Jose E. Marchesi  <jemarch@gnu.org>
 
+       * libpoke/pkl-typify.c (pkl_typify1_pr_func): Do not set location
+       information in generated type.
+       * libpoke/pkl-anal.c (pkl_anal1_pr_func): Fix checking for vararg
+       arguments.
+
+2021-12-23  Jose E. Marchesi  <jemarch@gnu.org>
+
        * libpoke/pkl-trans.c (pkl_trans1_ps_array): Emit an error instead
        of an ICE in case of a non-constant index in array initializer.
        * libpoke/pkl-anal.c (pkl_anal2_ps_array): Remove.
diff --git a/libpoke/pkl-anal.c b/libpoke/pkl-anal.c
index 8e82e361..7fae3ad3 100644
--- a/libpoke/pkl-anal.c
+++ b/libpoke/pkl-anal.c
@@ -344,14 +344,18 @@ PKL_PHASE_BEGIN_HANDLER (pkl_anal1_ps_func)
 {
   pkl_ast_node func = PKL_PASS_NODE;
   pkl_ast_node fa;
+  int in_opt_args = 0;
 
-  for (fa = PKL_AST_FUNC_FIRST_OPT_ARG (func);
+  for (fa = PKL_AST_FUNC_ARGS (func);
        fa;
        fa = PKL_AST_CHAIN (fa))
     {
+      if (fa == PKL_AST_FUNC_FIRST_OPT_ARG (func))
+        in_opt_args = 1;
+
       /* All optional formal arguments in a function specifier should
          be at the end of the arguments list.  */
-      if (!PKL_AST_FUNC_ARG_INITIAL (fa))
+      if (in_opt_args && !PKL_AST_FUNC_ARG_INITIAL (fa))
         {
           PKL_ERROR (PKL_AST_LOC (fa),
                      "non-optional argument after optional arguments");
@@ -361,8 +365,7 @@ PKL_PHASE_BEGIN_HANDLER (pkl_anal1_ps_func)
 
       /* If there is a vararg argument, it should be at the end of the
          list of arguments.  Also, it should be unique.  */
-      if (PKL_AST_FUNC_ARG_VARARG (fa) == 1
-          && PKL_AST_CHAIN (fa) != NULL)
+      if (PKL_AST_FUNC_ARG_VARARG (fa) == 1 && PKL_AST_CHAIN (fa) != NULL)
         {
           PKL_ERROR (PKL_AST_LOC (fa),
                      "vararg argument should be the last argument");
@@ -389,7 +392,8 @@ PKL_PHASE_BEGIN_HANDLER (pkl_anal1_ps_type_function)
        arg = PKL_AST_CHAIN (arg))
     {
       if (PKL_AST_FUNC_TYPE_ARG_VARARG (arg)
-          && PKL_AST_CHAIN (arg) != NULL)
+          && PKL_AST_CHAIN (arg) != NULL
+          && PKL_AST_LOC_VALID (PKL_AST_LOC (arg)))
         {
           PKL_ERROR (PKL_AST_LOC (arg),
                      "vararg argument should be the last argument");
diff --git a/libpoke/pkl-typify.c b/libpoke/pkl-typify.c
index 76c43a3d..54ebbbb0 100644
--- a/libpoke/pkl-typify.c
+++ b/libpoke/pkl-typify.c
@@ -1359,9 +1359,6 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_pr_func)
         = pkl_ast_make_func_type_arg (PKL_PASS_AST,
                                       PKL_AST_FUNC_ARG_TYPE (t),
                                       PKL_AST_FUNC_ARG_IDENTIFIER (t));
-      PKL_AST_LOC (func_type_arg) = PKL_AST_LOC (t); /* XXX this
-                                                        shouldn't be
-                                                        necessary.  */
 
       func_type_args = pkl_ast_chainon (func_type_args,
                                         func_type_arg);
diff --git a/testsuite/poke.pkl/funcall-vararg-diag-2.pk 
b/testsuite/poke.pkl/funcall-vararg-diag-2.pk
index 4ef12e1b..0bcf6288 100644
--- a/testsuite/poke.pkl/funcall-vararg-diag-2.pk
+++ b/testsuite/poke.pkl/funcall-vararg-diag-2.pk
@@ -2,5 +2,5 @@
 
 fun foo = (args..., int a) int: /* { dg-error "" } */
   {
-   return args[0];
+   return args[0] as int;
   }
-- 
2.11.0




reply via email to

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