From f9548cb213df417520937ff8471fafd1be11b5c2 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Tue, 20 Jun 2023 17:05:13 +0200 Subject: [PATCH] Fix nested hash resolution for access identifiers. Fixes #789 --- src/compiler/sema_expr.c | 3 +- src/version.h | 2 +- test/test_suite/macros/hash_ident_nested.c3t | 36 ++++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 test/test_suite/macros/hash_ident_nested.c3t diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 7cb5c730c..94d7079db 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -2824,7 +2824,8 @@ RETRY: { Decl *decl = sema_resolve_symbol(context, child->hash_ident_expr.identifier, NULL, child->span); if (!decl_ok(decl)) return NULL; - return sema_expr_resolve_access_child(context, decl->var.init_expr, missing); + Expr *expr = copy_expr_single(decl->var.init_expr); + return sema_expr_resolve_access_child(decl->var.hash_var.context, expr, missing); } case EXPR_CT_EVAL: { diff --git a/src/version.h b/src/version.h index 181b6ac06..6b43e1599 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define COMPILER_VERSION "0.4.532" \ No newline at end of file +#define COMPILER_VERSION "0.4.533" \ No newline at end of file diff --git a/test/test_suite/macros/hash_ident_nested.c3t b/test/test_suite/macros/hash_ident_nested.c3t new file mode 100644 index 000000000..9bb473c4a --- /dev/null +++ b/test/test_suite/macros/hash_ident_nested.c3t @@ -0,0 +1,36 @@ +// #target: macos-x64 +module test; +fn void main() +{ + @foo(x); +} + +struct Point { float x; float y; } + +macro @foo(#x) +{ + @bar(#x); +} + +macro @bar(#x) +{ + Point pt; + var z = pt.#x; +} + +/* #expect: test.ll + +define void @test.main() #0 { +entry: + %pt = alloca %Point, align 4 + %z = alloca float, align 4 + %0 = getelementptr inbounds %Point, ptr %pt, i32 0, i32 0 + store float 0.000000e+00, ptr %0, align 4 + %1 = getelementptr inbounds %Point, ptr %pt, i32 0, i32 1 + store float 0.000000e+00, ptr %1, align 4 + %2 = getelementptr inbounds %Point, ptr %pt, i32 0, i32 0 + %3 = load float, ptr %2, align 4 + store float %3, ptr %z, align 4 + ret void +} +