diff --git a/releasenotes.md b/releasenotes.md index 51579469b..bf80ee6f3 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -20,6 +20,7 @@ - Regression with invalid setup of the WASM temp allocator. - Correctly detect multiple overloads of the same type. - ABI bug on x64 Linux / MacOS when passing a union containing a struct of 3 floats. #2087 +- Bug with slice acces as inline struct member #2088. ### Stdlib changes - Hash functions for integer vectors and arrays. diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 115849273..90cb65a3d 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -5362,13 +5362,13 @@ CHECK_DEEPER: if (flat_type->type_kind == TYPE_SLICE) { // Handle literal "foo".len which is now a slice. - sema_expr_flatten_const_ident(parent); - if (expr_is_const_string(parent)) + sema_expr_flatten_const_ident(current_parent); + if (expr_is_const_string(current_parent)) { - expr_rewrite_const_int(expr, type_isz, parent->const_expr.bytes.len); + expr_rewrite_const_int(expr, type_isz, current_parent->const_expr.bytes.len); return true; } - expr_rewrite_slice_len(expr, parent, type_usz); + expr_rewrite_slice_len(expr, current_parent, type_usz); return true; } if (flat_type->type_kind == TYPE_ARRAY || flat_type->type_kind == TYPE_VECTOR) @@ -5385,7 +5385,7 @@ CHECK_DEEPER: if (flat_type->type_kind == TYPE_TYPEID) { bool was_error = false; - if (sema_expr_rewrite_to_typeid_property(context, expr, parent, kw, &was_error)) return !was_error; + if (sema_expr_rewrite_to_typeid_property(context, expr, current_parent, kw, &was_error)) return !was_error; } if (flat_type->type_kind == TYPE_VECTOR) { @@ -5486,7 +5486,7 @@ CHECK_DEEPER: if (!sema_analyse_decl(context, decl)) return false; Decl *ref = current_parent->const_expr.enum_val; if (!sema_analyse_decl(context, ref)) return false; - ASSERT_SPAN(expr, parent->const_expr.const_kind == CONST_ENUM); + ASSERT_SPAN(expr, current_parent->const_expr.const_kind == CONST_ENUM); Expr *copy_init = copy_expr_single(ref->enum_constant.args[member->var.index]); expr_replace(expr, copy_init); ASSERT_SPAN(expr, copy_init->resolve_status == RESOLVE_DONE); diff --git a/test/test_suite/struct/inline_slice_access_2088.c3t b/test/test_suite/struct/inline_slice_access_2088.c3t new file mode 100644 index 000000000..e97954ec7 --- /dev/null +++ b/test/test_suite/struct/inline_slice_access_2088.c3t @@ -0,0 +1,22 @@ +// #target: macos-x64 +module test; + +struct Foo +{ + inline String str; +} + +fn int main() +{ + (Foo){}.len; + return 0; +} + +/* #expect: test.ll + +entry: + %literal = alloca %Foo, align 8 + call void @llvm.memset.p0.i64(ptr align 8 %literal, i8 0, i64 16, i1 false) + %ptradd = getelementptr inbounds i8, ptr %literal, i64 8 + ret i32 0 +}