zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 0fbb9e09ea89ea24ec214b244e1de9574516c74c (tree)
parent a2ac06dcd506fd5e119e4eb8e1de201fefa05bbc
Author: Andrew Kelley <superjoe30@gmail.com>
Date:   Tue, 16 Aug 2016 23:24:33 -0700

fix crash when calling method on slice

Diffstat:
Msrc/analyze.cpp | 2+-
Mtest/run_tests.cpp | 6++++++
2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/analyze.cpp b/src/analyze.cpp @@ -2686,7 +2686,7 @@ static TypeTableEntry *analyze_field_access_expr(CodeGen *g, ImportTableEntry *i node->data.field_access_expr.type_struct_field = find_struct_type_field(bare_struct_type, field_name); if (node->data.field_access_expr.type_struct_field) { return node->data.field_access_expr.type_struct_field->type_entry; - } else if (wrapped_in_fn_call) { + } else if (wrapped_in_fn_call && !is_slice(bare_struct_type)) { BlockContext *container_block_context = get_container_block_context(bare_struct_type); assert(container_block_context); auto entry = container_block_context->decl_table.maybe_get(field_name); diff --git a/test/run_tests.cpp b/test/run_tests.cpp @@ -1451,6 +1451,12 @@ fn function_with_return_type_type() { ".tmp_source.zig:3:5: error: failed to evaluate function at compile time", ".tmp_source.zig:4:5: note: unable to evaluate this expression at compile time", ".tmp_source.zig:3:32: note: required to be compile-time function because of return type 'type'"); + + add_compile_fail_case("bogus method call on slice", R"SOURCE( +fn f(m: []const u8) { + m.copy(u8, self.list.items[old_len...], m); +} + )SOURCE", 1, ".tmp_source.zig:3:6: error: no member named 'copy' in '[]const u8'"); } //////////////////////////////////////////////////////////////////////////////