From 34c7f4e6b77e3eacca44a1e84721f10f7ae34ceb Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Mon, 6 Jan 2025 13:54:02 +0100 Subject: [PATCH] Deref subscripts as needed for macro ref method arguments. #1789 --- releasenotes.md | 1 + src/compiler/sema_expr.c | 1 + test/test_suite/macros/ref_macro_method.c3 | 26 ++++++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 test/test_suite/macros/ref_macro_method.c3 diff --git a/releasenotes.md b/releasenotes.md index fb031669d..872d9a7f3 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -59,6 +59,7 @@ - Fix `+a = 1` erronously being accepted. - Fix not freeing a zero length String - Macros with trailing bodys aren't allowed as the single statement after a while loop with no body #1772. +- Deref subscripts as needed for macro ref method arguments. #1789 ### Stdlib changes - Increase BitWriter.write_bits limit up to 32 bits. diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 4ed1575d7..260618f4f 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -1323,6 +1323,7 @@ static bool sema_analyse_parameter(SemaContext *context, Expr *arg, Decl *param, switch (arg->expr_kind) { case EXPR_SUBSCRIPT: + if (type) break; arg->expr_kind = EXPR_SUBSCRIPT_ADDR; is_subscript = true; break; diff --git a/test/test_suite/macros/ref_macro_method.c3 b/test/test_suite/macros/ref_macro_method.c3 new file mode 100644 index 000000000..7cd42e8f6 --- /dev/null +++ b/test/test_suite/macros/ref_macro_method.c3 @@ -0,0 +1,26 @@ +import std::io; + +struct MyStruct +{ + DString* dyn; +} + +fn void main() +{ + @pool() + { + usz values_len = 10; + + MyStruct ms = { + .dyn = mem::temp_new_array(DString, values_len).ptr, + }; + + for (usz i; i < values_len; ++i) + { + ms.dyn[i].temp_init(); + } + + ms.dyn[0].append_chars("sad"); + ms.dyn[0].append("sad"); + }; +} \ No newline at end of file