From 7647378e7cc27f73190f8a158cb78272468e6ea5 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Sat, 3 Dec 2022 23:07:37 +0100 Subject: [PATCH] Fix missing check when macro method incorrectly has a raw vararg argument. --- src/compiler/sema_decls.c | 8 ++++++-- src/version.h | 2 +- test/test_suite/macro_methods/macro_method_first_param.c3 | 4 ++++ .../test_suite2/macro_methods/macro_method_first_param.c3 | 4 ++++ 4 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 test/test_suite/macro_methods/macro_method_first_param.c3 create mode 100644 test/test_suite2/macro_methods/macro_method_first_param.c3 diff --git a/src/compiler/sema_decls.c b/src/compiler/sema_decls.c index c0cd23eae..a98c7feb6 100644 --- a/src/compiler/sema_decls.c +++ b/src/compiler/sema_decls.c @@ -2170,11 +2170,15 @@ static bool sema_analyse_macro_method(SemaContext *context, Decl *decl) } if (!vec_size(decl->func_decl.signature.params)) { - SEMA_ERROR(decl, "Expected at least one parameter - of type %s.", type_to_error_string(parent_type)); + SEMA_ERROR(decl, "Expected at least one parameter - of type '%s'.", type_to_error_string(parent_type)); return false; } Decl *first_param = decl->func_decl.signature.params[0]; - + if (!first_param) + { + SEMA_ERROR(decl, "The first parameter to this method must be of type '%s'.", type_to_error_string(parent_type)); + return false; + } if (!sema_is_valid_method_param(context, first_param, parent_type->canonical)) return false; if (first_param->var.kind != VARDECL_PARAM_REF && first_param->var.kind != VARDECL_PARAM) diff --git a/src/version.h b/src/version.h index fc8f3cbdf..2178fbbc1 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define COMPILER_VERSION "0.3.103" \ No newline at end of file +#define COMPILER_VERSION "0.3.104" \ No newline at end of file diff --git a/test/test_suite/macro_methods/macro_method_first_param.c3 b/test/test_suite/macro_methods/macro_method_first_param.c3 new file mode 100644 index 000000000..c670e2446 --- /dev/null +++ b/test/test_suite/macro_methods/macro_method_first_param.c3 @@ -0,0 +1,4 @@ + +struct Foo { int y; } + +macro Foo.text(...) = f.y; // #error: The first parameter to this method must \ No newline at end of file diff --git a/test/test_suite2/macro_methods/macro_method_first_param.c3 b/test/test_suite2/macro_methods/macro_method_first_param.c3 new file mode 100644 index 000000000..c670e2446 --- /dev/null +++ b/test/test_suite2/macro_methods/macro_method_first_param.c3 @@ -0,0 +1,4 @@ + +struct Foo { int y; } + +macro Foo.text(...) = f.y; // #error: The first parameter to this method must \ No newline at end of file