poke-devel
[Top][All Lists]
Advanced

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

[PATCH] pkl: Report funcarg index, if there's no name


From: Mohammad-Reza Nabipoor
Subject: [PATCH] pkl: Report funcarg index, if there's no name
Date: Sat, 22 Jan 2022 21:10:45 +0330

2022-01-22  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>

        * libpoke/pkl-typify.c (pkl_typify1_ps_funcall): When the arg
        doesn't have a name, uses the arg index in error reporting.
---
 ChangeLog            |  5 +++++
 libpoke/pkl-typify.c | 20 ++++++++++++++------
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2ac9daa4..ee3e304c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2022-01-22  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
+
+       * libpoke/pkl-typify.c (pkl_typify1_ps_funcall): When the arg
+       doesn't have a name, uses the arg index in error reporting.
+
 2022-01-22  Jose E. Marchesi  <jemarch@gnu.org>
 
        * libpoke/pkl-rt-1.pk (Pk_Type): Add closures for array and struct
diff --git a/libpoke/pkl-typify.c b/libpoke/pkl-typify.c
index 1a761890..ec652e5d 100644
--- a/libpoke/pkl-typify.c
+++ b/libpoke/pkl-typify.c
@@ -1503,7 +1503,8 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_funcall)
   /* Ok, check that the types of the actual arguments match the
      types of the corresponding formal arguments.  */
   for (fa = PKL_AST_TYPE_F_ARGS  (funcall_function_type),
-         aa = PKL_AST_FUNCALL_ARGS (funcall);
+         aa = PKL_AST_FUNCALL_ARGS (funcall),
+         narg = 0;
        fa && aa;
        fa = PKL_AST_CHAIN (fa), aa = PKL_AST_CHAIN (aa))
     {
@@ -1527,17 +1528,24 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_funcall)
               char *passed_type = pkl_type_str (aa_type, 1);
               char *expected_type = pkl_type_str (fa_type, 1);
 
-              PKL_ERROR (PKL_AST_LOC (aa),
-                         "invalid value for function argument `%s'\n"
-                         "expected %s, got %s",
-                         PKL_AST_IDENTIFIER_POINTER (arg_name),
-                         expected_type, passed_type);
+              if (arg_name)
+                PKL_ERROR (PKL_AST_LOC (aa),
+                           "invalid value for function argument `%s'\n"
+                           "expected %s, got %s",
+                           PKL_AST_IDENTIFIER_POINTER (arg_name),
+                           expected_type, passed_type);
+              else
+                PKL_ERROR (PKL_AST_LOC (aa),
+                           "invalid value for function argument `%d'\n"
+                           "expected %s, got %s",
+                           narg + 1, expected_type, passed_type);
               free (expected_type);
               free (passed_type);
 
               PKL_TYPIFY_PAYLOAD->errors++;
               PKL_PASS_ERROR;
             }
+          narg++;
         }
     }
 
-- 
2.34.1




reply via email to

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