[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2] pkl: Report funcarg index, if there's no name
From: |
Mohammad-Reza Nabipoor |
Subject: |
[PATCH v2] pkl: Report funcarg index, if there's no name |
Date: |
Sat, 22 Jan 2022 21:36:58 +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.
---
Hi, Jose.
Alfred told me that having dupplication is not a good idea, and he
is right :)
So, this new patch does the same think with less dupplication.
Feel free to choose one them :D
Regards,
Mohammad-Reza
ChangeLog | 5 +++++
libpoke/pkl-typify.c | 17 ++++++++++++++---
2 files changed, 19 insertions(+), 3 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..fa621aa6 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))
{
@@ -1526,18 +1527,28 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_funcall)
pkl_ast_node arg_name = PKL_AST_FUNC_TYPE_ARG_NAME (fa);
char *passed_type = pkl_type_str (aa_type, 1);
char *expected_type = pkl_type_str (fa_type, 1);
+ char arg_index_str[16];
+ char *arg_name_str;
+ if (arg_name)
+ arg_name_str = PKL_AST_IDENTIFIER_POINTER (arg_name);
+ else
+ {
+ snprintf(arg_index_str, sizeof (arg_index_str), "%d",
+ narg + 1);
+ arg_name_str = arg_index_str;
+ }
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);
+ arg_index_str, expected_type, passed_type);
free (expected_type);
free (passed_type);
PKL_TYPIFY_PAYLOAD->errors++;
PKL_PASS_ERROR;
}
+ narg++;
}
}
--
2.34.1