From 7f64f7c9259ba5f67adb386ba55473d4b2b74607 Mon Sep 17 00:00:00 2001 From: Cody Tapscott Date: Wed, 23 Mar 2022 22:03:17 -0700 Subject: [PATCH 1/3] Add rudimentary compile error test file support This brings two quality-of-life improvements for folks working on compile error test cases: - test cases can be added/changed without re-building Zig - wrapping the source in a multi-line string literal is not necessary I decided to keep things as simple as possible for this initial implementation. The test "manifest" is a contiguous comment block at the end of the test file: 1. The first line is the test case name 2. The second line is a blank comment 2. The following lines are expected errors Here's an example: ```zig const U = union(enum(u2)) { A: u8, B: u8, C: u8, D: u8, E: u8, }; export fn entry() void { _ = U{ .E = 1 }; } // union with too small explicit unsigned tag type // // tmp.zig:1:22: error: specified integer tag type cannot represent every field // tmp.zig:1:22: note: type u2 cannot fit values in range 0...4 ``` The mode of the test (obj/exe/test), as well as the target (stage1/stage2) is determined based on the directory containing the test. We'll probably eventually want to support embedding this information in the test files themselves, similar to the arocc test runner, but that enhancement can be tackled later. --- src/test.zig | 99 +++++++++++++++++++++++++++++++++++++++++ test/compile_errors.zig | 36 +++++++++++++++ 2 files changed, 135 insertions(+) diff --git a/src/test.zig b/src/test.zig index e2be5e2172..6bdff16a58 100644 --- a/src/test.zig +++ b/src/test.zig @@ -20,6 +20,7 @@ const assert = std.debug.assert; const zig_h = link.File.C.zig_h; +var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){}; const hr = "=" ** 80; test { @@ -594,6 +595,104 @@ pub const TestContext = struct { case.compiles(fixed_src); } + /// Adds a compile-error test for each file in the provided directory, using the + /// selected backend and output mode. If `one_test_case_per_file` is true, a new + /// test case is created for each file. Otherwise, a single test case is used for + /// all tests. + /// + /// Each file should include a test manifest as a contiguous block of comments at + /// the end of the file. The first line should be the test case name, followed by + /// a blank line, then one expected errors on each line in the form + /// `:line:column: error: message` + pub fn addErrorCasesFromDir( + ctx: *TestContext, + name: []const u8, + dir: std.fs.Dir, + backend: Backend, + output_mode: std.builtin.OutputMode, + is_test: bool, + one_test_case_per_file: bool, + ) !void { + if (skip_compile_errors) return; + + const gpa = general_purpose_allocator.allocator(); + var case: ?*Case = null; + + var it = dir.iterate(); + while (try it.next()) |entry| { + if (entry.kind != .File) continue; + + var contents = try dir.readFileAlloc(gpa, entry.name, std.math.maxInt(u32)); + defer gpa.free(contents); + + // The manifest is the last contiguous block of comments in the file + // We scan for the beginning by searching backward for the first non-empty line that does not start with "//" + var manifest_start: ?usize = null; + var manifest_end: usize = contents.len; + if (contents.len > 0) { + var cursor: usize = contents.len - 1; + while (true) { + // Move to beginning of line + while (cursor > 0 and contents[cursor - 1] != '\n') cursor -= 1; + + // Check if line is non-empty and does not start with "//" + if (cursor + 1 < contents.len and contents[cursor + 1] != '\n' and contents[cursor + 1] != '\r') { + if (std.mem.startsWith(u8, contents[cursor..], "//")) { + manifest_start = cursor; + } else { + break; + } + } else manifest_end = cursor; + + // Move to previous line + if (cursor != 0) cursor -= 1 else break; + } + } + + var errors = std.ArrayList([]const u8).init(gpa); + defer errors.deinit(); + + if (manifest_start) |start| { + // Due to the above processing, we know that this is a contiguous block of comments + var manifest_it = std.mem.tokenize(u8, contents[start..manifest_end], "\r\n"); + + // First line is the test case name + const first_line = manifest_it.next() orelse return error.InvalidFile; + const case_name = try std.mem.concat(gpa, u8, &.{ name, ": ", std.mem.trim(u8, first_line[2..], " \t") }); + + // If the second line is present, it should be blank + if (manifest_it.next()) |second_line| { + if (std.mem.trim(u8, second_line[2..], " \t").len != 0) return error.InvalidFile; + } + + // All following lines are expected error messages + while (manifest_it.next()) |line| try errors.append(try gpa.dupe(u8, std.mem.trim(u8, line[2..], " \t"))); + + // The entire file contents is the source, including the manifest + const src = try gpa.dupeZ(u8, contents); + + // Create a new test case, if necessary + case = if (one_test_case_per_file or case == null) blk: { + ctx.cases.append(TestContext.Case{ + .name = if (one_test_case_per_file) case_name else name, + .target = .{}, + .backend = backend, + .updates = std.ArrayList(TestContext.Update).init(ctx.cases.allocator), + .is_test = is_test, + .output_mode = output_mode, + .files = std.ArrayList(TestContext.File).init(ctx.cases.allocator), + }) catch @panic("out of memory"); + break :blk &ctx.cases.items[ctx.cases.items.len - 1]; + } else case.?; + + // Add our update + expected errors + case.?.addError(src, errors.items); + } else { + return error.InvalidFile; // Manifests are currently mandatory + } + } + } + fn init() TestContext { const allocator = std.heap.page_allocator; return .{ .cases = std.ArrayList(Case).init(allocator) }; diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 5008bdd7b8..e0d90e3ee2 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -3,6 +3,42 @@ const builtin = @import("builtin"); const TestContext = @import("../src/test.zig").TestContext; pub fn addCases(ctx: *TestContext) !void { + var parent_dir = try std.fs.cwd().openDir(std.fs.path.dirname(@src().file).?, .{ .no_follow = true }); + defer parent_dir.close(); + + var compile_errors_dir = try parent_dir.openDir("compile_errors", .{ .no_follow = true }); + defer compile_errors_dir.close(); + + { + var stage2_dir = try compile_errors_dir.openDir("stage2", .{ .iterate = true, .no_follow = true }); + defer stage2_dir.close(); + + const one_test_case_per_file = false; + try ctx.addErrorCasesFromDir("stage2 compile errors", stage2_dir, .stage2, .Obj, false, one_test_case_per_file); + } + + { + var stage1_dir = try compile_errors_dir.openDir("stage1", .{ .no_follow = true }); + defer stage1_dir.close(); + { + const one_test_case_per_file = true; + + var obj_dir = try stage1_dir.openDir("obj", .{ .iterate = true, .no_follow = true }); + defer obj_dir.close(); + + try ctx.addErrorCasesFromDir("stage1", obj_dir, .stage1, .Obj, false, one_test_case_per_file); + + var exe_dir = try stage1_dir.openDir("exe", .{ .iterate = true, .no_follow = true }); + defer exe_dir.close(); + + try ctx.addErrorCasesFromDir("stage1", exe_dir, .stage1, .Exe, false, one_test_case_per_file); + + var test_dir = try stage1_dir.openDir("test", .{ .iterate = true, .no_follow = true }); + defer test_dir.close(); + + try ctx.addErrorCasesFromDir("stage1", test_dir, .stage1, .Exe, true, one_test_case_per_file); + } + } { var case = ctx.obj("stage2 compile errors", .{}); From 1de63ad79331aec9f53a7a9d95069fd0ca5f66f4 Mon Sep 17 00:00:00 2001 From: Cody Tapscott Date: Wed, 23 Mar 2022 23:05:33 -0700 Subject: [PATCH 2/3] zig fmt: Add `--exclude` argument to skip dir/file This change adds a "--exclude" parameter to zig format, which can be used to make sure that it does not process certain files or folders when recursively walking a directory. To do this, we simply piggy-back on the existing "seen" logic in zig fmt and mark these files/folders as seen before processing begins. --- ci/zinc/linux_test.sh | 2 +- src/main.zig | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ci/zinc/linux_test.sh b/ci/zinc/linux_test.sh index 9b0734b170..739d85cff0 100755 --- a/ci/zinc/linux_test.sh +++ b/ci/zinc/linux_test.sh @@ -45,7 +45,7 @@ cd $WORKSPACE # Look for non-conforming code formatting. # Formatting errors can be fixed by running `zig fmt` on the files printed here. -$ZIG fmt --check . +$ZIG fmt --check . --exclude test/compile_errors/ # Build stage2 standalone so that we can test stage2 against stage2 compiler-rt. $ZIG build -p stage2 -Denable-llvm -Duse-zig-libcxx diff --git a/src/main.zig b/src/main.zig index 115f3748b6..a647216b05 100644 --- a/src/main.zig +++ b/src/main.zig @@ -3792,6 +3792,7 @@ pub const usage_fmt = \\ --check List non-conforming files and exit with an error \\ if the list is non-empty \\ --ast-check Run zig ast-check on every file + \\ --exclude [file] Exclude file or directory from formatting \\ \\ ; @@ -3815,6 +3816,8 @@ pub fn cmdFmt(gpa: Allocator, arena: Allocator, args: []const []const u8) !void var check_ast_flag: bool = false; var input_files = ArrayList([]const u8).init(gpa); defer input_files.deinit(); + var excluded_files = ArrayList([]const u8).init(gpa); + defer excluded_files.deinit(); { var i: usize = 0; @@ -3840,6 +3843,13 @@ pub fn cmdFmt(gpa: Allocator, arena: Allocator, args: []const []const u8) !void check_flag = true; } else if (mem.eql(u8, arg, "--ast-check")) { check_ast_flag = true; + } else if (mem.eql(u8, arg, "--exclude")) { + if (i + 1 >= args.len) { + fatal("expected parameter after --exclude", .{}); + } + i += 1; + const next_arg = args[i]; + try excluded_files.append(next_arg); } else { fatal("unrecognized parameter: '{s}'", .{arg}); } @@ -3940,6 +3950,16 @@ pub fn cmdFmt(gpa: Allocator, arena: Allocator, args: []const []const u8) !void defer fmt.seen.deinit(); defer fmt.out_buffer.deinit(); + // Mark any excluded files/directories as already seen, + // so that they are skipped later during actual processing + for (excluded_files.items) |file_path| { + var dir = try fs.cwd().openDir(file_path, .{}); + defer dir.close(); + + const stat = try dir.stat(); + try fmt.seen.put(stat.inode, {}); + } + for (input_files.items) |file_path| { try fmtPath(&fmt, file_path, check_flag, fs.cwd(), file_path); } From 0568b4577947f7af2e04cb9e9c95011b0fca88c8 Mon Sep 17 00:00:00 2001 From: Cody Tapscott Date: Wed, 23 Mar 2022 22:28:08 -0700 Subject: [PATCH 3/3] Move existing compile errors to independent files Some cases had to stay behind, either because they required complex case configuration that we don't support in independent files yet, or because they have associated comments which we don't want to lose track of. To make sure I didn't drop any tests in the process, I logged all obj/test/exe test cases from a run of "zig build test" and compared before/after this change. All of the test cases match, with two exceptions: - "use of comptime-known undefined function value" was deleted, since it was a duplicate - "slice sentinel mismatch" was renamed to "vector index out of bounds", since it was incorrectly named --- test/compile_errors.zig | 8573 +---------------- .../stage1/exe/main_missing_name.zig | 5 + .../exe/missing_main_fn_in_executable.zig | 5 + .../stage1/exe/private_main_fn.zig | 6 + .../std.fmt_error_for_unused_arguments.zig | 7 + ..._ABI_compatible_type_or_has_align_attr.zig | 10 + .../stage1/obj/C_pointer_to_anyopaque.zig | 9 + .../stage1/obj/Frame_of_generic_function.zig | 12 + ...nus_for_unsigned_types_a_compile_error.zig | 14 + ...e_6823_dont_allow_._to_be_followed_by_.zig | 8 + ...5_windows_tcp_server_compilation_error.zig | 14 + ...ccess_non-existent_member_of_error_set.zig | 9 + ..._runtime_parameter_from_outer_function.zig | 19 + .../obj/add_assign_on_undefined_value.zig | 8 + .../stage1/obj/add_on_undefined_value.zig | 8 + .../add_overflow_in_function_evaluation.zig | 10 + .../add_wrap_assign_on_undefined_value.zig | 8 + .../obj/add_wrap_on_undefined_value.zig | 8 + .../stage1/obj/addition_with_non_numbers.zig | 10 + .../stage1/obj/address_of_number_literal.zig | 8 + .../alignCast_expects_pointer_or_slice.zig | 7 + .../obj/aligned_variable_of_zero-bit_type.zig | 8 + .../obj/alignment_of_enum_field_specified.zig | 12 + .../stage1/obj/ambiguous_decl_reference.zig | 19 + .../stage1/obj/and_on_undefined_value.zig | 8 + .../stage1/obj/array_access_of_non_array.zig | 13 + .../stage1/obj/array_access_of_type.zig | 8 + .../array_access_of_undeclared_identifier.zig | 7 + .../array_access_with_non_integer_index.zig | 15 + .../array_concatenation_with_wrong_type.zig | 9 + .../obj/array_in_c_exported_function.zig | 12 + .../stage1/obj/asm_at_compile_time.zig | 15 + .../assign_inline_fn_to_non-comptime_var.zig | 10 + .../assign_null_to_non-optional_pointer.zig | 7 + .../obj/assign_through_constant_pointer.zig | 8 + .../obj/assign_through_constant_slice.zig | 8 + .../stage1/obj/assign_to_constant_field.zig | 11 + .../obj/assign_to_constant_variable.zig | 8 + .../obj/assign_to_invalid_dereference.zig | 7 + .../obj/assign_too_big_number_to_u16.zig | 8 + .../stage1/obj/assign_unreachable.zig | 8 + ...th_a_function_that_returns_an_optional.zig | 19 + ...sync_function_depends_on_its_own_frame.zig | 11 + ...on_indirectly_depends_on_its_own_frame.zig | 15 + ...rings_of_atomicStore_Acquire_or_AcqRel.zig | 8 + ..._cmpxchg-failure_stricter_than_success.zig | 9 + ..._cmpxchg-success_Monotonic_or_stricter.zig | 9 + ...orderings_of_fence_Acquire_or_stricter.zig | 7 + .../obj/atomicrmw_with_bool_op_not_.Xchg.zig | 8 + .../obj/atomicrmw_with_enum_op_not_.Xchg.zig | 14 + ...w_with_float_op_not_.Xchg_.Add_or_.Sub.zig | 8 + .../attempt_to_cast_enum_literal_to_error.zig | 9 + ...ver_comptime_variable_from_outer_scope.zig | 12 + .../attempt_to_create_17_bit_float_type.zig | 8 + ...n-integer_non-float_or_non-vector_type.zig | 12 + ...attempt_to_use_0_bit_type_in_extern_fn.zig | 15 + .../stage1/obj/attempted_double_ampersand.zig | 10 + ...ttempted_double_pipe_on_boolean_values.zig | 11 + ..._implicit_cast_from_T_to_slice_const_T.zig | 8 + ...cit_cast_from_const_T_to_array_len_1_T.zig | 12 + ...d_implicit_cast_from_const_T_to_sliceT.zig | 9 + .../stage1/obj/bad_alignCast_at_comptime.zig | 9 + ...licit_cast_from_array_pointer_to_slice.zig | 9 + .../stage1/obj/bad_alignment_type.zig | 13 + ..._function_which_references_local_const.zig | 15 + test/compile_errors/stage1/obj/bad_import.zig | 5 + .../stage1/obj/bad_usage_of_call.zig | 28 + .../obj/bin_and_assign_on_undefined_value.zig | 8 + .../stage1/obj/bin_and_on_undefined_value.zig | 8 + .../stage1/obj/bin_not_on_undefined_value.zig | 8 + .../obj/bin_or_assign_on_undefined_value.zig | 8 + .../stage1/obj/bin_or_on_undefined_value.zig | 8 + .../obj/bin_xor_assign_on_undefined_value.zig | 8 + .../stage1/obj/bin_xor_on_undefined_value.zig | 8 + .../obj/binary_not_on_number_literal.zig | 9 + ...tCast_same_size_but_bit_count_mismatch.zig | 8 + .../stage1/obj/bitCast_to_enum_type.zig | 8 + ...h_different_sizes_inside_an_expression.zig | 8 + ...t_shifting_only_works_on_integer_types.zig | 8 + .../stage1/obj/bogus_compile_var.zig | 6 + .../stage1/obj/bogus_method_call_on_slice.zig | 9 + .../obj/bool_not_on_undefined_value.zig | 8 + .../stage1/obj/branch_on_undefined_value.zig | 7 + .../stage1/obj/cImport_with_bogus_include.zig | 7 + .../stage1/obj/call_assigned_to_constant.zig | 22 + ...generic_function_only_known_at_runtime.zig | 12 + ...function_with_naked_calling_convention.zig | 9 + ...ction_passing_array_instead_of_pointer.zig | 8 + .../cannot_break_out_of_defer_expression.zig | 11 + ...annot_continue_out_of_defer_expression.zig | 11 + ..._prong_with_incompatible_payload_types.zig | 19 + ...um_literal_to_enum_but_it_doesnt_match.zig | 13 + ...et_to_error_union_of_smaller_error_set.zig | 14 + .../cast_global_error_set_to_error_set.zig | 13 + ...cast_negative_integer_literal_to_usize.zig | 8 + ...ast_negative_value_to_unsigned_integer.zig | 15 + .../stage1/obj/cast_unreachable.zig | 9 + ..._bit_offset_pointer_to_regular_pointer.zig | 19 + .../stage1/obj/catch_on_undefined_value.zig | 8 + .../obj/chained_comparison_operators.zig | 7 + .../stage1/obj/cmpxchg_with_float.zig | 8 + .../colliding_invalid_top_level_functions.zig | 8 + ...nal_to_non-optional_with_invalid_types.zig | 33 + ...ng_a_non-optional_pointer_against_null.zig | 8 + ...nst_undefined_produces_undefined_value.zig | 7 + ...parison_operators_with_undefined_value.zig | 45 + ...rison_with_error_union_and_error_value.zig | 8 + .../obj/compile-time_division_by_zero.zig | 10 + ...ompile-time_remainder_division_by_zero.zig | 10 + ...traceback_of_references_that_caused_it.zig | 12 + ..._tagged_enum_doesnt_crash_the_compiler.zig | 15 + ...ompile_error_in_struct_init_expression.zig | 14 + ...ting_return_type_of_inferred_error_set.zig | 12 + .../compile_errors/stage1/obj/compile_log.zig | 14 + ...mpile_log_a_pointer_to_an_opaque_value.zig | 7 + ...ction_which_must_be_comptime_evaluated.zig | 12 + ...nt_warning_deduplication_in_generic_fn.zig | 12 + .../obj/compile_time_division_by_zero.zig | 10 + ...st_enum_to_union_but_field_has_payload.zig | 15 + ...comptime_continue_inside_runtime_catch.zig | 14 + ...mptime_continue_inside_runtime_if_bool.zig | 13 + ...ptime_continue_inside_runtime_if_error.zig | 13 + ...me_continue_inside_runtime_if_optional.zig | 13 + ...omptime_continue_inside_runtime_switch.zig | 16 + ...ime_continue_inside_runtime_while_bool.zig | 13 + ...me_continue_inside_runtime_while_error.zig | 15 + ...continue_inside_runtime_while_optional.zig | 13 + .../obj/comptime_float_in_asm_input.zig | 7 + .../obj/comptime_implicit_cast_f64_to_f32.zig | 9 + .../stage1/obj/comptime_int_in_asm_input.zig | 7 + .../comptime_ptrcast_of_zero-sized_type.zig | 10 + ...atch_memory_at_target_index_terminated.zig | 65 + ...ch_memory_at_target_index_unterminated.zig | 65 + ...entinel_does_not_match_target-sentinel.zig | 65 + ...e-sentinel_is_out_of_bounds_terminated.zig | 65 + ...sentinel_is_out_of_bounds_unterminated.zig | 65 + .../comptime_slice_of_an_undefined_slice.zig | 9 + ...lice_of_undefined_pointer_non-zero_len.zig | 8 + .../comptime_struct_field_no_init_value.zig | 11 + .../obj/const_frame_cast_to_anyframe.zig | 17 + ...const_is_a_statement_not_an_expression.zig | 7 + ...de_comptime_function_has_compile_error.zig | 19 + .../obj/container_init_with_non-type.zig | 8 + ...trol_flow_uses_comptime_var_at_runtime.zig | 13 + ...ntrol_reaches_end_of_non-void_function.zig | 6 + .../stage1/obj/declaration_between_fields.zig | 22 + ...e_as_primitive_must_use_special_syntax.zig | 10 + .../obj/deduplicate_undeclared_identifier.zig | 10 + .../stage1/obj/deref_on_undefined_value.zig | 8 + .../obj/deref_slice_and_get_len_field.zig | 8 + .../stage1/obj/dereference_an_array.zig | 12 + .../dereference_unknown_length_pointer.zig | 7 + .../stage1/obj/direct_struct_loop.zig | 6 + ...edding_opaque_type_in_struct_and_union.zig | 27 + ...ted_pointer_to_null-terminated_pointer.zig | 10 + .../stage1/obj/discarding_error_value.zig | 10 + .../obj/div_assign_on_undefined_value.zig | 8 + .../stage1/obj/div_on_undefined_value.zig | 8 + .../stage1/obj/division_by_zero.zig | 16 + ...licit_cast_double_pointer_to_anyopaque.zig | 11 + .../double_optional_on_main_return_value.zig | 6 + .../obj/duplicate_boolean_switch_value.zig | 21 + .../stage1/obj/duplicate_enum_field.zig | 14 + .../stage1/obj/duplicate_error_in_switch.zig | 20 + .../duplicate_error_value_in_error_set.zig | 13 + ...icate_field_in_struct_value_expression.zig | 18 + .../stage1/obj/duplicate_struct_field.zig | 13 + .../stage1/obj/duplicate_union_field.zig | 13 + .../stage1/obj/embedFile_with_bogus_file.zig | 7 + .../stage1/obj/empty_for_loop_body.zig | 7 + .../stage1/obj/empty_if_body.zig | 7 + .../stage1/obj/empty_switch_on_an_integer.zig | 8 + .../stage1/obj/empty_while_loop_body.zig | 7 + .../endless_loop_in_function_evaluation.zig | 10 + .../obj/enum_field_value_references_enum.zig | 13 + ...field_count_range_but_not_matching_tag.zig | 13 + .../stage1/obj/enum_value_already_taken.zig | 16 + .../stage1/obj/enum_with_0_fields.zig | 5 + ...eclarations_unavailable_for_reify_type.zig | 7 + ...uality_but_sets_have_no_common_members.zig | 14 + .../obj/error_not_handled_in_switch.zig | 18 + ...for_function_parameter_incompatibility.zig | 10 + ..._union_operator_with_non_error_set_LHS.zig | 9 + .../obj/error_when_evaluating_return_type.zig | 15 + .../exceeded_maximum_bit_width_of_integer.zig | 13 + ...ger_when_there_is_a_fraction_component.zig | 7 + ..._known_at_comptime_violates_error_sets.zig | 11 + ...xplicitly_casting_non_tag_type_to_enum.zig | 16 + ...xport_function_with_comptime_parameter.zig | 7 + .../stage1/obj/export_generic_function.zig | 8 + .../stage1/obj/exported_async_function.zig | 5 + ...enum_without_explicit_integer_tag_type.zig | 13 + .../obj/extern_function_pointer_mismatch.zig | 10 + ...xtern_function_with_comptime_parameter.zig | 9 + ...mpatible_but_inferred_integer_tag_type.zig | 41 + ...non-extern-compatible_integer_tag_type.zig | 12 + .../obj/extern_union_field_missing_type.zig | 11 + .../obj/extern_union_given_enum_tag_type.zig | 18 + .../obj/extern_variable_has_no_type.zig | 8 + .../obj/fieldParentPtr-bad_field_name.zig | 10 + ...comptime_field_ptr_not_based_on_struct.zig | 15 + ...ldParentPtr-comptime_wrong_field_index.zig | 14 + ...ParentPtr-field_pointer_is_not_pointer.zig | 10 + .../stage1/obj/fieldParentPtr-non_struct.zig | 8 + .../obj/field_access_of_opaque_type.zig | 14 + .../stage1/obj/field_access_of_slices.zig | 9 + ...field_access_of_unknown_length_pointer.zig | 11 + .../obj/field_type_supplied_in_an_enum.zig | 10 + .../stage1/obj/floatToInt_comptime_safety.zig | 15 + .../obj/float_literal_too_large_error.zig | 8 + ...float_literal_too_small_error_denormal.zig | 8 + .../obj/for_loop_body_expression_ignored.zig | 16 + ..._called_outside_of_function_definition.zig | 9 + .../obj/frame_causes_function_to_be_async.zig | 11 + .../obj/function_alignment_non_power_of_2.zig | 6 + ...nction_call_assigned_to_incorrect_type.zig | 11 + .../obj/function_parameter_is_opaque.zig | 27 + .../obj/function_prototype_with_no_body.zig | 8 + .../obj/function_returning_opaque_type.zig | 17 + ..._ccc_indirectly_calling_async_function.zig | 16 + .../obj/function_with_invalid_return_type.zig | 5 + ...h_non-extern_non-packed_enum_parameter.zig | 6 + ...non-extern_non-packed_struct_parameter.zig | 10 + ..._non-extern_non-packed_union_parameter.zig | 10 + ..._as_parameter_without_comptime_keyword.zig | 9 + ...nction_call_assigned_to_incorrect_type.zig | 11 + ..._instance_with_non-constant_expression.zig | 10 + ...generic_function_returning_opaque_type.zig | 23 + ...n_where_return_type_is_self-referenced.zig | 13 + ...obal_variable_alignment_non_power_of_2.zig | 6 + ...nitializer_must_be_constant_expression.zig | 7 + .../stage1/obj/hasDecl_with_non-container.zig | 7 + .../obj/if_condition_is_bool_not_int.zig | 7 + .../ignored_assert-err-ok_return_value.zig | 8 + .../obj/ignored_comptime_statement_value.zig | 7 + .../stage1/obj/ignored_comptime_value.zig | 7 + .../obj/ignored_deferred_function_call.zig | 8 + .../obj/ignored_deferred_statement_value.zig | 7 + ...nored_expression_in_while_continuation.zig | 20 + .../stage1/obj/ignored_return_value.zig | 8 + .../stage1/obj/ignored_statement_value.zig | 7 + .../obj/illegal_comparison_of_types.zig | 18 + ..._and_Zig_pointer-bad_const-align-child.zig | 40 + ...icit_cast_const_array_to_mutable_slice.zig | 10 + ...licit_cast_from_array_to_mutable_slice.zig | 9 + .../obj/implicit_cast_from_f64_to_f32.zig | 8 + ...mplicit_cast_of_error_set_not_a_subset.zig | 14 + ...ers_which_would_mess_up_null_semantics.zig | 24 + ..._casting_null_c_pointer_to_zig_pointer.zig | 9 + ...casting_too_big_integers_to_C_pointers.zig | 14 + ...ing_undefined_c_pointer_to_zig_pointer.zig | 9 + .../obj/implicit_semicolon-block_expr.zig | 10 + .../implicit_semicolon-block_statement.zig | 10 + ...implicit_semicolon-comptime_expression.zig | 10 + .../implicit_semicolon-comptime_statement.zig | 10 + .../stage1/obj/implicit_semicolon-defer.zig | 10 + .../obj/implicit_semicolon-for_expression.zig | 10 + .../obj/implicit_semicolon-for_statement.zig | 10 + ...t_semicolon-if-else-if-else_expression.zig | 10 + ...it_semicolon-if-else-if-else_statement.zig | 10 + ...plicit_semicolon-if-else-if_expression.zig | 10 + ...mplicit_semicolon-if-else-if_statement.zig | 10 + .../implicit_semicolon-if-else_expression.zig | 10 + .../implicit_semicolon-if-else_statement.zig | 10 + .../obj/implicit_semicolon-if_expression.zig | 10 + .../obj/implicit_semicolon-if_statement.zig | 10 + .../implicit_semicolon-test_expression.zig | 10 + .../obj/implicit_semicolon-test_statement.zig | 10 + ...it_semicolon-while-continue_expression.zig | 10 + ...cit_semicolon-while-continue_statement.zig | 10 + .../implicit_semicolon-while_expression.zig | 10 + .../implicit_semicolon-while_statement.zig | 10 + .../implicitly_casting_enum_to_tag_type.zig | 15 + ...mplicitly_increasing_pointer_alignment.zig | 17 + .../implicitly_increasing_slice_alignment.zig | 20 + .../obj/import_outside_package_path.zig | 7 + .../stage1/obj/incorrect_return_type.zig | 19 + .../increase_pointer_alignment_in_ptrCast.zig | 11 + ...indexing_a_undefined_slice_at_comptime.zig | 8 + .../obj/indexing_an_array_of_size_zero.zig | 9 + ..._array_of_size_zero_with_runtime_index.zig | 10 + .../obj/indexing_single-item_pointer.zig | 7 + ..._recursion_of_async_functions_detected.zig | 34 + .../stage1/obj/indirect_struct_loop.zig | 8 + .../obj/inferred_array_size_invalid_here.zig | 14 + ...nferring_error_set_of_function_pointer.zig | 7 + .../initializing_array_with_struct_syntax.zig | 8 + ...an_invalid_struct_that_contains_itself.zig | 13 + .../obj/intToPtr_with_misaligned_address.zig | 8 + .../obj/int_to_err_global_invalid_number.zig | 13 + .../int_to_err_non_global_invalid_number.zig | 17 + .../stage1/obj/int_to_ptr_of_0_bits.zig | 9 + .../obj/integer_cast_truncates_bits.zig | 29 + .../stage1/obj/integer_overflow_error.zig | 6 + .../stage1/obj/integer_underflow_error.zig | 7 + .../stage1/obj/invalid_break_expression.zig | 7 + .../stage1/obj/invalid_builtin_fn.zig | 7 + ...nvalid_cast_from_integral_type_to_enum.zig | 15 + ...valid_comparison_for_function_pointers.zig | 8 + .../obj/invalid_continue_expression.zig | 7 + .../obj/invalid_deref_on_switch_target.zig | 15 + .../obj/invalid_empty_unicode_escape.zig | 7 + .../invalid_exponent_in_float_literal-1.zig | 9 + .../invalid_exponent_in_float_literal-2.zig | 9 + .../obj/invalid_field_access_in_comptime.zig | 5 + ...valid_field_in_struct_value_expression.zig | 17 + .../stage1/obj/invalid_float_literal.zig | 11 + .../obj/invalid_legacy_unicode_escape.zig | 8 + .../stage1/obj/invalid_maybe_type.zig | 7 + .../obj/invalid_member_of_builtin_enum.zig | 9 + .../obj/invalid_multiple_dereferences.zig | 17 + ...invalid_optional_type_in_extern_struct.zig | 8 + .../obj/invalid_pointer_for_var_type.zig | 11 + .../stage1/obj/invalid_pointer_syntax.zig | 7 + .../stage1/obj/invalid_shift_amount_error.zig | 9 + .../stage1/obj/invalid_struct_field.zig | 17 + .../invalid_suspend_in_exported_function.zig | 13 + .../stage1/obj/invalid_type.zig | 6 + .../obj/invalid_type_used_in_array_type.zig | 12 + ...nderscore_placement_in_float_literal-1.zig | 9 + ...derscore_placement_in_float_literal-10.zig | 9 + ...derscore_placement_in_float_literal-11.zig | 9 + ...derscore_placement_in_float_literal-12.zig | 9 + ...derscore_placement_in_float_literal-13.zig | 9 + ...derscore_placement_in_float_literal-14.zig | 9 + ...nderscore_placement_in_float_literal-2.zig | 9 + ...nderscore_placement_in_float_literal-3.zig | 9 + ...nderscore_placement_in_float_literal-4.zig | 9 + ...nderscore_placement_in_float_literal-5.zig | 9 + ...nderscore_placement_in_float_literal-6.zig | 9 + ...nderscore_placement_in_float_literal-7.zig | 9 + ...nderscore_placement_in_float_literal-9.zig | 9 + ..._underscore_placement_in_int_literal-1.zig | 9 + ..._underscore_placement_in_int_literal-2.zig | 9 + ..._underscore_placement_in_int_literal-3.zig | 9 + ..._underscore_placement_in_int_literal-4.zig | 9 + ...invalid_union_field_access_in_comptime.zig | 13 + ...gnostic_string_for_top_level_decl_type.zig | 8 + ..._from_undefined_array_pointer_to_slice.zig | 25 + ..._3818_bitcast_from_parray-slice_to_u16.zig | 15 + ...terminated-slice_to_terminated-pointer.zig | 9 + ...d_by_typeInfo_and_passed_into_function.zig | 14 + ...ional_anyopaque_to_anyopaque_must_fail.zig | 9 + ...time_slice-len_increment_beyond_bounds.zig | 12 + ..._9346_return_outside_of_function_scope.zig | 5 + .../stage1/obj/labeled_break_not_found.zig | 11 + .../stage1/obj/labeled_continue_not_found.zig | 12 + ...zy_pointer_with_undefined_element_type.zig | 10 + ...es_from_comptime_reinterpreted_pointer.zig | 11 + ...tor_pointer_with_unknown_runtime_index.zig | 15 + ...local_shadows_global_that_occurs_later.zig | 10 + .../obj/local_variable_redeclaration.zig | 9 + .../local_variable_redeclares_parameter.zig | 9 + .../obj/local_variable_shadowing_global.zig | 12 + .../locally_shadowing_a_primitive_type.zig | 10 + .../main_function_with_bogus_args_type.zig | 5 + ...hod_call_with_first_arg_type_primitive.zig | 19 + ...ll_with_first_arg_type_wrong_container.zig | 28 + .../obj/missing_boolean_switch_value.zig | 17 + ..._const_in_slice_with_nested_array_type.zig | 16 + .../stage1/obj/missing_else_clause.zig | 14 + ...ssing_field_in_struct_value_expression.zig | 18 + .../obj/missing_function_call_param.zig | 29 + .../stage1/obj/missing_function_name.zig | 6 + .../stage1/obj/missing_param_name.zig | 6 + ...ing_parameter_name_of_generic_function.zig | 9 + .../obj/missing_result_type_for_phi_node.zig | 10 + ...elled_type_with_pointer_only_reference.zig | 35 + .../obj/mod_assign_on_undefined_value.zig | 8 + .../stage1/obj/mod_on_undefined_value.zig | 8 + .../mul_overflow_in_function_evaluation.zig | 10 + .../obj/mult_assign_on_undefined_value.zig | 8 + .../stage1/obj/mult_on_undefined_value.zig | 8 + .../mult_wrap_assign_on_undefined_value.zig | 8 + .../obj/mult_wrap_on_undefined_value.zig | 8 + .../obj/multiple_function_definitions.zig | 8 + .../stage1/obj/negate_on_undefined_value.zig | 8 + .../obj/negate_wrap_on_undefined_value.zig | 8 + ...gation_overflow_in_function_evaluation.zig | 10 + .../stage1/obj/nested_error_set_mismatch.zig | 18 + ...se_prong_on_switch_on_global_error_set.zig | 12 + .../obj/noalias_on_non_pointer_param.zig | 6 + ...eventually_is_inferred_to_become_async.zig | 13 + ...h_struct_return_value_outside_function.zig | 15 + ...ion_in_struct_literal_outside_function.zig | 11 + .../obj/non-const_switch_number_literal.zig | 15 + ...of_things_that_require_const_variables.zig | 49 + .../obj/non-enum_tag_type_passed_to_union.zig | 11 + .../obj/non-extern_function_with_var_args.zig | 8 + ..._loop_on_a_type_that_requires_comptime.zig | 12 + ...teger_tag_type_to_automatic_union_enum.zig | 11 + .../obj/non-pure_function_returns_type.zig | 22 + ...c_function_pointer_passed_to_asyncCall.zig | 10 + .../non_compile_time_array_concatenation.zig | 9 + .../non_constant_expression_in_array_size.zig | 12 + ...sets_used_in_merge_error_sets_operator.zig | 15 + .../obj/non_float_passed_to_floatToInt.zig | 8 + .../obj/non_int_passed_to_intToFloat.zig | 8 + .../obj/non_pointer_given_to_ptrToInt.zig | 7 + .../stage1/obj/normal_string_with_newline.zig | 7 + .../stage1/obj/offsetOf-bad_field_name.zig | 10 + .../stage1/obj/offsetOf-non_struct.zig | 8 + ...binary_operator_allowed_for_error_sets.zig | 8 + .../stage1/obj/opaque_type_with_field.zig | 9 + ...ional_pointer_to_void_in_extern_struct.zig | 12 + .../stage1/obj/or_on_undefined_value.zig | 8 + .../stage1/obj/orelse_on_undefined_value.zig | 8 + ...ange_comptime_int_passed_to_floatToInt.zig | 8 + .../obj/overflow_in_enum_value_allocation.zig | 12 + .../obj/packed_union_given_enum_tag_type.zig | 18 + ...cked_union_with_automatic_layout_field.zig | 16 + .../obj/panic_called_at_compile_time.zig | 9 + .../stage1/obj/parameter_redeclaration.zig | 8 + .../stage1/obj/parameter_shadowing_global.zig | 10 + .../obj/pass_const_ptr_to_mutable_ptr_fn.zig | 15 + ..._not-aligned-enough_pointer_to_cmpxchg.zig | 10 + ...sing_an_under-aligned_function_pointer.zig | 11 + ...ast_const_pointer_to_mutable_C_pointer.zig | 9 + ...pointer_arithmetic_on_pointer-to-array.zig | 10 + ..._when_coercing_pointer_to_anon_literal.zig | 22 + .../stage1/obj/pointer_to_noreturn.zig | 6 + .../stage1/obj/popCount-non-integer.zig | 7 + ...bad_implicit_casting_of_anyframe_types.zig | 22 + ...ives_take_precedence_over_declarations.zig | 9 + ...Cast_a_0_bit_type_to_a_non-_0_bit_type.zig | 11 + .../obj/ptrCast_discards_const_qualifier.zig | 9 + .../ptrToInt_0_to_non_optional_pointer.zig | 8 + .../stage1/obj/ptrToInt_on_void.zig | 7 + .../stage1/obj/ptrcast_to_non-pointer.zig | 7 + ...e_operator_in_switch_used_on_error_set.zig | 17 + ...ading_past_end_of_pointer_casted_array.zig | 11 + .../obj/recursive_inferred_error_set.zig | 10 + .../stage1/obj/redefinition_of_enums.zig | 7 + .../obj/redefinition_of_global_variables.zig | 7 + .../stage1/obj/redefinition_of_struct.zig | 7 + ...efer_to_the_type_of_a_generic_function.zig | 9 + .../referring_to_a_struct_that_is_invalid.zig | 15 + ...when_assigning_a_value_within_a_struct.zig | 19 + .../reify_type.Fn_with_is_generic_true.zig | 15 + ...th_is_var_args_true_and_non-C_callconv.zig | 15 + .../reify_type.Fn_with_return_type_null.zig | 15 + ...ype.Pointer_with_invalid_address_space.zig | 16 + ...austive_enum_with_non-integer_tag_type.zig | 16 + ...xhaustive_enum_with_undefined_tag_type.zig | 16 + ...e_for_exhaustive_enum_with_zero_fields.zig | 16 + ...for_tagged_union_with_extra_enum_field.zig | 32 + ...or_tagged_union_with_extra_union_field.zig | 33 + ...reify_type_for_union_with_opaque_field.zig | 17 + .../reify_type_for_union_with_zero_fields.zig | 15 + .../reify_type_union_payload_is_undefined.zig | 8 + .../stage1/obj/reify_type_with_Type.Int.zig | 11 + ...eify_type_with_non-constant_expression.zig | 9 + .../stage1/obj/reify_type_with_undefined.zig | 18 + ...ompatibility_mismatching_handle_is_ptr.zig | 16 + ...mismatching_handle_is_ptr_generic_call.zig | 16 + .../obj/return_from_defer_expression.zig | 19 + ...turning_error_from_void_async_function.zig | 10 + .../runtime-known_async_function_called.zig | 12 + ...own_function_called_with_async_keyword.zig | 10 + ...ime_assignment_to_comptime_struct_type.zig | 13 + ...time_assignment_to_comptime_union_type.zig | 13 + ...ast_to_union_which_has_non-void_fields.zig | 18 + ...runtime_index_into_comptime_type_slice.zig | 15 + ...ating_arithmetic_does_not_allow_floats.zig | 7 + ...oes_not_allow_negative_rhs_at_comptime.zig | 10 + ...oes_not_allow_negative_rhs_at_comptime.zig | 7 + .../obj/setAlignStack_in_inline_function.zig | 10 + .../obj/setAlignStack_in_naked_function.zig | 7 + .../obj/setAlignStack_outside_function.zig | 7 + .../stage1/obj/setAlignStack_set_twice.zig | 9 + .../stage1/obj/setAlignStack_too_big.zig | 7 + .../obj/setFloatMode_twice_for_same_scope.zig | 9 + .../setRuntimeSafety_twice_for_same_scope.zig | 9 + .../setting_a_section_on_a_local_variable.zig | 8 + ...shift_amount_has_to_be_an_integer_type.zig | 8 + .../shift_by_negative_comptime_integer.zig | 8 + .../shift_left_assign_on_undefined_value.zig | 8 + .../obj/shift_left_on_undefined_value.zig | 8 + .../shift_right_assign_on_undefined_value.zig | 8 + .../obj/shift_right_on_undefined_value.zig | 8 + ...fting_RHS_is_log2_of_LHS_int_bit_width.zig | 7 + ...ing_without_int_type_or_comptime_known.zig | 7 + .../stage1/obj/shlExact_shifts_out_1_bits.zig | 8 + .../stage1/obj/shrExact_shifts_out_1_bits.zig | 8 + .../stage1/obj/signed_integer_division.zig | 7 + .../obj/signed_integer_remainder_division.zig | 7 + .../stage1/obj/sizeOf_bad_type.zig | 7 + ...ce_cannot_have_its_bytes_reinterpreted.zig | 9 + .../obj/slice_passed_as_array_init_type.zig | 8 + ...e_passed_as_array_init_type_with_elems.zig | 8 + .../stage1/obj/slice_sentinel_mismatch-1.zig | 8 + .../stage1/obj/slice_sentinel_mismatch-2.zig | 10 + .../slicing_of_global_undefined_pointer.zig | 8 + .../obj/slicing_single-item_pointer.zig | 8 + ...pecify_enum_tag_type_that_is_too_small.zig | 16 + .../obj/specify_non-integer_enum_tag_type.zig | 14 + .../stage1/obj/src_outside_function.zig | 7 + ...tor_pointer_with_unknown_runtime_index.zig | 14 + ...in_compile_time_variable_then_using_it.zig | 47 + ...t_depends_on_itself_via_optional_field.zig | 17 + .../stage1/obj/struct_field_missing_type.zig | 11 + .../obj/struct_init_syntax_for_array.zig | 8 + ...eclarations_unavailable_for_reify_type.zig | 7 + .../stage1/obj/struct_with_invalid_field.zig | 28 + .../obj/sub_assign_on_undefined_value.zig | 8 + .../stage1/obj/sub_on_undefined_value.zig | 8 + .../sub_overflow_in_function_evaluation.zig | 10 + .../sub_wrap_assign_on_undefined_value.zig | 8 + .../obj/sub_wrap_on_undefined_value.zig | 8 + .../obj/suspend_inside_suspend_block.zig | 14 + ...expression-duplicate_enumeration_prong.zig | 22 + ...te_enumeration_prong_when_else_present.zig | 23 + ...duplicate_or_overlapping_integer_value.zig | 14 + .../obj/switch_expression-duplicate_type.zig | 15 + ...expression-duplicate_type_struct_alias.zig | 19 + ...h_expression-missing_enumeration_prong.zig | 19 + ...switch_expression-multiple_else_prongs.zig | 14 + ...pression-non_exhaustive_integer_prongs.zig | 10 + ...on-switch_on_pointer_type_with_no_else.zig | 11 + ...expression-unreachable_else_prong_bool.zig | 12 + ...expression-unreachable_else_prong_enum.zig | 22 + ...ession-unreachable_else_prong_range_i8.zig | 15 + ...ession-unreachable_else_prong_range_u8.zig | 15 + ...h_expression-unreachable_else_prong_u1.zig | 12 + ...h_expression-unreachable_else_prong_u2.zig | 14 + ...ch_on_enum_with_1_field_with_no_prongs.zig | 10 + .../switch_on_union_with_no_attached_enum.zig | 20 + ...itch_with_invalid_expression_parameter.zig | 15 + .../switch_with_overlapping_case_ranges.zig | 11 + ...d_on_union_with_no_associated_enum_tag.zig | 14 + .../obj/take_slice_of_invalid_dereference.zig | 8 + ...ing_bit_offset_of_void_field_in_struct.zig | 11 + ...ng_byte_offset_of_void_field_in_struct.zig | 11 + .../obj/threadlocal_qualifier_on_const.zig | 8 + .../obj/top_level_decl_dependency_loop.zig | 10 + .../stage1/obj/truncate_sign_mismatch.zig | 23 + .../stage1/obj/truncate_undefined_value.zig | 8 + ...in_function_with_non_error_return_type.zig | 8 + .../obj/type_checking_function_pointers.zig | 11 + .../obj/type_variables_must_be_constant.zig | 8 + .../stage1/obj/undeclared_identifier.zig | 9 + ...ntifier_error_should_mark_fn_as_impure.zig | 10 + ...clared_identifier_in_unanalyzed_branch.zig | 9 + .../undefined_as_field_type_is_rejected.zig | 11 + .../stage1/obj/undefined_function_call.zig | 7 + .../underscore_is_not_a_declarable_symbol.zig | 8 + ...rscore_should_not_be_usable_inside_for.zig | 11 + ...core_should_not_be_usable_inside_while.zig | 14 + ...should_not_be_usable_inside_while_else.zig | 16 + .../union_auto-enum_value_already_taken.zig | 16 + .../union_enum_field_does_not_match_enum.zig | 20 + .../union_fields_with_value_assignments.zig | 12 + .../stage1/obj/union_with_0_fields.zig | 5 + .../union_with_specified_enum_omits_field.zig | 17 + ...ith_too_small_explicit_signed_tag_type.zig | 14 + ...h_too_small_explicit_unsigned_tag_type.zig | 15 + .../obj/unknown_length_pointer_to_opaque.zig | 5 + .../obj/unreachable_code-double_break.zig | 10 + .../obj/unreachable_code-nested_returns.zig | 8 + .../stage1/obj/unreachable_code.zig | 11 + .../obj/unreachable_executed_at_comptime.zig | 14 + .../stage1/obj/unreachable_parameter.zig | 6 + .../stage1/obj/unreachable_variable.zig | 8 + .../stage1/obj/unreachable_with_return.zig | 6 + ...fier_at_start_of_asm_output_constraint.zig | 8 + ...use_anyopaque_as_return_type_of_fn_ptr.zig | 8 + ...to_assign_null_to_non-nullable_pointer.zig | 12 + ..._invalid_number_literal_as_array_index.zig | 9 + ...omptime-known_undefined_function_value.zig | 11 + .../obj/use_of_undeclared_identifier.zig | 7 + ..._unknown_len_ptr_type_instead_of_array.zig | 11 + ...types_in_function_call_raises_an_error.zig | 9 + .../obj/usingnamespace_with_wrong_type.zig | 5 + .../stage1/obj/variable_has_wrong_type.zig | 8 + ...lization_compile_error_then_referenced.zig | 17 + .../obj/variable_with_type_noreturn.zig | 8 + .../stage1/obj/vector_index_out_of_bounds.zig | 8 + .../obj/volatile_on_global_assembly.zig | 7 + ...is_a_compile_error_in_non-Wasm_targets.zig | 8 + ...is_a_compile_error_in_non-Wasm_targets.zig | 8 + .../while_expected_bool_got_error_union.zig | 8 + .../obj/while_expected_bool_got_optional.zig | 8 + .../while_expected_error_union_got_bool.zig | 8 + ...hile_expected_error_union_got_optional.zig | 8 + .../obj/while_expected_optional_got_bool.zig | 8 + ...hile_expected_optional_got_error_union.zig | 8 + .../while_loop_body_expression_ignored.zig | 20 + .../obj/write_to_const_global_variable.zig | 9 + .../wrong_frame_type_used_for_async_call.zig | 14 + .../stage1/obj/wrong_function_type.zig | 9 + ...ializer_for_union_payload_of_type_type.zig | 14 + .../stage1/obj/wrong_number_of_arguments.zig | 8 + ...number_of_arguments_for_method_fn_call.zig | 12 + ...wrong_panic_signature_generic_function.zig | 10 + ...wrong_panic_signature_runtime_function.zig | 8 + ...ointer_coerced_to_pointer_to_opaque_{}.zig | 10 + .../stage1/obj/wrong_return_type_for_main.zig | 5 + .../obj/wrong_size_to_an_array_literal.zig | 8 + ...g_type_for_argument_tuple_to_asyncCall.zig | 12 + .../stage1/obj/wrong_type_for_reify_type.zig | 7 + ...wrong_type_for_result_ptr_to_asyncCall.zig | 14 + .../stage1/obj/wrong_type_passed_to_panic.zig | 8 + .../stage1/obj/wrong_type_to_hasField.zig | 7 + ..._given_to_atomic_order_args_in_cmpxchg.zig | 8 + .../obj/wrong_types_given_to_export.zig | 8 + .../test/access_invalid_typeInfo_decl.zig | 8 + .../test/alignCast_of_zero_sized_types.zig | 25 + .../stage1/test/bad_splat_type.zig | 9 + .../test/binary_OR_operator_on_error_sets.zig | 10 + ...ts_non_comptime-known_fn-always_inline.zig | 8 + ...cts_non_comptime-known_fn-compile_time.zig | 8 + ...en_optional_T_where_T_is_not_a_pointer.zig | 12 + .../combination_of_nosuspend_and_async.zig | 13 + ...n_of_non-tagged_union_and_enum_literal.zig | 11 + ...mptime_vector_overflow_shows_the_index.zig | 11 + .../stage1/test/duplicate-unused_labels.zig | 30 + ...cate_field_in_anonymous_struct_literal.zig | 16 + ..._initializer_doesnt_crash_the_compiler.zig | 12 + ...rors_in_for_loop_bodies_are_propagated.zig | 8 + .../test/export_with_empty_name_string.zig | 8 + .../helpful_return_type_error_message.zig | 27 + ...float_conversion_to_comptime_int-float.zig | 13 + .../stage1/test/invalid_assignments.zig | 17 + .../stage1/test/invalid_float_casts.zig | 23 + .../stage1/test/invalid_int_casts.zig | 23 + .../invalid_non-exhaustive_enum_to_union.zig | 24 + .../test/invalid_pointer_with_reify_type.zig | 16 + .../stage1/test/nested_vectors.zig | 10 + ...xhaustive_enum_marker_assigned_a_value.zig | 17 + .../stage1/test/non-exhaustive_enums.zig | 19 + .../stage1/test/not_an_enum_type.zig | 17 + ...truct_with_fields_of_not_allowed_types.zig | 71 + ...rToInt_with_pointer_to_zero-sized_type.zig | 9 + .../test/reassign_to_array_parameter.zig | 10 + .../test/reassign_to_slice_parameter.zig | 10 + .../test/reassign_to_struct_parameter.zig | 13 + .../stage1/test/reference_to_const_data.zig | 27 + ...ify_typeOf_with_incompatible_arguments.zig | 9 + .../test/reify_typeOf_with_no_arguments.zig | 7 + ..._extern_function_definitions_with_body.zig | 7 + ...ect_extern_variables_with_initializers.zig | 5 + ...n_returning_type_crashes_compiler_2655.zig | 11 + .../test/return_invalid_type_from_test.zig | 5 + ...ift_on_type_with_non-power-of-two_size.zig | 31 + ...elected_index_past_first_vector_length.zig | 12 + .../switch_ranges_endpoints_are_validated.zig | 13 + ...hing_with_exhaustive_enum_has___prong_.zig | 16 + .../switching_with_non-exhaustive_enums.zig | 32 + ...n_invalid_value_of_non-exhaustive_enum.zig | 8 + ...e_mismatch_in_C_prototype_with_varargs.zig | 11 + ...type_mismatch_with_tuple_concatenation.zig | 8 + .../unused_variable_error_on_errdefer.zig | 11 + .../stage2/embed_outside_package.zig | 7 + .../stage2/import_outside_package.zig | 7 + .../stage2/out_of_bounds_index.zig | 28 + 655 files changed, 7896 insertions(+), 8563 deletions(-) create mode 100644 test/compile_errors/stage1/exe/main_missing_name.zig create mode 100644 test/compile_errors/stage1/exe/missing_main_fn_in_executable.zig create mode 100644 test/compile_errors/stage1/exe/private_main_fn.zig create mode 100644 test/compile_errors/stage1/exe/std.fmt_error_for_unused_arguments.zig create mode 100644 test/compile_errors/stage1/obj/C_pointer_pointing_to_non_C_ABI_compatible_type_or_has_align_attr.zig create mode 100644 test/compile_errors/stage1/obj/C_pointer_to_anyopaque.zig create mode 100644 test/compile_errors/stage1/obj/Frame_of_generic_function.zig create mode 100644 test/compile_errors/stage1/obj/Issue_5586_Make_unary_minus_for_unsigned_types_a_compile_error.zig create mode 100644 test/compile_errors/stage1/obj/Issue_6823_dont_allow_._to_be_followed_by_.zig create mode 100644 test/compile_errors/stage1/obj/Issue_9165_windows_tcp_server_compilation_error.zig create mode 100644 test/compile_errors/stage1/obj/access_non-existent_member_of_error_set.zig create mode 100644 test/compile_errors/stage1/obj/accessing_runtime_parameter_from_outer_function.zig create mode 100644 test/compile_errors/stage1/obj/add_assign_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/add_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/add_overflow_in_function_evaluation.zig create mode 100644 test/compile_errors/stage1/obj/add_wrap_assign_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/add_wrap_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/addition_with_non_numbers.zig create mode 100644 test/compile_errors/stage1/obj/address_of_number_literal.zig create mode 100644 test/compile_errors/stage1/obj/alignCast_expects_pointer_or_slice.zig create mode 100644 test/compile_errors/stage1/obj/aligned_variable_of_zero-bit_type.zig create mode 100644 test/compile_errors/stage1/obj/alignment_of_enum_field_specified.zig create mode 100644 test/compile_errors/stage1/obj/ambiguous_decl_reference.zig create mode 100644 test/compile_errors/stage1/obj/and_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/array_access_of_non_array.zig create mode 100644 test/compile_errors/stage1/obj/array_access_of_type.zig create mode 100644 test/compile_errors/stage1/obj/array_access_of_undeclared_identifier.zig create mode 100644 test/compile_errors/stage1/obj/array_access_with_non_integer_index.zig create mode 100644 test/compile_errors/stage1/obj/array_concatenation_with_wrong_type.zig create mode 100644 test/compile_errors/stage1/obj/array_in_c_exported_function.zig create mode 100644 test/compile_errors/stage1/obj/asm_at_compile_time.zig create mode 100644 test/compile_errors/stage1/obj/assign_inline_fn_to_non-comptime_var.zig create mode 100644 test/compile_errors/stage1/obj/assign_null_to_non-optional_pointer.zig create mode 100644 test/compile_errors/stage1/obj/assign_through_constant_pointer.zig create mode 100644 test/compile_errors/stage1/obj/assign_through_constant_slice.zig create mode 100644 test/compile_errors/stage1/obj/assign_to_constant_field.zig create mode 100644 test/compile_errors/stage1/obj/assign_to_constant_variable.zig create mode 100644 test/compile_errors/stage1/obj/assign_to_invalid_dereference.zig create mode 100644 test/compile_errors/stage1/obj/assign_too_big_number_to_u16.zig create mode 100644 test/compile_errors/stage1/obj/assign_unreachable.zig create mode 100644 test/compile_errors/stage1/obj/assigning_to_struct_or_union_fields_that_are_not_optionals_with_a_function_that_returns_an_optional.zig create mode 100644 test/compile_errors/stage1/obj/async_function_depends_on_its_own_frame.zig create mode 100644 test/compile_errors/stage1/obj/async_function_indirectly_depends_on_its_own_frame.zig create mode 100644 test/compile_errors/stage1/obj/atomic_orderings_of_atomicStore_Acquire_or_AcqRel.zig create mode 100644 test/compile_errors/stage1/obj/atomic_orderings_of_cmpxchg-failure_stricter_than_success.zig create mode 100644 test/compile_errors/stage1/obj/atomic_orderings_of_cmpxchg-success_Monotonic_or_stricter.zig create mode 100644 test/compile_errors/stage1/obj/atomic_orderings_of_fence_Acquire_or_stricter.zig create mode 100644 test/compile_errors/stage1/obj/atomicrmw_with_bool_op_not_.Xchg.zig create mode 100644 test/compile_errors/stage1/obj/atomicrmw_with_enum_op_not_.Xchg.zig create mode 100644 test/compile_errors/stage1/obj/atomicrmw_with_float_op_not_.Xchg_.Add_or_.Sub.zig create mode 100644 test/compile_errors/stage1/obj/attempt_to_cast_enum_literal_to_error.zig create mode 100644 test/compile_errors/stage1/obj/attempt_to_close_over_comptime_variable_from_outer_scope.zig create mode 100644 test/compile_errors/stage1/obj/attempt_to_create_17_bit_float_type.zig create mode 100644 test/compile_errors/stage1/obj/attempt_to_negate_a_non-integer_non-float_or_non-vector_type.zig create mode 100644 test/compile_errors/stage1/obj/attempt_to_use_0_bit_type_in_extern_fn.zig create mode 100644 test/compile_errors/stage1/obj/attempted_double_ampersand.zig create mode 100644 test/compile_errors/stage1/obj/attempted_double_pipe_on_boolean_values.zig create mode 100644 test/compile_errors/stage1/obj/attempted_implicit_cast_from_T_to_slice_const_T.zig create mode 100644 test/compile_errors/stage1/obj/attempted_implicit_cast_from_const_T_to_array_len_1_T.zig create mode 100644 test/compile_errors/stage1/obj/attempted_implicit_cast_from_const_T_to_sliceT.zig create mode 100644 test/compile_errors/stage1/obj/bad_alignCast_at_comptime.zig create mode 100644 test/compile_errors/stage1/obj/bad_alignment_in_implicit_cast_from_array_pointer_to_slice.zig create mode 100644 test/compile_errors/stage1/obj/bad_alignment_type.zig create mode 100644 test/compile_errors/stage1/obj/bad_identifier_in_function_with_struct_defined_inside_function_which_references_local_const.zig create mode 100644 test/compile_errors/stage1/obj/bad_import.zig create mode 100644 test/compile_errors/stage1/obj/bad_usage_of_call.zig create mode 100644 test/compile_errors/stage1/obj/bin_and_assign_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/bin_and_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/bin_not_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/bin_or_assign_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/bin_or_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/bin_xor_assign_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/bin_xor_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/binary_not_on_number_literal.zig create mode 100644 test/compile_errors/stage1/obj/bitCast_same_size_but_bit_count_mismatch.zig create mode 100644 test/compile_errors/stage1/obj/bitCast_to_enum_type.zig create mode 100644 test/compile_errors/stage1/obj/bitCast_with_different_sizes_inside_an_expression.zig create mode 100644 test/compile_errors/stage1/obj/bit_shifting_only_works_on_integer_types.zig create mode 100644 test/compile_errors/stage1/obj/bogus_compile_var.zig create mode 100644 test/compile_errors/stage1/obj/bogus_method_call_on_slice.zig create mode 100644 test/compile_errors/stage1/obj/bool_not_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/branch_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/cImport_with_bogus_include.zig create mode 100644 test/compile_errors/stage1/obj/call_assigned_to_constant.zig create mode 100644 test/compile_errors/stage1/obj/calling_a_generic_function_only_known_at_runtime.zig create mode 100644 test/compile_errors/stage1/obj/calling_function_with_naked_calling_convention.zig create mode 100644 test/compile_errors/stage1/obj/calling_var_args_extern_function_passing_array_instead_of_pointer.zig create mode 100644 test/compile_errors/stage1/obj/cannot_break_out_of_defer_expression.zig create mode 100644 test/compile_errors/stage1/obj/cannot_continue_out_of_defer_expression.zig create mode 100644 test/compile_errors/stage1/obj/capture_group_on_switch_prong_with_incompatible_payload_types.zig create mode 100644 test/compile_errors/stage1/obj/cast_enum_literal_to_enum_but_it_doesnt_match.zig create mode 100644 test/compile_errors/stage1/obj/cast_error_union_of_global_error_set_to_error_union_of_smaller_error_set.zig create mode 100644 test/compile_errors/stage1/obj/cast_global_error_set_to_error_set.zig create mode 100644 test/compile_errors/stage1/obj/cast_negative_integer_literal_to_usize.zig create mode 100644 test/compile_errors/stage1/obj/cast_negative_value_to_unsigned_integer.zig create mode 100644 test/compile_errors/stage1/obj/cast_unreachable.zig create mode 100644 test/compile_errors/stage1/obj/casting_bit_offset_pointer_to_regular_pointer.zig create mode 100644 test/compile_errors/stage1/obj/catch_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/chained_comparison_operators.zig create mode 100644 test/compile_errors/stage1/obj/cmpxchg_with_float.zig create mode 100644 test/compile_errors/stage1/obj/colliding_invalid_top_level_functions.zig create mode 100644 test/compile_errors/stage1/obj/compare_optional_to_non-optional_with_invalid_types.zig create mode 100644 test/compile_errors/stage1/obj/comparing_a_non-optional_pointer_against_null.zig create mode 100644 test/compile_errors/stage1/obj/comparing_against_undefined_produces_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/comparison_operators_with_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/comparison_with_error_union_and_error_value.zig create mode 100644 test/compile_errors/stage1/obj/compile-time_division_by_zero.zig create mode 100644 test/compile_errors/stage1/obj/compile-time_remainder_division_by_zero.zig create mode 100644 test/compile_errors/stage1/obj/compileError_shows_traceback_of_references_that_caused_it.zig create mode 100644 test/compile_errors/stage1/obj/compileLog_of_tagged_enum_doesnt_crash_the_compiler.zig create mode 100644 test/compile_errors/stage1/obj/compile_error_in_struct_init_expression.zig create mode 100644 test/compile_errors/stage1/obj/compile_error_when_evaluating_return_type_of_inferred_error_set.zig create mode 100644 test/compile_errors/stage1/obj/compile_log.zig create mode 100644 test/compile_errors/stage1/obj/compile_log_a_pointer_to_an_opaque_value.zig create mode 100644 test/compile_errors/stage1/obj/compile_log_statement_inside_function_which_must_be_comptime_evaluated.zig create mode 100644 test/compile_errors/stage1/obj/compile_log_statement_warning_deduplication_in_generic_fn.zig create mode 100644 test/compile_errors/stage1/obj/compile_time_division_by_zero.zig create mode 100644 test/compile_errors/stage1/obj/comptime_cast_enum_to_union_but_field_has_payload.zig create mode 100644 test/compile_errors/stage1/obj/comptime_continue_inside_runtime_catch.zig create mode 100644 test/compile_errors/stage1/obj/comptime_continue_inside_runtime_if_bool.zig create mode 100644 test/compile_errors/stage1/obj/comptime_continue_inside_runtime_if_error.zig create mode 100644 test/compile_errors/stage1/obj/comptime_continue_inside_runtime_if_optional.zig create mode 100644 test/compile_errors/stage1/obj/comptime_continue_inside_runtime_switch.zig create mode 100644 test/compile_errors/stage1/obj/comptime_continue_inside_runtime_while_bool.zig create mode 100644 test/compile_errors/stage1/obj/comptime_continue_inside_runtime_while_error.zig create mode 100644 test/compile_errors/stage1/obj/comptime_continue_inside_runtime_while_optional.zig create mode 100644 test/compile_errors/stage1/obj/comptime_float_in_asm_input.zig create mode 100644 test/compile_errors/stage1/obj/comptime_implicit_cast_f64_to_f32.zig create mode 100644 test/compile_errors/stage1/obj/comptime_int_in_asm_input.zig create mode 100644 test/compile_errors/stage1/obj/comptime_ptrcast_of_zero-sized_type.zig create mode 100644 test/compile_errors/stage1/obj/comptime_slice-sentinel_does_not_match_memory_at_target_index_terminated.zig create mode 100644 test/compile_errors/stage1/obj/comptime_slice-sentinel_does_not_match_memory_at_target_index_unterminated.zig create mode 100644 test/compile_errors/stage1/obj/comptime_slice-sentinel_does_not_match_target-sentinel.zig create mode 100644 test/compile_errors/stage1/obj/comptime_slice-sentinel_is_out_of_bounds_terminated.zig create mode 100644 test/compile_errors/stage1/obj/comptime_slice-sentinel_is_out_of_bounds_unterminated.zig create mode 100644 test/compile_errors/stage1/obj/comptime_slice_of_an_undefined_slice.zig create mode 100644 test/compile_errors/stage1/obj/comptime_slice_of_undefined_pointer_non-zero_len.zig create mode 100644 test/compile_errors/stage1/obj/comptime_struct_field_no_init_value.zig create mode 100644 test/compile_errors/stage1/obj/const_frame_cast_to_anyframe.zig create mode 100644 test/compile_errors/stage1/obj/const_is_a_statement_not_an_expression.zig create mode 100644 test/compile_errors/stage1/obj/constant_inside_comptime_function_has_compile_error.zig create mode 100644 test/compile_errors/stage1/obj/container_init_with_non-type.zig create mode 100644 test/compile_errors/stage1/obj/control_flow_uses_comptime_var_at_runtime.zig create mode 100644 test/compile_errors/stage1/obj/control_reaches_end_of_non-void_function.zig create mode 100644 test/compile_errors/stage1/obj/declaration_between_fields.zig create mode 100644 test/compile_errors/stage1/obj/declaration_with_same_name_as_primitive_must_use_special_syntax.zig create mode 100644 test/compile_errors/stage1/obj/deduplicate_undeclared_identifier.zig create mode 100644 test/compile_errors/stage1/obj/deref_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/deref_slice_and_get_len_field.zig create mode 100644 test/compile_errors/stage1/obj/dereference_an_array.zig create mode 100644 test/compile_errors/stage1/obj/dereference_unknown_length_pointer.zig create mode 100644 test/compile_errors/stage1/obj/direct_struct_loop.zig create mode 100644 test/compile_errors/stage1/obj/directly_embedding_opaque_type_in_struct_and_union.zig create mode 100644 test/compile_errors/stage1/obj/disallow_coercion_from_non-null-terminated_pointer_to_null-terminated_pointer.zig create mode 100644 test/compile_errors/stage1/obj/discarding_error_value.zig create mode 100644 test/compile_errors/stage1/obj/div_assign_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/div_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/division_by_zero.zig create mode 100644 test/compile_errors/stage1/obj/dont_implicit_cast_double_pointer_to_anyopaque.zig create mode 100644 test/compile_errors/stage1/obj/double_optional_on_main_return_value.zig create mode 100644 test/compile_errors/stage1/obj/duplicate_boolean_switch_value.zig create mode 100644 test/compile_errors/stage1/obj/duplicate_enum_field.zig create mode 100644 test/compile_errors/stage1/obj/duplicate_error_in_switch.zig create mode 100644 test/compile_errors/stage1/obj/duplicate_error_value_in_error_set.zig create mode 100644 test/compile_errors/stage1/obj/duplicate_field_in_struct_value_expression.zig create mode 100644 test/compile_errors/stage1/obj/duplicate_struct_field.zig create mode 100644 test/compile_errors/stage1/obj/duplicate_union_field.zig create mode 100644 test/compile_errors/stage1/obj/embedFile_with_bogus_file.zig create mode 100644 test/compile_errors/stage1/obj/empty_for_loop_body.zig create mode 100644 test/compile_errors/stage1/obj/empty_if_body.zig create mode 100644 test/compile_errors/stage1/obj/empty_switch_on_an_integer.zig create mode 100644 test/compile_errors/stage1/obj/empty_while_loop_body.zig create mode 100644 test/compile_errors/stage1/obj/endless_loop_in_function_evaluation.zig create mode 100644 test/compile_errors/stage1/obj/enum_field_value_references_enum.zig create mode 100644 test/compile_errors/stage1/obj/enum_in_field_count_range_but_not_matching_tag.zig create mode 100644 test/compile_errors/stage1/obj/enum_value_already_taken.zig create mode 100644 test/compile_errors/stage1/obj/enum_with_0_fields.zig create mode 100644 test/compile_errors/stage1/obj/enum_with_declarations_unavailable_for_reify_type.zig create mode 100644 test/compile_errors/stage1/obj/error_equality_but_sets_have_no_common_members.zig create mode 100644 test/compile_errors/stage1/obj/error_not_handled_in_switch.zig create mode 100644 test/compile_errors/stage1/obj/error_note_for_function_parameter_incompatibility.zig create mode 100644 test/compile_errors/stage1/obj/error_union_operator_with_non_error_set_LHS.zig create mode 100644 test/compile_errors/stage1/obj/error_when_evaluating_return_type.zig create mode 100644 test/compile_errors/stage1/obj/exceeded_maximum_bit_width_of_integer.zig create mode 100644 test/compile_errors/stage1/obj/explicit_cast_float_literal_to_integer_when_there_is_a_fraction_component.zig create mode 100644 test/compile_errors/stage1/obj/explicit_error_set_cast_known_at_comptime_violates_error_sets.zig create mode 100644 test/compile_errors/stage1/obj/explicitly_casting_non_tag_type_to_enum.zig create mode 100644 test/compile_errors/stage1/obj/export_function_with_comptime_parameter.zig create mode 100644 test/compile_errors/stage1/obj/export_generic_function.zig create mode 100644 test/compile_errors/stage1/obj/exported_async_function.zig create mode 100644 test/compile_errors/stage1/obj/exported_enum_without_explicit_integer_tag_type.zig create mode 100644 test/compile_errors/stage1/obj/extern_function_pointer_mismatch.zig create mode 100644 test/compile_errors/stage1/obj/extern_function_with_comptime_parameter.zig create mode 100644 test/compile_errors/stage1/obj/extern_struct_with_extern-compatible_but_inferred_integer_tag_type.zig create mode 100644 test/compile_errors/stage1/obj/extern_struct_with_non-extern-compatible_integer_tag_type.zig create mode 100644 test/compile_errors/stage1/obj/extern_union_field_missing_type.zig create mode 100644 test/compile_errors/stage1/obj/extern_union_given_enum_tag_type.zig create mode 100644 test/compile_errors/stage1/obj/extern_variable_has_no_type.zig create mode 100644 test/compile_errors/stage1/obj/fieldParentPtr-bad_field_name.zig create mode 100644 test/compile_errors/stage1/obj/fieldParentPtr-comptime_field_ptr_not_based_on_struct.zig create mode 100644 test/compile_errors/stage1/obj/fieldParentPtr-comptime_wrong_field_index.zig create mode 100644 test/compile_errors/stage1/obj/fieldParentPtr-field_pointer_is_not_pointer.zig create mode 100644 test/compile_errors/stage1/obj/fieldParentPtr-non_struct.zig create mode 100644 test/compile_errors/stage1/obj/field_access_of_opaque_type.zig create mode 100644 test/compile_errors/stage1/obj/field_access_of_slices.zig create mode 100644 test/compile_errors/stage1/obj/field_access_of_unknown_length_pointer.zig create mode 100644 test/compile_errors/stage1/obj/field_type_supplied_in_an_enum.zig create mode 100644 test/compile_errors/stage1/obj/floatToInt_comptime_safety.zig create mode 100644 test/compile_errors/stage1/obj/float_literal_too_large_error.zig create mode 100644 test/compile_errors/stage1/obj/float_literal_too_small_error_denormal.zig create mode 100644 test/compile_errors/stage1/obj/for_loop_body_expression_ignored.zig create mode 100644 test/compile_errors/stage1/obj/frame_called_outside_of_function_definition.zig create mode 100644 test/compile_errors/stage1/obj/frame_causes_function_to_be_async.zig create mode 100644 test/compile_errors/stage1/obj/function_alignment_non_power_of_2.zig create mode 100644 test/compile_errors/stage1/obj/function_call_assigned_to_incorrect_type.zig create mode 100644 test/compile_errors/stage1/obj/function_parameter_is_opaque.zig create mode 100644 test/compile_errors/stage1/obj/function_prototype_with_no_body.zig create mode 100644 test/compile_errors/stage1/obj/function_returning_opaque_type.zig create mode 100644 test/compile_errors/stage1/obj/function_with_ccc_indirectly_calling_async_function.zig create mode 100644 test/compile_errors/stage1/obj/function_with_invalid_return_type.zig create mode 100644 test/compile_errors/stage1/obj/function_with_non-extern_non-packed_enum_parameter.zig create mode 100644 test/compile_errors/stage1/obj/function_with_non-extern_non-packed_struct_parameter.zig create mode 100644 test/compile_errors/stage1/obj/function_with_non-extern_non-packed_union_parameter.zig create mode 100644 test/compile_errors/stage1/obj/generic_fn_as_parameter_without_comptime_keyword.zig create mode 100644 test/compile_errors/stage1/obj/generic_function_call_assigned_to_incorrect_type.zig create mode 100644 test/compile_errors/stage1/obj/generic_function_instance_with_non-constant_expression.zig create mode 100644 test/compile_errors/stage1/obj/generic_function_returning_opaque_type.zig create mode 100644 test/compile_errors/stage1/obj/generic_function_where_return_type_is_self-referenced.zig create mode 100644 test/compile_errors/stage1/obj/global_variable_alignment_non_power_of_2.zig create mode 100644 test/compile_errors/stage1/obj/global_variable_initializer_must_be_constant_expression.zig create mode 100644 test/compile_errors/stage1/obj/hasDecl_with_non-container.zig create mode 100644 test/compile_errors/stage1/obj/if_condition_is_bool_not_int.zig create mode 100644 test/compile_errors/stage1/obj/ignored_assert-err-ok_return_value.zig create mode 100644 test/compile_errors/stage1/obj/ignored_comptime_statement_value.zig create mode 100644 test/compile_errors/stage1/obj/ignored_comptime_value.zig create mode 100644 test/compile_errors/stage1/obj/ignored_deferred_function_call.zig create mode 100644 test/compile_errors/stage1/obj/ignored_deferred_statement_value.zig create mode 100644 test/compile_errors/stage1/obj/ignored_expression_in_while_continuation.zig create mode 100644 test/compile_errors/stage1/obj/ignored_return_value.zig create mode 100644 test/compile_errors/stage1/obj/ignored_statement_value.zig create mode 100644 test/compile_errors/stage1/obj/illegal_comparison_of_types.zig create mode 100644 test/compile_errors/stage1/obj/implicit_cast_between_C_pointer_and_Zig_pointer-bad_const-align-child.zig create mode 100644 test/compile_errors/stage1/obj/implicit_cast_const_array_to_mutable_slice.zig create mode 100644 test/compile_errors/stage1/obj/implicit_cast_from_array_to_mutable_slice.zig create mode 100644 test/compile_errors/stage1/obj/implicit_cast_from_f64_to_f32.zig create mode 100644 test/compile_errors/stage1/obj/implicit_cast_of_error_set_not_a_subset.zig create mode 100644 test/compile_errors/stage1/obj/implicit_casting_C_pointers_which_would_mess_up_null_semantics.zig create mode 100644 test/compile_errors/stage1/obj/implicit_casting_null_c_pointer_to_zig_pointer.zig create mode 100644 test/compile_errors/stage1/obj/implicit_casting_too_big_integers_to_C_pointers.zig create mode 100644 test/compile_errors/stage1/obj/implicit_casting_undefined_c_pointer_to_zig_pointer.zig create mode 100644 test/compile_errors/stage1/obj/implicit_semicolon-block_expr.zig create mode 100644 test/compile_errors/stage1/obj/implicit_semicolon-block_statement.zig create mode 100644 test/compile_errors/stage1/obj/implicit_semicolon-comptime_expression.zig create mode 100644 test/compile_errors/stage1/obj/implicit_semicolon-comptime_statement.zig create mode 100644 test/compile_errors/stage1/obj/implicit_semicolon-defer.zig create mode 100644 test/compile_errors/stage1/obj/implicit_semicolon-for_expression.zig create mode 100644 test/compile_errors/stage1/obj/implicit_semicolon-for_statement.zig create mode 100644 test/compile_errors/stage1/obj/implicit_semicolon-if-else-if-else_expression.zig create mode 100644 test/compile_errors/stage1/obj/implicit_semicolon-if-else-if-else_statement.zig create mode 100644 test/compile_errors/stage1/obj/implicit_semicolon-if-else-if_expression.zig create mode 100644 test/compile_errors/stage1/obj/implicit_semicolon-if-else-if_statement.zig create mode 100644 test/compile_errors/stage1/obj/implicit_semicolon-if-else_expression.zig create mode 100644 test/compile_errors/stage1/obj/implicit_semicolon-if-else_statement.zig create mode 100644 test/compile_errors/stage1/obj/implicit_semicolon-if_expression.zig create mode 100644 test/compile_errors/stage1/obj/implicit_semicolon-if_statement.zig create mode 100644 test/compile_errors/stage1/obj/implicit_semicolon-test_expression.zig create mode 100644 test/compile_errors/stage1/obj/implicit_semicolon-test_statement.zig create mode 100644 test/compile_errors/stage1/obj/implicit_semicolon-while-continue_expression.zig create mode 100644 test/compile_errors/stage1/obj/implicit_semicolon-while-continue_statement.zig create mode 100644 test/compile_errors/stage1/obj/implicit_semicolon-while_expression.zig create mode 100644 test/compile_errors/stage1/obj/implicit_semicolon-while_statement.zig create mode 100644 test/compile_errors/stage1/obj/implicitly_casting_enum_to_tag_type.zig create mode 100644 test/compile_errors/stage1/obj/implicitly_increasing_pointer_alignment.zig create mode 100644 test/compile_errors/stage1/obj/implicitly_increasing_slice_alignment.zig create mode 100644 test/compile_errors/stage1/obj/import_outside_package_path.zig create mode 100644 test/compile_errors/stage1/obj/incorrect_return_type.zig create mode 100644 test/compile_errors/stage1/obj/increase_pointer_alignment_in_ptrCast.zig create mode 100644 test/compile_errors/stage1/obj/indexing_a_undefined_slice_at_comptime.zig create mode 100644 test/compile_errors/stage1/obj/indexing_an_array_of_size_zero.zig create mode 100644 test/compile_errors/stage1/obj/indexing_an_array_of_size_zero_with_runtime_index.zig create mode 100644 test/compile_errors/stage1/obj/indexing_single-item_pointer.zig create mode 100644 test/compile_errors/stage1/obj/indirect_recursion_of_async_functions_detected.zig create mode 100644 test/compile_errors/stage1/obj/indirect_struct_loop.zig create mode 100644 test/compile_errors/stage1/obj/inferred_array_size_invalid_here.zig create mode 100644 test/compile_errors/stage1/obj/inferring_error_set_of_function_pointer.zig create mode 100644 test/compile_errors/stage1/obj/initializing_array_with_struct_syntax.zig create mode 100644 test/compile_errors/stage1/obj/instantiating_an_undefined_value_for_an_invalid_struct_that_contains_itself.zig create mode 100644 test/compile_errors/stage1/obj/intToPtr_with_misaligned_address.zig create mode 100644 test/compile_errors/stage1/obj/int_to_err_global_invalid_number.zig create mode 100644 test/compile_errors/stage1/obj/int_to_err_non_global_invalid_number.zig create mode 100644 test/compile_errors/stage1/obj/int_to_ptr_of_0_bits.zig create mode 100644 test/compile_errors/stage1/obj/integer_cast_truncates_bits.zig create mode 100644 test/compile_errors/stage1/obj/integer_overflow_error.zig create mode 100644 test/compile_errors/stage1/obj/integer_underflow_error.zig create mode 100644 test/compile_errors/stage1/obj/invalid_break_expression.zig create mode 100644 test/compile_errors/stage1/obj/invalid_builtin_fn.zig create mode 100644 test/compile_errors/stage1/obj/invalid_cast_from_integral_type_to_enum.zig create mode 100644 test/compile_errors/stage1/obj/invalid_comparison_for_function_pointers.zig create mode 100644 test/compile_errors/stage1/obj/invalid_continue_expression.zig create mode 100644 test/compile_errors/stage1/obj/invalid_deref_on_switch_target.zig create mode 100644 test/compile_errors/stage1/obj/invalid_empty_unicode_escape.zig create mode 100644 test/compile_errors/stage1/obj/invalid_exponent_in_float_literal-1.zig create mode 100644 test/compile_errors/stage1/obj/invalid_exponent_in_float_literal-2.zig create mode 100644 test/compile_errors/stage1/obj/invalid_field_access_in_comptime.zig create mode 100644 test/compile_errors/stage1/obj/invalid_field_in_struct_value_expression.zig create mode 100644 test/compile_errors/stage1/obj/invalid_float_literal.zig create mode 100644 test/compile_errors/stage1/obj/invalid_legacy_unicode_escape.zig create mode 100644 test/compile_errors/stage1/obj/invalid_maybe_type.zig create mode 100644 test/compile_errors/stage1/obj/invalid_member_of_builtin_enum.zig create mode 100644 test/compile_errors/stage1/obj/invalid_multiple_dereferences.zig create mode 100644 test/compile_errors/stage1/obj/invalid_optional_type_in_extern_struct.zig create mode 100644 test/compile_errors/stage1/obj/invalid_pointer_for_var_type.zig create mode 100644 test/compile_errors/stage1/obj/invalid_pointer_syntax.zig create mode 100644 test/compile_errors/stage1/obj/invalid_shift_amount_error.zig create mode 100644 test/compile_errors/stage1/obj/invalid_struct_field.zig create mode 100644 test/compile_errors/stage1/obj/invalid_suspend_in_exported_function.zig create mode 100644 test/compile_errors/stage1/obj/invalid_type.zig create mode 100644 test/compile_errors/stage1/obj/invalid_type_used_in_array_type.zig create mode 100644 test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-1.zig create mode 100644 test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-10.zig create mode 100644 test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-11.zig create mode 100644 test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-12.zig create mode 100644 test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-13.zig create mode 100644 test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-14.zig create mode 100644 test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-2.zig create mode 100644 test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-3.zig create mode 100644 test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-4.zig create mode 100644 test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-5.zig create mode 100644 test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-6.zig create mode 100644 test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-7.zig create mode 100644 test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-9.zig create mode 100644 test/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-1.zig create mode 100644 test/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-2.zig create mode 100644 test/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-3.zig create mode 100644 test/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-4.zig create mode 100644 test/compile_errors/stage1/obj/invalid_union_field_access_in_comptime.zig create mode 100644 test/compile_errors/stage1/obj/issue_2032_compile_diagnostic_string_for_top_level_decl_type.zig create mode 100644 test/compile_errors/stage1/obj/issue_2687_coerce_from_undefined_array_pointer_to_slice.zig create mode 100644 test/compile_errors/stage1/obj/issue_3818_bitcast_from_parray-slice_to_u16.zig create mode 100644 test/compile_errors/stage1/obj/issue_4207_coerce_from_non-terminated-slice_to_terminated-pointer.zig create mode 100644 test/compile_errors/stage1/obj/issue_5221_invalid_struct_init_type_referenced_by_typeInfo_and_passed_into_function.zig create mode 100644 test/compile_errors/stage1/obj/issue_5618_coercion_of_optional_anyopaque_to_anyopaque_must_fail.zig create mode 100644 test/compile_errors/stage1/obj/issue_7810-comptime_slice-len_increment_beyond_bounds.zig create mode 100644 test/compile_errors/stage1/obj/issue_9346_return_outside_of_function_scope.zig create mode 100644 test/compile_errors/stage1/obj/labeled_break_not_found.zig create mode 100644 test/compile_errors/stage1/obj/labeled_continue_not_found.zig create mode 100644 test/compile_errors/stage1/obj/lazy_pointer_with_undefined_element_type.zig create mode 100644 test/compile_errors/stage1/obj/load_too_many_bytes_from_comptime_reinterpreted_pointer.zig create mode 100644 test/compile_errors/stage1/obj/load_vector_pointer_with_unknown_runtime_index.zig create mode 100644 test/compile_errors/stage1/obj/local_shadows_global_that_occurs_later.zig create mode 100644 test/compile_errors/stage1/obj/local_variable_redeclaration.zig create mode 100644 test/compile_errors/stage1/obj/local_variable_redeclares_parameter.zig create mode 100644 test/compile_errors/stage1/obj/local_variable_shadowing_global.zig create mode 100644 test/compile_errors/stage1/obj/locally_shadowing_a_primitive_type.zig create mode 100644 test/compile_errors/stage1/obj/main_function_with_bogus_args_type.zig create mode 100644 test/compile_errors/stage1/obj/method_call_with_first_arg_type_primitive.zig create mode 100644 test/compile_errors/stage1/obj/method_call_with_first_arg_type_wrong_container.zig create mode 100644 test/compile_errors/stage1/obj/missing_boolean_switch_value.zig create mode 100644 test/compile_errors/stage1/obj/missing_const_in_slice_with_nested_array_type.zig create mode 100644 test/compile_errors/stage1/obj/missing_else_clause.zig create mode 100644 test/compile_errors/stage1/obj/missing_field_in_struct_value_expression.zig create mode 100644 test/compile_errors/stage1/obj/missing_function_call_param.zig create mode 100644 test/compile_errors/stage1/obj/missing_function_name.zig create mode 100644 test/compile_errors/stage1/obj/missing_param_name.zig create mode 100644 test/compile_errors/stage1/obj/missing_parameter_name_of_generic_function.zig create mode 100644 test/compile_errors/stage1/obj/missing_result_type_for_phi_node.zig create mode 100644 test/compile_errors/stage1/obj/misspelled_type_with_pointer_only_reference.zig create mode 100644 test/compile_errors/stage1/obj/mod_assign_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/mod_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/mul_overflow_in_function_evaluation.zig create mode 100644 test/compile_errors/stage1/obj/mult_assign_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/mult_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/mult_wrap_assign_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/mult_wrap_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/multiple_function_definitions.zig create mode 100644 test/compile_errors/stage1/obj/negate_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/negate_wrap_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/negation_overflow_in_function_evaluation.zig create mode 100644 test/compile_errors/stage1/obj/nested_error_set_mismatch.zig create mode 100644 test/compile_errors/stage1/obj/no_else_prong_on_switch_on_global_error_set.zig create mode 100644 test/compile_errors/stage1/obj/noalias_on_non_pointer_param.zig create mode 100644 test/compile_errors/stage1/obj/non-async_function_pointer_eventually_is_inferred_to_become_async.zig create mode 100644 test/compile_errors/stage1/obj/non-const_expression_function_call_with_struct_return_value_outside_function.zig create mode 100644 test/compile_errors/stage1/obj/non-const_expression_in_struct_literal_outside_function.zig create mode 100644 test/compile_errors/stage1/obj/non-const_switch_number_literal.zig create mode 100644 test/compile_errors/stage1/obj/non-const_variables_of_things_that_require_const_variables.zig create mode 100644 test/compile_errors/stage1/obj/non-enum_tag_type_passed_to_union.zig create mode 100644 test/compile_errors/stage1/obj/non-extern_function_with_var_args.zig create mode 100644 test/compile_errors/stage1/obj/non-inline_for_loop_on_a_type_that_requires_comptime.zig create mode 100644 test/compile_errors/stage1/obj/non-integer_tag_type_to_automatic_union_enum.zig create mode 100644 test/compile_errors/stage1/obj/non-pure_function_returns_type.zig create mode 100644 test/compile_errors/stage1/obj/non_async_function_pointer_passed_to_asyncCall.zig create mode 100644 test/compile_errors/stage1/obj/non_compile_time_array_concatenation.zig create mode 100644 test/compile_errors/stage1/obj/non_constant_expression_in_array_size.zig create mode 100644 test/compile_errors/stage1/obj/non_error_sets_used_in_merge_error_sets_operator.zig create mode 100644 test/compile_errors/stage1/obj/non_float_passed_to_floatToInt.zig create mode 100644 test/compile_errors/stage1/obj/non_int_passed_to_intToFloat.zig create mode 100644 test/compile_errors/stage1/obj/non_pointer_given_to_ptrToInt.zig create mode 100644 test/compile_errors/stage1/obj/normal_string_with_newline.zig create mode 100644 test/compile_errors/stage1/obj/offsetOf-bad_field_name.zig create mode 100644 test/compile_errors/stage1/obj/offsetOf-non_struct.zig create mode 100644 test/compile_errors/stage1/obj/only_equality_binary_operator_allowed_for_error_sets.zig create mode 100644 test/compile_errors/stage1/obj/opaque_type_with_field.zig create mode 100644 test/compile_errors/stage1/obj/optional_pointer_to_void_in_extern_struct.zig create mode 100644 test/compile_errors/stage1/obj/or_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/orelse_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/out_of_range_comptime_int_passed_to_floatToInt.zig create mode 100644 test/compile_errors/stage1/obj/overflow_in_enum_value_allocation.zig create mode 100644 test/compile_errors/stage1/obj/packed_union_given_enum_tag_type.zig create mode 100644 test/compile_errors/stage1/obj/packed_union_with_automatic_layout_field.zig create mode 100644 test/compile_errors/stage1/obj/panic_called_at_compile_time.zig create mode 100644 test/compile_errors/stage1/obj/parameter_redeclaration.zig create mode 100644 test/compile_errors/stage1/obj/parameter_shadowing_global.zig create mode 100644 test/compile_errors/stage1/obj/pass_const_ptr_to_mutable_ptr_fn.zig create mode 100644 test/compile_errors/stage1/obj/passing_a_not-aligned-enough_pointer_to_cmpxchg.zig create mode 100644 test/compile_errors/stage1/obj/passing_an_under-aligned_function_pointer.zig create mode 100644 test/compile_errors/stage1/obj/peer_cast_then_implicit_cast_const_pointer_to_mutable_C_pointer.zig create mode 100644 test/compile_errors/stage1/obj/pointer_arithmetic_on_pointer-to-array.zig create mode 100644 test/compile_errors/stage1/obj/pointer_attributes_checked_when_coercing_pointer_to_anon_literal.zig create mode 100644 test/compile_errors/stage1/obj/pointer_to_noreturn.zig create mode 100644 test/compile_errors/stage1/obj/popCount-non-integer.zig create mode 100644 test/compile_errors/stage1/obj/prevent_bad_implicit_casting_of_anyframe_types.zig create mode 100644 test/compile_errors/stage1/obj/primitives_take_precedence_over_declarations.zig create mode 100644 test/compile_errors/stage1/obj/ptrCast_a_0_bit_type_to_a_non-_0_bit_type.zig create mode 100644 test/compile_errors/stage1/obj/ptrCast_discards_const_qualifier.zig create mode 100644 test/compile_errors/stage1/obj/ptrToInt_0_to_non_optional_pointer.zig create mode 100644 test/compile_errors/stage1/obj/ptrToInt_on_void.zig create mode 100644 test/compile_errors/stage1/obj/ptrcast_to_non-pointer.zig create mode 100644 test/compile_errors/stage1/obj/range_operator_in_switch_used_on_error_set.zig create mode 100644 test/compile_errors/stage1/obj/reading_past_end_of_pointer_casted_array.zig create mode 100644 test/compile_errors/stage1/obj/recursive_inferred_error_set.zig create mode 100644 test/compile_errors/stage1/obj/redefinition_of_enums.zig create mode 100644 test/compile_errors/stage1/obj/redefinition_of_global_variables.zig create mode 100644 test/compile_errors/stage1/obj/redefinition_of_struct.zig create mode 100644 test/compile_errors/stage1/obj/refer_to_the_type_of_a_generic_function.zig create mode 100644 test/compile_errors/stage1/obj/referring_to_a_struct_that_is_invalid.zig create mode 100644 test/compile_errors/stage1/obj/regression_test_2980_base_type_u32_is_not_type_checked_properly_when_assigning_a_value_within_a_struct.zig create mode 100644 test/compile_errors/stage1/obj/reify_type.Fn_with_is_generic_true.zig create mode 100644 test/compile_errors/stage1/obj/reify_type.Fn_with_is_var_args_true_and_non-C_callconv.zig create mode 100644 test/compile_errors/stage1/obj/reify_type.Fn_with_return_type_null.zig create mode 100644 test/compile_errors/stage1/obj/reify_type.Pointer_with_invalid_address_space.zig create mode 100644 test/compile_errors/stage1/obj/reify_type_for_exhaustive_enum_with_non-integer_tag_type.zig create mode 100644 test/compile_errors/stage1/obj/reify_type_for_exhaustive_enum_with_undefined_tag_type.zig create mode 100644 test/compile_errors/stage1/obj/reify_type_for_exhaustive_enum_with_zero_fields.zig create mode 100644 test/compile_errors/stage1/obj/reify_type_for_tagged_union_with_extra_enum_field.zig create mode 100644 test/compile_errors/stage1/obj/reify_type_for_tagged_union_with_extra_union_field.zig create mode 100644 test/compile_errors/stage1/obj/reify_type_for_union_with_opaque_field.zig create mode 100644 test/compile_errors/stage1/obj/reify_type_for_union_with_zero_fields.zig create mode 100644 test/compile_errors/stage1/obj/reify_type_union_payload_is_undefined.zig create mode 100644 test/compile_errors/stage1/obj/reify_type_with_Type.Int.zig create mode 100644 test/compile_errors/stage1/obj/reify_type_with_non-constant_expression.zig create mode 100644 test/compile_errors/stage1/obj/reify_type_with_undefined.zig create mode 100644 test/compile_errors/stage1/obj/result_location_incompatibility_mismatching_handle_is_ptr.zig create mode 100644 test/compile_errors/stage1/obj/result_location_incompatibility_mismatching_handle_is_ptr_generic_call.zig create mode 100644 test/compile_errors/stage1/obj/return_from_defer_expression.zig create mode 100644 test/compile_errors/stage1/obj/returning_error_from_void_async_function.zig create mode 100644 test/compile_errors/stage1/obj/runtime-known_async_function_called.zig create mode 100644 test/compile_errors/stage1/obj/runtime-known_function_called_with_async_keyword.zig create mode 100644 test/compile_errors/stage1/obj/runtime_assignment_to_comptime_struct_type.zig create mode 100644 test/compile_errors/stage1/obj/runtime_assignment_to_comptime_union_type.zig create mode 100644 test/compile_errors/stage1/obj/runtime_cast_to_union_which_has_non-void_fields.zig create mode 100644 test/compile_errors/stage1/obj/runtime_index_into_comptime_type_slice.zig create mode 100644 test/compile_errors/stage1/obj/saturating_arithmetic_does_not_allow_floats.zig create mode 100644 test/compile_errors/stage1/obj/saturating_shl_assign_does_not_allow_negative_rhs_at_comptime.zig create mode 100644 test/compile_errors/stage1/obj/saturating_shl_does_not_allow_negative_rhs_at_comptime.zig create mode 100644 test/compile_errors/stage1/obj/setAlignStack_in_inline_function.zig create mode 100644 test/compile_errors/stage1/obj/setAlignStack_in_naked_function.zig create mode 100644 test/compile_errors/stage1/obj/setAlignStack_outside_function.zig create mode 100644 test/compile_errors/stage1/obj/setAlignStack_set_twice.zig create mode 100644 test/compile_errors/stage1/obj/setAlignStack_too_big.zig create mode 100644 test/compile_errors/stage1/obj/setFloatMode_twice_for_same_scope.zig create mode 100644 test/compile_errors/stage1/obj/setRuntimeSafety_twice_for_same_scope.zig create mode 100644 test/compile_errors/stage1/obj/setting_a_section_on_a_local_variable.zig create mode 100644 test/compile_errors/stage1/obj/shift_amount_has_to_be_an_integer_type.zig create mode 100644 test/compile_errors/stage1/obj/shift_by_negative_comptime_integer.zig create mode 100644 test/compile_errors/stage1/obj/shift_left_assign_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/shift_left_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/shift_right_assign_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/shift_right_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/shifting_RHS_is_log2_of_LHS_int_bit_width.zig create mode 100644 test/compile_errors/stage1/obj/shifting_without_int_type_or_comptime_known.zig create mode 100644 test/compile_errors/stage1/obj/shlExact_shifts_out_1_bits.zig create mode 100644 test/compile_errors/stage1/obj/shrExact_shifts_out_1_bits.zig create mode 100644 test/compile_errors/stage1/obj/signed_integer_division.zig create mode 100644 test/compile_errors/stage1/obj/signed_integer_remainder_division.zig create mode 100644 test/compile_errors/stage1/obj/sizeOf_bad_type.zig create mode 100644 test/compile_errors/stage1/obj/slice_cannot_have_its_bytes_reinterpreted.zig create mode 100644 test/compile_errors/stage1/obj/slice_passed_as_array_init_type.zig create mode 100644 test/compile_errors/stage1/obj/slice_passed_as_array_init_type_with_elems.zig create mode 100644 test/compile_errors/stage1/obj/slice_sentinel_mismatch-1.zig create mode 100644 test/compile_errors/stage1/obj/slice_sentinel_mismatch-2.zig create mode 100644 test/compile_errors/stage1/obj/slicing_of_global_undefined_pointer.zig create mode 100644 test/compile_errors/stage1/obj/slicing_single-item_pointer.zig create mode 100644 test/compile_errors/stage1/obj/specify_enum_tag_type_that_is_too_small.zig create mode 100644 test/compile_errors/stage1/obj/specify_non-integer_enum_tag_type.zig create mode 100644 test/compile_errors/stage1/obj/src_outside_function.zig create mode 100644 test/compile_errors/stage1/obj/store_vector_pointer_with_unknown_runtime_index.zig create mode 100644 test/compile_errors/stage1/obj/storing_runtime_value_in_compile_time_variable_then_using_it.zig create mode 100644 test/compile_errors/stage1/obj/struct_depends_on_itself_via_optional_field.zig create mode 100644 test/compile_errors/stage1/obj/struct_field_missing_type.zig create mode 100644 test/compile_errors/stage1/obj/struct_init_syntax_for_array.zig create mode 100644 test/compile_errors/stage1/obj/struct_with_declarations_unavailable_for_reify_type.zig create mode 100644 test/compile_errors/stage1/obj/struct_with_invalid_field.zig create mode 100644 test/compile_errors/stage1/obj/sub_assign_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/sub_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/sub_overflow_in_function_evaluation.zig create mode 100644 test/compile_errors/stage1/obj/sub_wrap_assign_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/sub_wrap_on_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/suspend_inside_suspend_block.zig create mode 100644 test/compile_errors/stage1/obj/switch_expression-duplicate_enumeration_prong.zig create mode 100644 test/compile_errors/stage1/obj/switch_expression-duplicate_enumeration_prong_when_else_present.zig create mode 100644 test/compile_errors/stage1/obj/switch_expression-duplicate_or_overlapping_integer_value.zig create mode 100644 test/compile_errors/stage1/obj/switch_expression-duplicate_type.zig create mode 100644 test/compile_errors/stage1/obj/switch_expression-duplicate_type_struct_alias.zig create mode 100644 test/compile_errors/stage1/obj/switch_expression-missing_enumeration_prong.zig create mode 100644 test/compile_errors/stage1/obj/switch_expression-multiple_else_prongs.zig create mode 100644 test/compile_errors/stage1/obj/switch_expression-non_exhaustive_integer_prongs.zig create mode 100644 test/compile_errors/stage1/obj/switch_expression-switch_on_pointer_type_with_no_else.zig create mode 100644 test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_bool.zig create mode 100644 test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_enum.zig create mode 100644 test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_range_i8.zig create mode 100644 test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_range_u8.zig create mode 100644 test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_u1.zig create mode 100644 test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_u2.zig create mode 100644 test/compile_errors/stage1/obj/switch_on_enum_with_1_field_with_no_prongs.zig create mode 100644 test/compile_errors/stage1/obj/switch_on_union_with_no_attached_enum.zig create mode 100644 test/compile_errors/stage1/obj/switch_with_invalid_expression_parameter.zig create mode 100644 test/compile_errors/stage1/obj/switch_with_overlapping_case_ranges.zig create mode 100644 test/compile_errors/stage1/obj/tagName_used_on_union_with_no_associated_enum_tag.zig create mode 100644 test/compile_errors/stage1/obj/take_slice_of_invalid_dereference.zig create mode 100644 test/compile_errors/stage1/obj/taking_bit_offset_of_void_field_in_struct.zig create mode 100644 test/compile_errors/stage1/obj/taking_byte_offset_of_void_field_in_struct.zig create mode 100644 test/compile_errors/stage1/obj/threadlocal_qualifier_on_const.zig create mode 100644 test/compile_errors/stage1/obj/top_level_decl_dependency_loop.zig create mode 100644 test/compile_errors/stage1/obj/truncate_sign_mismatch.zig create mode 100644 test/compile_errors/stage1/obj/truncate_undefined_value.zig create mode 100644 test/compile_errors/stage1/obj/try_in_function_with_non_error_return_type.zig create mode 100644 test/compile_errors/stage1/obj/type_checking_function_pointers.zig create mode 100644 test/compile_errors/stage1/obj/type_variables_must_be_constant.zig create mode 100644 test/compile_errors/stage1/obj/undeclared_identifier.zig create mode 100644 test/compile_errors/stage1/obj/undeclared_identifier_error_should_mark_fn_as_impure.zig create mode 100644 test/compile_errors/stage1/obj/undeclared_identifier_in_unanalyzed_branch.zig create mode 100644 test/compile_errors/stage1/obj/undefined_as_field_type_is_rejected.zig create mode 100644 test/compile_errors/stage1/obj/undefined_function_call.zig create mode 100644 test/compile_errors/stage1/obj/underscore_is_not_a_declarable_symbol.zig create mode 100644 test/compile_errors/stage1/obj/underscore_should_not_be_usable_inside_for.zig create mode 100644 test/compile_errors/stage1/obj/underscore_should_not_be_usable_inside_while.zig create mode 100644 test/compile_errors/stage1/obj/underscore_should_not_be_usable_inside_while_else.zig create mode 100644 test/compile_errors/stage1/obj/union_auto-enum_value_already_taken.zig create mode 100644 test/compile_errors/stage1/obj/union_enum_field_does_not_match_enum.zig create mode 100644 test/compile_errors/stage1/obj/union_fields_with_value_assignments.zig create mode 100644 test/compile_errors/stage1/obj/union_with_0_fields.zig create mode 100644 test/compile_errors/stage1/obj/union_with_specified_enum_omits_field.zig create mode 100644 test/compile_errors/stage1/obj/union_with_too_small_explicit_signed_tag_type.zig create mode 100644 test/compile_errors/stage1/obj/union_with_too_small_explicit_unsigned_tag_type.zig create mode 100644 test/compile_errors/stage1/obj/unknown_length_pointer_to_opaque.zig create mode 100644 test/compile_errors/stage1/obj/unreachable_code-double_break.zig create mode 100644 test/compile_errors/stage1/obj/unreachable_code-nested_returns.zig create mode 100644 test/compile_errors/stage1/obj/unreachable_code.zig create mode 100644 test/compile_errors/stage1/obj/unreachable_executed_at_comptime.zig create mode 100644 test/compile_errors/stage1/obj/unreachable_parameter.zig create mode 100644 test/compile_errors/stage1/obj/unreachable_variable.zig create mode 100644 test/compile_errors/stage1/obj/unreachable_with_return.zig create mode 100644 test/compile_errors/stage1/obj/unsupported_modifier_at_start_of_asm_output_constraint.zig create mode 100644 test/compile_errors/stage1/obj/use_anyopaque_as_return_type_of_fn_ptr.zig create mode 100644 test/compile_errors/stage1/obj/use_implicit_casts_to_assign_null_to_non-nullable_pointer.zig create mode 100644 test/compile_errors/stage1/obj/use_invalid_number_literal_as_array_index.zig create mode 100644 test/compile_errors/stage1/obj/use_of_comptime-known_undefined_function_value.zig create mode 100644 test/compile_errors/stage1/obj/use_of_undeclared_identifier.zig create mode 100644 test/compile_errors/stage1/obj/using_an_unknown_len_ptr_type_instead_of_array.zig create mode 100644 test/compile_errors/stage1/obj/using_invalid_types_in_function_call_raises_an_error.zig create mode 100644 test/compile_errors/stage1/obj/usingnamespace_with_wrong_type.zig create mode 100644 test/compile_errors/stage1/obj/variable_has_wrong_type.zig create mode 100644 test/compile_errors/stage1/obj/variable_initialization_compile_error_then_referenced.zig create mode 100644 test/compile_errors/stage1/obj/variable_with_type_noreturn.zig create mode 100644 test/compile_errors/stage1/obj/vector_index_out_of_bounds.zig create mode 100644 test/compile_errors/stage1/obj/volatile_on_global_assembly.zig create mode 100644 test/compile_errors/stage1/obj/wasmMemoryGrow_is_a_compile_error_in_non-Wasm_targets.zig create mode 100644 test/compile_errors/stage1/obj/wasmMemorySize_is_a_compile_error_in_non-Wasm_targets.zig create mode 100644 test/compile_errors/stage1/obj/while_expected_bool_got_error_union.zig create mode 100644 test/compile_errors/stage1/obj/while_expected_bool_got_optional.zig create mode 100644 test/compile_errors/stage1/obj/while_expected_error_union_got_bool.zig create mode 100644 test/compile_errors/stage1/obj/while_expected_error_union_got_optional.zig create mode 100644 test/compile_errors/stage1/obj/while_expected_optional_got_bool.zig create mode 100644 test/compile_errors/stage1/obj/while_expected_optional_got_error_union.zig create mode 100644 test/compile_errors/stage1/obj/while_loop_body_expression_ignored.zig create mode 100644 test/compile_errors/stage1/obj/write_to_const_global_variable.zig create mode 100644 test/compile_errors/stage1/obj/wrong_frame_type_used_for_async_call.zig create mode 100644 test/compile_errors/stage1/obj/wrong_function_type.zig create mode 100644 test/compile_errors/stage1/obj/wrong_initializer_for_union_payload_of_type_type.zig create mode 100644 test/compile_errors/stage1/obj/wrong_number_of_arguments.zig create mode 100644 test/compile_errors/stage1/obj/wrong_number_of_arguments_for_method_fn_call.zig create mode 100644 test/compile_errors/stage1/obj/wrong_panic_signature_generic_function.zig create mode 100644 test/compile_errors/stage1/obj/wrong_panic_signature_runtime_function.zig create mode 100644 test/compile_errors/stage1/obj/wrong_pointer_coerced_to_pointer_to_opaque_{}.zig create mode 100644 test/compile_errors/stage1/obj/wrong_return_type_for_main.zig create mode 100644 test/compile_errors/stage1/obj/wrong_size_to_an_array_literal.zig create mode 100644 test/compile_errors/stage1/obj/wrong_type_for_argument_tuple_to_asyncCall.zig create mode 100644 test/compile_errors/stage1/obj/wrong_type_for_reify_type.zig create mode 100644 test/compile_errors/stage1/obj/wrong_type_for_result_ptr_to_asyncCall.zig create mode 100644 test/compile_errors/stage1/obj/wrong_type_passed_to_panic.zig create mode 100644 test/compile_errors/stage1/obj/wrong_type_to_hasField.zig create mode 100644 test/compile_errors/stage1/obj/wrong_types_given_to_atomic_order_args_in_cmpxchg.zig create mode 100644 test/compile_errors/stage1/obj/wrong_types_given_to_export.zig create mode 100644 test/compile_errors/stage1/test/access_invalid_typeInfo_decl.zig create mode 100644 test/compile_errors/stage1/test/alignCast_of_zero_sized_types.zig create mode 100644 test/compile_errors/stage1/test/bad_splat_type.zig create mode 100644 test/compile_errors/stage1/test/binary_OR_operator_on_error_sets.zig create mode 100644 test/compile_errors/stage1/test/call_rejects_non_comptime-known_fn-always_inline.zig create mode 100644 test/compile_errors/stage1/test/call_rejects_non_comptime-known_fn-compile_time.zig create mode 100644 test/compile_errors/stage1/test/cast_between_optional_T_where_T_is_not_a_pointer.zig create mode 100644 test/compile_errors/stage1/test/combination_of_nosuspend_and_async.zig create mode 100644 test/compile_errors/stage1/test/comparison_of_non-tagged_union_and_enum_literal.zig create mode 100644 test/compile_errors/stage1/test/comptime_vector_overflow_shows_the_index.zig create mode 100644 test/compile_errors/stage1/test/duplicate-unused_labels.zig create mode 100644 test/compile_errors/stage1/test/duplicate_field_in_anonymous_struct_literal.zig create mode 100644 test/compile_errors/stage1/test/error_in_struct_initializer_doesnt_crash_the_compiler.zig create mode 100644 test/compile_errors/stage1/test/errors_in_for_loop_bodies_are_propagated.zig create mode 100644 test/compile_errors/stage1/test/export_with_empty_name_string.zig create mode 100644 test/compile_errors/stage1/test/helpful_return_type_error_message.zig create mode 100644 test/compile_errors/stage1/test/int-float_conversion_to_comptime_int-float.zig create mode 100644 test/compile_errors/stage1/test/invalid_assignments.zig create mode 100644 test/compile_errors/stage1/test/invalid_float_casts.zig create mode 100644 test/compile_errors/stage1/test/invalid_int_casts.zig create mode 100644 test/compile_errors/stage1/test/invalid_non-exhaustive_enum_to_union.zig create mode 100644 test/compile_errors/stage1/test/invalid_pointer_with_reify_type.zig create mode 100644 test/compile_errors/stage1/test/nested_vectors.zig create mode 100644 test/compile_errors/stage1/test/non-exhaustive_enum_marker_assigned_a_value.zig create mode 100644 test/compile_errors/stage1/test/non-exhaustive_enums.zig create mode 100644 test/compile_errors/stage1/test/not_an_enum_type.zig create mode 100644 test/compile_errors/stage1/test/packed_struct_with_fields_of_not_allowed_types.zig create mode 100644 test/compile_errors/stage1/test/ptrToInt_with_pointer_to_zero-sized_type.zig create mode 100644 test/compile_errors/stage1/test/reassign_to_array_parameter.zig create mode 100644 test/compile_errors/stage1/test/reassign_to_slice_parameter.zig create mode 100644 test/compile_errors/stage1/test/reassign_to_struct_parameter.zig create mode 100644 test/compile_errors/stage1/test/reference_to_const_data.zig create mode 100644 test/compile_errors/stage1/test/reify_typeOf_with_incompatible_arguments.zig create mode 100644 test/compile_errors/stage1/test/reify_typeOf_with_no_arguments.zig create mode 100644 test/compile_errors/stage1/test/reject_extern_function_definitions_with_body.zig create mode 100644 test/compile_errors/stage1/test/reject_extern_variables_with_initializers.zig create mode 100644 test/compile_errors/stage1/test/repeated_invalid_field_access_to_generic_function_returning_type_crashes_compiler_2655.zig create mode 100644 test/compile_errors/stage1/test/return_invalid_type_from_test.zig create mode 100644 test/compile_errors/stage1/test/shift_on_type_with_non-power-of-two_size.zig create mode 100644 test/compile_errors/stage1/test/shuffle_with_selected_index_past_first_vector_length.zig create mode 100644 test/compile_errors/stage1/test/switch_ranges_endpoints_are_validated.zig create mode 100644 test/compile_errors/stage1/test/switching_with_exhaustive_enum_has___prong_.zig create mode 100644 test/compile_errors/stage1/test/switching_with_non-exhaustive_enums.zig create mode 100644 test/compile_errors/stage1/test/tagName_on_invalid_value_of_non-exhaustive_enum.zig create mode 100644 test/compile_errors/stage1/test/type_mismatch_in_C_prototype_with_varargs.zig create mode 100644 test/compile_errors/stage1/test/type_mismatch_with_tuple_concatenation.zig create mode 100644 test/compile_errors/stage1/test/unused_variable_error_on_errdefer.zig create mode 100644 test/compile_errors/stage2/embed_outside_package.zig create mode 100644 test/compile_errors/stage2/import_outside_package.zig create mode 100644 test/compile_errors/stage2/out_of_bounds_index.zig diff --git a/test/compile_errors.zig b/test/compile_errors.zig index e0d90e3ee2..14f32c150e 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -39,180 +39,6 @@ pub fn addCases(ctx: *TestContext) !void { try ctx.addErrorCasesFromDir("stage1", test_dir, .stage1, .Exe, true, one_test_case_per_file); } } - { - var case = ctx.obj("stage2 compile errors", .{}); - - case.addError( - \\export fn a() usize { - \\ return @embedFile("/root/foo").len; - \\} - , &[_][]const u8{ - ":2:23: error: embed of file outside package path: '/root/foo'", - }); - - case.addError( - \\export fn a() usize { - \\ return @import("../../above.zig").len; - \\} - , &[_][]const u8{ - ":2:20: error: import of file outside package path: '../../above.zig'", - }); - - case.addError( - \\comptime { - \\ var array = [_:0]u8{ 1, 2, 3, 4 }; - \\ var src_slice: [:0]u8 = &array; - \\ var slice = src_slice[2..6]; - \\ _ = slice; - \\} - \\comptime { - \\ var array = [_:0]u8{ 1, 2, 3, 4 }; - \\ var slice = array[2..6]; - \\ _ = slice; - \\} - \\comptime { - \\ var array = [_]u8{ 1, 2, 3, 4 }; - \\ var slice = array[2..5]; - \\ _ = slice; - \\} - \\comptime { - \\ var array = [_:0]u8{ 1, 2, 3, 4 }; - \\ var slice = array[3..2]; - \\ _ = slice; - \\} - , &[_][]const u8{ - ":4:26: error: end index 6 out of bounds for slice of length 4 +1 (sentinel)", - ":9:22: error: end index 6 out of bounds for array of length 4 +1 (sentinel)", - ":14:22: error: end index 5 out of bounds for array of length 4", - ":19:22: error: start index 3 is larger than end index 2", - }); - } - - ctx.objErrStage1("exported enum without explicit integer tag type", - \\const E = enum { one, two }; - \\comptime { - \\ @export(E, .{ .name = "E" }); - \\} - \\const e: E = .two; - \\comptime { - \\ @export(e, .{ .name = "e" }); - \\} - , &.{ - "tmp.zig:3:13: error: exported enum without explicit integer tag type", - "tmp.zig:7:13: error: exported enum value without explicit integer tag type", - }); - - ctx.objErrStage1("issue #9346: return outside of function scope", - \\pub const empty = return 1; - , &.{"tmp.zig:1:19: error: 'return' outside function scope"}); - - ctx.exeErrStage1("std.fmt error for unused arguments", - \\pub fn main() !void { - \\ @import("std").debug.print("{d} {d} {d} {d} {d}", .{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}); - \\} - , &.{ - "?:?:?: error: 10 unused arguments in '{d} {d} {d} {d} {d}'", - }); - - ctx.objErrStage1("lazy pointer with undefined element type", - \\export fn foo() void { - \\ comptime var T: type = undefined; - \\ const S = struct { x: *T }; - \\ const I = @typeInfo(S); - \\ _ = I; - \\} - , &[_][]const u8{ - ":3:28: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("pointer arithmetic on pointer-to-array", - \\export fn foo() void { - \\ var x: [10]u8 = undefined; - \\ var y = &x; - \\ var z = y + 1; - \\ _ = z; - \\} - , &[_][]const u8{ - "tmp.zig:4:17: error: integer value 1 cannot be coerced to type '*[10]u8'", - }); - - ctx.objErrStage1("pointer attributes checked when coercing pointer to anon literal", - \\comptime { - \\ const c: [][]const u8 = &.{"hello", "world" }; - \\ _ = c; - \\} - \\comptime { - \\ const c: *[2][]const u8 = &.{"hello", "world" }; - \\ _ = c; - \\} - \\const S = struct {a: u8 = 1, b: u32 = 2}; - \\comptime { - \\ const c: *S = &.{}; - \\ _ = c; - \\} - , &[_][]const u8{ - "tmp.zig:2:31: error: cannot cast pointer to array literal to slice type '[][]const u8'", - "tmp.zig:2:31: note: cast discards const qualifier", - "tmp.zig:6:33: error: cannot cast pointer to array literal to '*[2][]const u8'", - "tmp.zig:6:33: note: cast discards const qualifier", - "tmp.zig:11:21: error: expected type '*S', found '*const struct:11:21'", - "tmp.zig:11:21: note: cast discards const qualifier", - }); - - ctx.objErrStage1("@Type() union payload is undefined", - \\const Foo = @Type(.{ - \\ .Struct = undefined, - \\}); - \\comptime { _ = Foo; } - , &[_][]const u8{ - "tmp.zig:1:20: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("wrong initializer for union payload of type 'type'", - \\const U = union(enum) { - \\ A: type, - \\}; - \\const S = struct { - \\ u: U, - \\}; - \\export fn entry() void { - \\ comptime var v: S = undefined; - \\ v.u.A = U{ .A = i32 }; - \\} - , &[_][]const u8{ - "tmp.zig:9:8: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("union with too small explicit signed tag type", - \\const U = union(enum(i2)) { - \\ A: u8, - \\ B: u8, - \\ C: u8, - \\ D: u8, - \\}; - \\export fn entry() void { - \\ _ = U{ .D = 1 }; - \\} - , &[_][]const u8{ - "tmp.zig:1:22: error: specified integer tag type cannot represent every field", - "tmp.zig:1:22: note: type i2 cannot fit values in range 0...3", - }); - - ctx.objErrStage1("union with too small explicit unsigned tag type", - \\const U = union(enum(u2)) { - \\ A: u8, - \\ B: u8, - \\ C: u8, - \\ D: u8, - \\ E: u8, - \\}; - \\export fn entry() void { - \\ _ = U{ .E = 1 }; - \\} - , &[_][]const u8{ - "tmp.zig:1:22: error: specified integer tag type cannot represent every field", - "tmp.zig:1:22: note: type u2 cannot fit values in range 0...4", - }); { const case = ctx.obj("callconv(.Interrupt) on unsupported platform", .{ @@ -308,1550 +134,6 @@ pub fn addCases(ctx: *TestContext) !void { }); } - ctx.objErrStage1("unreachable executed at comptime", - \\fn foo(comptime x: i32) i32 { - \\ comptime { - \\ if (x >= 0) return -x; - \\ unreachable; - \\ } - \\} - \\export fn entry() void { - \\ _ = foo(-42); - \\} - , &[_][]const u8{ - "tmp.zig:4:9: error: reached unreachable code", - "tmp.zig:8:12: note: called from here", - }); - - ctx.objErrStage1("@Type with Type.Int", - \\const builtin = @import("std").builtin; - \\export fn entry() void { - \\ _ = @Type(builtin.Type.Int{ - \\ .signedness = .signed, - \\ .bits = 8, - \\ }); - \\} - , &[_][]const u8{ - "tmp.zig:3:31: error: expected type 'std.builtin.Type', found 'std.builtin.Type.Int'", - }); - - ctx.objErrStage1("indexing a undefined slice at comptime", - \\comptime { - \\ var slice: []u8 = undefined; - \\ slice[0] = 2; - \\} - , &[_][]const u8{ - "tmp.zig:3:10: error: index 0 outside slice of size 0", - }); - - ctx.objErrStage1("array in c exported function", - \\export fn zig_array(x: [10]u8) void { - \\ try std.testing.expect(std.mem.eql(u8, &x, "1234567890")); - \\} - \\const std = @import("std"); - \\export fn zig_return_array() [10]u8 { - \\ return "1234567890".*; - \\} - , &[_][]const u8{ - "tmp.zig:1:24: error: parameter of type '[10]u8' not allowed in function with calling convention 'C'", - "tmp.zig:5:30: error: return type '[10]u8' not allowed in function with calling convention 'C'", - }); - - ctx.objErrStage1("@Type for exhaustive enum with undefined tag type", - \\const Tag = @Type(.{ - \\ .Enum = .{ - \\ .layout = .Auto, - \\ .tag_type = undefined, - \\ .fields = &.{}, - \\ .decls = &.{}, - \\ .is_exhaustive = false, - \\ }, - \\}); - \\export fn entry() void { - \\ _ = @intToEnum(Tag, 0); - \\} - , &[_][]const u8{ - "tmp.zig:1:20: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("extern struct with non-extern-compatible integer tag type", - \\pub const E = enum(u31) { A, B, C }; - \\pub const S = extern struct { - \\ e: E, - \\}; - \\export fn entry() void { - \\ const s: S = undefined; - \\ _ = s; - \\} - , &[_][]const u8{ - "tmp.zig:3:5: error: extern structs cannot contain fields of type 'E'", - }); - - ctx.objErrStage1("@Type for exhaustive enum with non-integer tag type", - \\const Tag = @Type(.{ - \\ .Enum = .{ - \\ .layout = .Auto, - \\ .tag_type = bool, - \\ .fields = &.{}, - \\ .decls = &.{}, - \\ .is_exhaustive = false, - \\ }, - \\}); - \\export fn entry() void { - \\ _ = @intToEnum(Tag, 0); - \\} - , &[_][]const u8{ - "tmp.zig:1:20: error: Type.Enum.tag_type must be an integer type, not 'bool'", - }); - - ctx.objErrStage1("extern struct with extern-compatible but inferred integer tag type", - \\pub const E = enum { - \\@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12", - \\@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23", - \\@"24",@"25",@"26",@"27",@"28",@"29",@"30",@"31",@"32",@"33",@"34", - \\@"35",@"36",@"37",@"38",@"39",@"40",@"41",@"42",@"43",@"44",@"45", - \\@"46",@"47",@"48",@"49",@"50",@"51",@"52",@"53",@"54",@"55",@"56", - \\@"57",@"58",@"59",@"60",@"61",@"62",@"63",@"64",@"65",@"66",@"67", - \\@"68",@"69",@"70",@"71",@"72",@"73",@"74",@"75",@"76",@"77",@"78", - \\@"79",@"80",@"81",@"82",@"83",@"84",@"85",@"86",@"87",@"88",@"89", - \\@"90",@"91",@"92",@"93",@"94",@"95",@"96",@"97",@"98",@"99",@"100", - \\@"101",@"102",@"103",@"104",@"105",@"106",@"107",@"108",@"109", - \\@"110",@"111",@"112",@"113",@"114",@"115",@"116",@"117",@"118", - \\@"119",@"120",@"121",@"122",@"123",@"124",@"125",@"126",@"127", - \\@"128",@"129",@"130",@"131",@"132",@"133",@"134",@"135",@"136", - \\@"137",@"138",@"139",@"140",@"141",@"142",@"143",@"144",@"145", - \\@"146",@"147",@"148",@"149",@"150",@"151",@"152",@"153",@"154", - \\@"155",@"156",@"157",@"158",@"159",@"160",@"161",@"162",@"163", - \\@"164",@"165",@"166",@"167",@"168",@"169",@"170",@"171",@"172", - \\@"173",@"174",@"175",@"176",@"177",@"178",@"179",@"180",@"181", - \\@"182",@"183",@"184",@"185",@"186",@"187",@"188",@"189",@"190", - \\@"191",@"192",@"193",@"194",@"195",@"196",@"197",@"198",@"199", - \\@"200",@"201",@"202",@"203",@"204",@"205",@"206",@"207",@"208", - \\@"209",@"210",@"211",@"212",@"213",@"214",@"215",@"216",@"217", - \\@"218",@"219",@"220",@"221",@"222",@"223",@"224",@"225",@"226", - \\@"227",@"228",@"229",@"230",@"231",@"232",@"233",@"234",@"235", - \\@"236",@"237",@"238",@"239",@"240",@"241",@"242",@"243",@"244", - \\@"245",@"246",@"247",@"248",@"249",@"250",@"251",@"252",@"253", - \\@"254",@"255" - \\}; - \\pub const S = extern struct { - \\ e: E, - \\}; - \\export fn entry() void { - \\ if (@typeInfo(E).Enum.tag_type != u8) @compileError("did not infer u8 tag type"); - \\ const s: S = undefined; - \\ _ = s; - \\} - , &[_][]const u8{ - "tmp.zig:31:5: error: extern structs cannot contain fields of type 'E'", - }); - - ctx.objErrStage1("@Type for tagged union with extra enum field", - \\const Tag = @Type(.{ - \\ .Enum = .{ - \\ .layout = .Auto, - \\ .tag_type = u2, - \\ .fields = &.{ - \\ .{ .name = "signed", .value = 0 }, - \\ .{ .name = "unsigned", .value = 1 }, - \\ .{ .name = "arst", .value = 2 }, - \\ }, - \\ .decls = &.{}, - \\ .is_exhaustive = true, - \\ }, - \\}); - \\const Tagged = @Type(.{ - \\ .Union = .{ - \\ .layout = .Auto, - \\ .tag_type = Tag, - \\ .fields = &.{ - \\ .{ .name = "signed", .field_type = i32, .alignment = @alignOf(i32) }, - \\ .{ .name = "unsigned", .field_type = u32, .alignment = @alignOf(u32) }, - \\ }, - \\ .decls = &.{}, - \\ }, - \\}); - \\export fn entry() void { - \\ var tagged = Tagged{ .signed = -1 }; - \\ tagged = .{ .unsigned = 1 }; - \\} - , &[_][]const u8{ - "tmp.zig:14:23: error: enum field missing: 'arst'", - }); - - ctx.objErrStage1("field access of opaque type", - \\const MyType = opaque {}; - \\ - \\export fn entry() bool { - \\ var x: i32 = 1; - \\ return bar(@ptrCast(*MyType, &x)); - \\} - \\ - \\fn bar(x: *MyType) bool { - \\ return x.blah; - \\} - , &[_][]const u8{ - "tmp.zig:9:13: error: no member named 'blah' in opaque type 'MyType'", - }); - - ctx.objErrStage1("opaque type with field", - \\const Opaque = opaque { foo: i32 }; - \\export fn entry() void { - \\ const foo: ?*Opaque = null; - \\ _ = foo; - \\} - , &[_][]const u8{ - "tmp.zig:1:25: error: opaque types cannot have fields", - }); - - ctx.objErrStage1("@Type(.Fn) with is_generic = true", - \\const Foo = @Type(.{ - \\ .Fn = .{ - \\ .calling_convention = .Unspecified, - \\ .alignment = 0, - \\ .is_generic = true, - \\ .is_var_args = false, - \\ .return_type = u0, - \\ .args = &.{}, - \\ }, - \\}); - \\comptime { _ = Foo; } - , &[_][]const u8{ - "tmp.zig:1:20: error: Type.Fn.is_generic must be false for @Type", - }); - - ctx.objErrStage1("@Type(.Fn) with is_var_args = true and non-C callconv", - \\const Foo = @Type(.{ - \\ .Fn = .{ - \\ .calling_convention = .Unspecified, - \\ .alignment = 0, - \\ .is_generic = false, - \\ .is_var_args = true, - \\ .return_type = u0, - \\ .args = &.{}, - \\ }, - \\}); - \\comptime { _ = Foo; } - , &[_][]const u8{ - "tmp.zig:1:20: error: varargs functions must have C calling convention", - }); - - ctx.objErrStage1("@Type(.Fn) with return_type = null", - \\const Foo = @Type(.{ - \\ .Fn = .{ - \\ .calling_convention = .Unspecified, - \\ .alignment = 0, - \\ .is_generic = false, - \\ .is_var_args = false, - \\ .return_type = null, - \\ .args = &.{}, - \\ }, - \\}); - \\comptime { _ = Foo; } - , &[_][]const u8{ - "tmp.zig:1:20: error: Type.Fn.return_type must be non-null for @Type", - }); - - ctx.objErrStage1("@Type for union with opaque field", - \\const Untagged = @Type(.{ - \\ .Union = .{ - \\ .layout = .Auto, - \\ .tag_type = null, - \\ .fields = &.{ - \\ .{ .name = "foo", .field_type = opaque {}, .alignment = 1 }, - \\ }, - \\ .decls = &.{}, - \\ }, - \\}); - \\export fn entry() void { - \\ _ = Untagged{}; - \\} - , &[_][]const u8{ - "tmp.zig:1:25: error: opaque types have unknown size and therefore cannot be directly embedded in unions", - }); - - ctx.objErrStage1("slice sentinel mismatch", - \\export fn entry() void { - \\ const x = @import("std").meta.Vector(3, f32){ 25, 75, 5, 0 }; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:2:62: error: index 3 outside vector of size 3", - }); - - ctx.objErrStage1("slice sentinel mismatch", - \\export fn entry() void { - \\ const y: [:1]const u8 = &[_:2]u8{ 1, 2 }; - \\ _ = y; - \\} - , &[_][]const u8{ - "tmp.zig:2:37: error: expected type '[:1]const u8', found '*const [2:2]u8'", - }); - - ctx.objErrStage1("@Type for union with zero fields", - \\const Untagged = @Type(.{ - \\ .Union = .{ - \\ .layout = .Auto, - \\ .tag_type = null, - \\ .fields = &.{}, - \\ .decls = &.{}, - \\ }, - \\}); - \\export fn entry() void { - \\ _ = Untagged{}; - \\} - , &[_][]const u8{ - "tmp.zig:1:25: error: unions must have 1 or more fields", - }); - - ctx.objErrStage1("@Type for exhaustive enum with zero fields", - \\const Tag = @Type(.{ - \\ .Enum = .{ - \\ .layout = .Auto, - \\ .tag_type = u1, - \\ .fields = &.{}, - \\ .decls = &.{}, - \\ .is_exhaustive = true, - \\ }, - \\}); - \\export fn entry() void { - \\ _ = @intToEnum(Tag, 0); - \\} - , &[_][]const u8{ - "tmp.zig:1:20: error: enums must have 1 or more fields", - }); - - ctx.objErrStage1("@Type for tagged union with extra union field", - \\const Tag = @Type(.{ - \\ .Enum = .{ - \\ .layout = .Auto, - \\ .tag_type = u1, - \\ .fields = &.{ - \\ .{ .name = "signed", .value = 0 }, - \\ .{ .name = "unsigned", .value = 1 }, - \\ }, - \\ .decls = &.{}, - \\ .is_exhaustive = true, - \\ }, - \\}); - \\const Tagged = @Type(.{ - \\ .Union = .{ - \\ .layout = .Auto, - \\ .tag_type = Tag, - \\ .fields = &.{ - \\ .{ .name = "signed", .field_type = i32, .alignment = @alignOf(i32) }, - \\ .{ .name = "unsigned", .field_type = u32, .alignment = @alignOf(u32) }, - \\ .{ .name = "arst", .field_type = f32, .alignment = @alignOf(f32) }, - \\ }, - \\ .decls = &.{}, - \\ }, - \\}); - \\export fn entry() void { - \\ var tagged = Tagged{ .signed = -1 }; - \\ tagged = .{ .unsigned = 1 }; - \\} - , &[_][]const u8{ - "tmp.zig:13:23: error: enum field not found: 'arst'", - "tmp.zig:1:20: note: enum declared here", - }); - - ctx.objErrStage1("@Type with undefined", - \\comptime { - \\ _ = @Type(.{ .Array = .{ .len = 0, .child = u8, .sentinel = undefined } }); - \\} - \\comptime { - \\ _ = @Type(.{ - \\ .Struct = .{ - \\ .fields = undefined, - \\ .decls = undefined, - \\ .is_tuple = false, - \\ .layout = .Auto, - \\ }, - \\ }); - \\} - , &[_][]const u8{ - "tmp.zig:2:16: error: use of undefined value here causes undefined behavior", - "tmp.zig:5:16: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("struct with declarations unavailable for @Type", - \\export fn entry() void { - \\ _ = @Type(@typeInfo(struct { const foo = 1; })); - \\} - , &[_][]const u8{ - "tmp.zig:2:15: error: Type.Struct.decls must be empty for @Type", - }); - - ctx.objErrStage1("enum with declarations unavailable for @Type", - \\export fn entry() void { - \\ _ = @Type(@typeInfo(enum { foo, const bar = 1; })); - \\} - , &[_][]const u8{ - "tmp.zig:2:15: error: Type.Enum.decls must be empty for @Type", - }); - - ctx.testErrStage1("reject extern variables with initializers", - \\extern var foo: int = 2; - , &[_][]const u8{ - "tmp.zig:1:23: error: extern variables have no initializers", - }); - - ctx.testErrStage1("duplicate/unused labels", - \\comptime { - \\ blk: { blk: while (false) {} } - \\} - \\comptime { - \\ blk: while (false) { blk: for (@as([0]void, undefined)) |_| {} } - \\} - \\comptime { - \\ blk: for (@as([0]void, undefined)) |_| { blk: {} } - \\} - \\comptime { - \\ blk: {} - \\} - \\comptime { - \\ blk: while(false) {} - \\} - \\comptime { - \\ blk: for(@as([0]void, undefined)) |_| {} - \\} - , &[_][]const u8{ - "tmp.zig:2:12: error: redefinition of label 'blk'", - "tmp.zig:2:5: note: previous definition here", - "tmp.zig:5:26: error: redefinition of label 'blk'", - "tmp.zig:5:5: note: previous definition here", - "tmp.zig:8:46: error: redefinition of label 'blk'", - "tmp.zig:8:5: note: previous definition here", - "tmp.zig:11:5: error: unused block label", - "tmp.zig:14:5: error: unused while loop label", - "tmp.zig:17:5: error: unused for loop label", - }); - - ctx.testErrStage1("@alignCast of zero sized types", - \\export fn foo() void { - \\ const a: *void = undefined; - \\ _ = @alignCast(2, a); - \\} - \\export fn bar() void { - \\ const a: ?*void = undefined; - \\ _ = @alignCast(2, a); - \\} - \\export fn baz() void { - \\ const a: []void = undefined; - \\ _ = @alignCast(2, a); - \\} - \\export fn qux() void { - \\ const a = struct { - \\ fn a(comptime b: u32) void { _ = b; } - \\ }.a; - \\ _ = @alignCast(2, a); - \\} - , &[_][]const u8{ - "tmp.zig:3:23: error: cannot adjust alignment of zero sized type '*void'", - "tmp.zig:7:23: error: cannot adjust alignment of zero sized type '?*void'", - "tmp.zig:11:23: error: cannot adjust alignment of zero sized type '[]void'", - "tmp.zig:17:23: error: cannot adjust alignment of zero sized type 'fn(u32) anytype'", - }); - - ctx.testErrStage1("invalid non-exhaustive enum to union", - \\const E = enum(u8) { - \\ a, - \\ b, - \\ _, - \\}; - \\const U = union(E) { - \\ a, - \\ b, - \\}; - \\export fn foo() void { - \\ var e = @intToEnum(E, 15); - \\ var u: U = e; - \\ _ = u; - \\} - \\export fn bar() void { - \\ const e = @intToEnum(E, 15); - \\ var u: U = e; - \\ _ = u; - \\} - , &[_][]const u8{ - "tmp.zig:12:16: error: runtime cast to union 'U' from non-exhaustive enum", - "tmp.zig:17:16: error: no tag by value 15", - }); - - ctx.testErrStage1("switching with exhaustive enum has '_' prong ", - \\const E = enum{ - \\ a, - \\ b, - \\}; - \\pub export fn entry() void { - \\ var e: E = .b; - \\ switch (e) { - \\ .a => {}, - \\ .b => {}, - \\ _ => {}, - \\ } - \\} - , &[_][]const u8{ - "tmp.zig:7:5: error: switch on exhaustive enum has `_` prong", - }); - - ctx.testErrStage1("invalid pointer with @Type", - \\export fn entry() void { - \\ _ = @Type(.{ .Pointer = .{ - \\ .size = .One, - \\ .is_const = false, - \\ .is_volatile = false, - \\ .alignment = 1, - \\ .address_space = .generic, - \\ .child = u8, - \\ .is_allowzero = false, - \\ .sentinel = &@as(u8, 0), - \\ }}); - \\} - , &[_][]const u8{ - "tmp.zig:2:16: error: sentinels are only allowed on slices and unknown-length pointers", - }); - - ctx.objErrStage1("@Type(.Pointer) with invalid address space ", - \\export fn entry() void { - \\ _ = @Type(.{ .Pointer = .{ - \\ .size = .One, - \\ .is_const = false, - \\ .is_volatile = false, - \\ .alignment = 1, - \\ .address_space = .gs, - \\ .child = u8, - \\ .is_allowzero = false, - \\ .sentinel = null, - \\ }}); - \\} - , &[_][]const u8{ - "tmp.zig:2:16: error: address space 'gs' not available in stage 1 compiler, must be .generic", - }); - - ctx.testErrStage1("helpful return type error message", - \\export fn foo() u32 { - \\ return error.Ohno; - \\} - \\fn bar() !u32 { - \\ return error.Ohno; - \\} - \\export fn baz() void { - \\ try bar(); - \\} - \\export fn qux() u32 { - \\ return bar(); - \\} - \\export fn quux() u32 { - \\ var buf: u32 = 0; - \\ buf = bar(); - \\} - , &[_][]const u8{ - "tmp.zig:2:17: error: expected type 'u32', found 'error{Ohno}'", - "tmp.zig:1:17: note: function cannot return an error", - "tmp.zig:8:5: error: expected type 'void', found '@typeInfo(@typeInfo(@TypeOf(bar)).Fn.return_type.?).ErrorUnion.error_set'", - "tmp.zig:7:17: note: function cannot return an error", - "tmp.zig:11:15: error: cannot convert error union to payload type. consider using `try`, `catch`, or `if`. expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(bar)).Fn.return_type.?).ErrorUnion.error_set!u32'", - "tmp.zig:10:17: note: function cannot return an error", - "tmp.zig:15:14: error: cannot convert error union to payload type. consider using `try`, `catch`, or `if`. expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(bar)).Fn.return_type.?).ErrorUnion.error_set!u32'", - "tmp.zig:14:5: note: cannot store an error in type 'u32'", - }); - - ctx.testErrStage1("int/float conversion to comptime_int/float", - \\export fn foo() void { - \\ var a: f32 = 2; - \\ _ = @floatToInt(comptime_int, a); - \\} - \\export fn bar() void { - \\ var a: u32 = 2; - \\ _ = @intToFloat(comptime_float, a); - \\} - , &[_][]const u8{ - "tmp.zig:3:35: error: unable to evaluate constant expression", - "tmp.zig:7:37: error: unable to evaluate constant expression", - }); - - ctx.objErrStage1("extern variable has no type", - \\extern var foo; - \\pub export fn entry() void { - \\ foo; - \\} - , &[_][]const u8{ - "tmp.zig:1:8: error: unable to infer variable type", - }); - - ctx.objErrStage1("@src outside function", - \\comptime { - \\ @src(); - \\} - , &[_][]const u8{ - "tmp.zig:2:5: error: @src outside function", - }); - - ctx.objErrStage1("call assigned to constant", - \\const Foo = struct { - \\ x: i32, - \\}; - \\fn foo() Foo { - \\ return .{ .x = 42 }; - \\} - \\fn bar(val: anytype) Foo { - \\ return .{ .x = val }; - \\} - \\export fn entry() void { - \\ const baz: Foo = undefined; - \\ baz = foo(); - \\} - \\export fn entry1() void { - \\ const baz: Foo = undefined; - \\ baz = bar(42); - \\} - , &[_][]const u8{ - "tmp.zig:12:14: error: cannot assign to constant", - "tmp.zig:16:14: error: cannot assign to constant", - }); - - ctx.objErrStage1("invalid pointer syntax", - \\export fn foo() void { - \\ var guid: *:0 const u8 = undefined; - \\} - , &[_][]const u8{ - "tmp.zig:2:16: error: expected type expression, found ':'", - }); - - ctx.objErrStage1("declaration between fields", - \\const S = struct { - \\ const foo = 2; - \\ const bar = 2; - \\ const baz = 2; - \\ a: struct { - \\ a: u32, - \\ b: u32, - \\ }, - \\ const foo1 = 2; - \\ const bar1 = 2; - \\ const baz1 = 2; - \\ b: usize, - \\}; - \\comptime { - \\ _ = S; - \\} - , &[_][]const u8{ - "tmp.zig:9:5: error: declarations are not allowed between container fields", - "tmp.zig:5:5: note: field before declarations here", - "tmp.zig:12:5: note: field after declarations here", - }); - - ctx.objErrStage1("non-extern function with var args", - \\fn foo(args: ...) void {} - \\export fn entry() void { - \\ foo(); - \\} - , &[_][]const u8{ - "tmp.zig:1:14: error: expected type expression, found '...'", - }); - - ctx.testErrStage1("invalid int casts", - \\export fn foo() void { - \\ var a: u32 = 2; - \\ _ = @intCast(comptime_int, a); - \\} - \\export fn bar() void { - \\ var a: u32 = 2; - \\ _ = @intToFloat(u32, a); - \\} - \\export fn baz() void { - \\ var a: u32 = 2; - \\ _ = @floatToInt(u32, a); - \\} - \\export fn qux() void { - \\ var a: f32 = 2; - \\ _ = @intCast(u32, a); - \\} - , &[_][]const u8{ - "tmp.zig:3:32: error: unable to evaluate constant expression", - "tmp.zig:7:21: error: expected float type, found 'u32'", - "tmp.zig:11:26: error: expected float type, found 'u32'", - "tmp.zig:15:23: error: expected integer type, found 'f32'", - }); - - ctx.testErrStage1("invalid float casts", - \\export fn foo() void { - \\ var a: f32 = 2; - \\ _ = @floatCast(comptime_float, a); - \\} - \\export fn bar() void { - \\ var a: f32 = 2; - \\ _ = @floatToInt(f32, a); - \\} - \\export fn baz() void { - \\ var a: f32 = 2; - \\ _ = @intToFloat(f32, a); - \\} - \\export fn qux() void { - \\ var a: u32 = 2; - \\ _ = @floatCast(f32, a); - \\} - , &[_][]const u8{ - "tmp.zig:3:36: error: unable to evaluate constant expression", - "tmp.zig:7:21: error: expected integer type, found 'f32'", - "tmp.zig:11:26: error: expected int type, found 'f32'", - "tmp.zig:15:25: error: expected float type, found 'u32'", - }); - - ctx.testErrStage1("invalid assignments", - \\export fn entry1() void { - \\ var a: []const u8 = "foo"; - \\ a[0..2] = "bar"; - \\} - \\export fn entry2() void { - \\ var a: u8 = 2; - \\ a + 2 = 3; - \\} - \\export fn entry4() void { - \\ 2 + 2 = 3; - \\} - , &[_][]const u8{ - "tmp.zig:3:6: error: invalid left-hand side to assignment", - "tmp.zig:7:7: error: invalid left-hand side to assignment", - "tmp.zig:10:7: error: invalid left-hand side to assignment", - }); - - ctx.testErrStage1("reassign to array parameter", - \\fn reassign(a: [3]f32) void { - \\ a = [3]f32{4, 5, 6}; - \\} - \\export fn entry() void { - \\ reassign(.{1, 2, 3}); - \\} - , &[_][]const u8{ - "tmp.zig:2:15: error: cannot assign to constant", - }); - - ctx.testErrStage1("reassign to slice parameter", - \\pub fn reassign(s: []const u8) void { - \\ s = s[0..]; - \\} - \\export fn entry() void { - \\ reassign("foo"); - \\} - , &[_][]const u8{ - "tmp.zig:2:10: error: cannot assign to constant", - }); - - ctx.testErrStage1("reassign to struct parameter", - \\const S = struct { - \\ x: u32, - \\}; - \\fn reassign(s: S) void { - \\ s = S{.x = 2}; - \\} - \\export fn entry() void { - \\ reassign(S{.x = 3}); - \\} - , &[_][]const u8{ - "tmp.zig:5:10: error: cannot assign to constant", - }); - - ctx.testErrStage1("reference to const data", - \\export fn foo() void { - \\ var ptr = &[_]u8{0,0,0,0}; - \\ ptr[1] = 2; - \\} - \\export fn bar() void { - \\ var ptr = &@as(u32, 2); - \\ ptr.* = 2; - \\} - \\export fn baz() void { - \\ var ptr = &true; - \\ ptr.* = false; - \\} - \\export fn qux() void { - \\ const S = struct{ - \\ x: usize, - \\ y: usize, - \\ }; - \\ var ptr = &S{.x=1,.y=2}; - \\ ptr.x = 2; - \\} - , &[_][]const u8{ - "tmp.zig:3:14: error: cannot assign to constant", - "tmp.zig:7:13: error: cannot assign to constant", - "tmp.zig:11:13: error: cannot assign to constant", - "tmp.zig:19:13: error: cannot assign to constant", - }); - - ctx.testErrStage1("cast between ?T where T is not a pointer", - \\pub const fnty1 = ?fn (i8) void; - \\pub const fnty2 = ?fn (u64) void; - \\export fn entry() void { - \\ var a: fnty1 = undefined; - \\ var b: fnty2 = undefined; - \\ a = b; - \\} - , &[_][]const u8{ - "tmp.zig:6:9: error: expected type '?fn(i8) void', found '?fn(u64) void'", - "tmp.zig:6:9: note: optional type child 'fn(u64) void' cannot cast into optional type child 'fn(i8) void'", - }); - - ctx.testErrStage1("unused variable error on errdefer", - \\fn foo() !void { - \\ errdefer |a| unreachable; - \\ return error.A; - \\} - \\export fn entry() void { - \\ foo() catch unreachable; - \\} - , &[_][]const u8{ - "tmp.zig:2:15: error: unused variable: 'a'", - }); - - ctx.testErrStage1("comparison of non-tagged union and enum literal", - \\export fn entry() void { - \\ const U = union { A: u32, B: u64 }; - \\ var u = U{ .A = 42 }; - \\ var ok = u == .A; - \\ _ = ok; - \\} - , &[_][]const u8{ - "tmp.zig:4:16: error: comparison of union and enum literal is only valid for tagged union types", - "tmp.zig:2:15: note: type U is not a tagged union", - }); - - ctx.testErrStage1("shift on type with non-power-of-two size", - \\export fn entry() void { - \\ const S = struct { - \\ fn a() void { - \\ var x: u24 = 42; - \\ _ = x >> 24; - \\ } - \\ fn b() void { - \\ var x: u24 = 42; - \\ _ = x << 24; - \\ } - \\ fn c() void { - \\ var x: u24 = 42; - \\ _ = @shlExact(x, 24); - \\ } - \\ fn d() void { - \\ var x: u24 = 42; - \\ _ = @shrExact(x, 24); - \\ } - \\ }; - \\ S.a(); - \\ S.b(); - \\ S.c(); - \\ S.d(); - \\} - , &[_][]const u8{ - "tmp.zig:5:19: error: RHS of shift is too large for LHS type", - "tmp.zig:9:19: error: RHS of shift is too large for LHS type", - "tmp.zig:13:17: error: RHS of shift is too large for LHS type", - "tmp.zig:17:17: error: RHS of shift is too large for LHS type", - }); - - ctx.testErrStage1("combination of nosuspend and async", - \\export fn entry() void { - \\ nosuspend { - \\ const bar = async foo(); - \\ suspend {} - \\ resume bar; - \\ } - \\} - \\fn foo() void {} - , &[_][]const u8{ - "tmp.zig:4:9: error: suspend inside nosuspend block", - "tmp.zig:2:5: note: nosuspend block here", - }); - - ctx.objErrStage1("atomicrmw with bool op not .Xchg", - \\export fn entry() void { - \\ var x = false; - \\ _ = @atomicRmw(bool, &x, .Add, true, .SeqCst); - \\} - , &[_][]const u8{ - "tmp.zig:3:30: error: @atomicRmw with bool only allowed with .Xchg", - }); - - ctx.testErrStage1("@TypeOf with no arguments", - \\export fn entry() void { - \\ _ = @TypeOf(); - \\} - , &[_][]const u8{ - "tmp.zig:2:9: error: expected at least 1 argument, found 0", - }); - - ctx.testErrStage1("@TypeOf with incompatible arguments", - \\export fn entry() void { - \\ var var_1: f32 = undefined; - \\ var var_2: u32 = undefined; - \\ _ = @TypeOf(var_1, var_2); - \\} - , &[_][]const u8{ - "tmp.zig:4:9: error: incompatible types: 'f32' and 'u32'", - }); - - ctx.testErrStage1("type mismatch with tuple concatenation", - \\export fn entry() void { - \\ var x = .{}; - \\ x = x ++ .{ 1, 2, 3 }; - \\} - , &[_][]const u8{ - "tmp.zig:3:11: error: expected type 'struct:2:14', found 'struct:3:11'", - }); - - ctx.testErrStage1("@tagName on invalid value of non-exhaustive enum", - \\test "enum" { - \\ const E = enum(u8) {A, B, _}; - \\ _ = @tagName(@intToEnum(E, 5)); - \\} - , &[_][]const u8{ - "tmp.zig:3:18: error: no tag by value 5", - }); - - ctx.testErrStage1("@ptrToInt with pointer to zero-sized type", - \\export fn entry() void { - \\ var pointer: ?*u0 = null; - \\ var x = @ptrToInt(pointer); - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:3:23: error: pointer to size 0 type has no address", - }); - - ctx.testErrStage1("access invalid @typeInfo decl", - \\const A = B; - \\test "Crash" { - \\ _ = @typeInfo(@This()).Struct.decls[0]; - \\} - , &[_][]const u8{ - "tmp.zig:1:11: error: use of undeclared identifier 'B'", - }); - - ctx.testErrStage1("reject extern function definitions with body", - \\extern "c" fn definitelyNotInLibC(a: i32, b: i32) i32 { - \\ return a + b; - \\} - , &[_][]const u8{ - "tmp.zig:1:1: error: extern functions have no body", - }); - - ctx.testErrStage1("duplicate field in anonymous struct literal", - \\export fn entry() void { - \\ const anon = .{ - \\ .inner = .{ - \\ .a = .{ - \\ .something = "text", - \\ }, - \\ .a = .{}, - \\ }, - \\ }; - \\ _ = anon; - \\} - , &[_][]const u8{ - "tmp.zig:7:13: error: duplicate field", - "tmp.zig:4:13: note: other field here", - }); - - ctx.testErrStage1("type mismatch in C prototype with varargs", - \\const fn_ty = ?fn ([*c]u8, ...) callconv(.C) void; - \\extern fn fn_decl(fmt: [*:0]u8, ...) void; - \\ - \\export fn main() void { - \\ const x: fn_ty = fn_decl; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:5:22: error: expected type 'fn([*c]u8, ...) callconv(.C) void', found 'fn([*:0]u8, ...) callconv(.C) void'", - }); - - ctx.objErrStage1("function call assigned to incorrect type", - \\export fn entry() void { - \\ var arr: [4]f32 = undefined; - \\ arr = concat(); - \\} - \\fn concat() [16]f32 { - \\ return [1]f32{0}**16; - \\} - , &[_][]const u8{ - "tmp.zig:3:17: error: expected type '[4]f32', found '[16]f32'", - }); - - ctx.objErrStage1("generic function call assigned to incorrect type", - \\pub export fn entry() void { - \\ var res: []i32 = undefined; - \\ res = myAlloc(i32); - \\} - \\fn myAlloc(comptime arg: type) anyerror!arg{ - \\ unreachable; - \\} - , &[_][]const u8{ - "tmp.zig:3:18: error: expected type '[]i32', found 'anyerror!i32", - }); - - ctx.testErrStage1("non-exhaustive enum marker assigned a value", - \\const A = enum { - \\ a, - \\ b, - \\ _ = 1, - \\}; - \\const B = enum { - \\ a, - \\ b, - \\ _, - \\}; - \\comptime { _ = A; _ = B; } - , &[_][]const u8{ - "tmp.zig:4:9: error: '_' is used to mark an enum as non-exhaustive and cannot be assigned a value", - "tmp.zig:6:11: error: non-exhaustive enum missing integer tag type", - "tmp.zig:9:5: note: marked non-exhaustive here", - }); - - ctx.testErrStage1("non-exhaustive enums", - \\const B = enum(u1) { - \\ a, - \\ _, - \\ b, - \\}; - \\const C = enum(u1) { - \\ a, - \\ b, - \\ _, - \\}; - \\pub export fn entry() void { - \\ _ = B; - \\ _ = C; - \\} - , &[_][]const u8{ - "tmp.zig:3:5: error: '_' field of non-exhaustive enum must be last", - "tmp.zig:6:11: error: non-exhaustive enum specifies every value", - }); - - ctx.testErrStage1("switching with non-exhaustive enums", - \\const E = enum(u8) { - \\ a, - \\ b, - \\ _, - \\}; - \\const U = union(E) { - \\ a: i32, - \\ b: u32, - \\}; - \\pub export fn entry() void { - \\ var e: E = .b; - \\ switch (e) { // error: switch not handling the tag `b` - \\ .a => {}, - \\ _ => {}, - \\ } - \\ switch (e) { // error: switch on non-exhaustive enum must include `else` or `_` prong - \\ .a => {}, - \\ .b => {}, - \\ } - \\ var u = U{.a = 2}; - \\ switch (u) { // error: `_` prong not allowed when switching on tagged union - \\ .a => {}, - \\ .b => {}, - \\ _ => {}, - \\ } - \\} - , &[_][]const u8{ - "tmp.zig:12:5: error: enumeration value 'E.b' not handled in switch", - "tmp.zig:16:5: error: switch on non-exhaustive enum must include `else` or `_` prong", - "tmp.zig:21:5: error: `_` prong not allowed when switching on tagged union", - }); - - ctx.objErrStage1("switch expression - unreachable else prong (bool)", - \\fn foo(x: bool) void { - \\ switch (x) { - \\ true => {}, - \\ false => {}, - \\ else => {}, - \\ } - \\} - \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } - , &[_][]const u8{ - "tmp.zig:5:9: error: unreachable else prong, all cases already handled", - }); - - ctx.objErrStage1("switch expression - unreachable else prong (u1)", - \\fn foo(x: u1) void { - \\ switch (x) { - \\ 0 => {}, - \\ 1 => {}, - \\ else => {}, - \\ } - \\} - \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } - , &[_][]const u8{ - "tmp.zig:5:9: error: unreachable else prong, all cases already handled", - }); - - ctx.objErrStage1("switch expression - unreachable else prong (u2)", - \\fn foo(x: u2) void { - \\ switch (x) { - \\ 0 => {}, - \\ 1 => {}, - \\ 2 => {}, - \\ 3 => {}, - \\ else => {}, - \\ } - \\} - \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } - , &[_][]const u8{ - "tmp.zig:7:9: error: unreachable else prong, all cases already handled", - }); - - ctx.objErrStage1("switch expression - unreachable else prong (range u8)", - \\fn foo(x: u8) void { - \\ switch (x) { - \\ 0 => {}, - \\ 1 => {}, - \\ 2 => {}, - \\ 3 => {}, - \\ 4...255 => {}, - \\ else => {}, - \\ } - \\} - \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } - , &[_][]const u8{ - "tmp.zig:8:9: error: unreachable else prong, all cases already handled", - }); - - ctx.objErrStage1("switch expression - unreachable else prong (range i8)", - \\fn foo(x: i8) void { - \\ switch (x) { - \\ -128...0 => {}, - \\ 1 => {}, - \\ 2 => {}, - \\ 3 => {}, - \\ 4...127 => {}, - \\ else => {}, - \\ } - \\} - \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } - , &[_][]const u8{ - "tmp.zig:8:9: error: unreachable else prong, all cases already handled", - }); - - ctx.objErrStage1("switch expression - unreachable else prong (enum)", - \\const TestEnum = enum{ T1, T2 }; - \\ - \\fn err(x: u8) TestEnum { - \\ switch (x) { - \\ 0 => return TestEnum.T1, - \\ else => return TestEnum.T2, - \\ } - \\} - \\ - \\fn foo(x: u8) void { - \\ switch (err(x)) { - \\ TestEnum.T1 => {}, - \\ TestEnum.T2 => {}, - \\ else => {}, - \\ } - \\} - \\ - \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } - , &[_][]const u8{ - "tmp.zig:14:9: error: unreachable else prong, all cases already handled", - }); - - ctx.testErrStage1("@export with empty name string", - \\pub export fn entry() void { } - \\comptime { - \\ @export(entry, .{ .name = "" }); - \\} - , &[_][]const u8{ - "tmp.zig:3:5: error: exported symbol name cannot be empty", - }); - - ctx.testErrStage1("switch ranges endpoints are validated", - \\pub export fn entry() void { - \\ var x: i32 = 0; - \\ switch (x) { - \\ 6...1 => {}, - \\ -1...-5 => {}, - \\ else => unreachable, - \\ } - \\} - , &[_][]const u8{ - "tmp.zig:4:9: error: range start value is greater than the end value", - "tmp.zig:5:9: error: range start value is greater than the end value", - }); - - ctx.testErrStage1("errors in for loop bodies are propagated", - \\pub export fn entry() void { - \\ var arr: [100]u8 = undefined; - \\ for (arr) |bits| _ = @popCount(bits); - \\} - , &[_][]const u8{ - "tmp.zig:3:26: error: expected 2 arguments, found 1", - }); - - ctx.testErrStage1("@call rejects non comptime-known fn - always_inline", - \\pub export fn entry() void { - \\ var call_me: fn () void = undefined; - \\ @call(.{ .modifier = .always_inline }, call_me, .{}); - \\} - , &[_][]const u8{ - "tmp.zig:3:5: error: the specified modifier requires a comptime-known function", - }); - - ctx.testErrStage1("@call rejects non comptime-known fn - compile_time", - \\pub export fn entry() void { - \\ var call_me: fn () void = undefined; - \\ @call(.{ .modifier = .compile_time }, call_me, .{}); - \\} - , &[_][]const u8{ - "tmp.zig:3:5: error: the specified modifier requires a comptime-known function", - }); - - ctx.testErrStage1("error in struct initializer doesn't crash the compiler", - \\pub export fn entry() void { - \\ const bitfield = struct { - \\ e: u8, - \\ e: u8, - \\ }; - \\ var a = .{@sizeOf(bitfield)}; - \\ _ = a; - \\} - , &[_][]const u8{ - "tmp.zig:4:9: error: duplicate struct field: 'e'", - }); - - ctx.testErrStage1("repeated invalid field access to generic function returning type crashes compiler. #2655", - \\pub fn A() type { - \\ return Q; - \\} - \\test "1" { - \\ _ = A().a; - \\ _ = A().a; - \\} - , &[_][]const u8{ - "tmp.zig:2:12: error: use of undeclared identifier 'Q'", - }); - - ctx.objErrStage1("bitCast to enum type", - \\export fn entry() void { - \\ const y = @bitCast(enum(u32) { a, b }, @as(u32, 3)); - \\ _ = y; - \\} - , &[_][]const u8{ - "tmp.zig:2:24: error: cannot cast a value of type 'y'", - }); - - ctx.objErrStage1("comparing against undefined produces undefined value", - \\export fn entry() void { - \\ if (2 == undefined) {} - \\} - , &[_][]const u8{ - "tmp.zig:2:11: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("comptime ptrcast of zero-sized type", - \\fn foo() void { - \\ const node: struct {} = undefined; - \\ const vla_ptr = @ptrCast([*]const u8, &node); - \\ _ = vla_ptr; - \\} - \\comptime { foo(); } - , &[_][]const u8{ - "tmp.zig:3:21: error: '*const struct:2:17' and '[*]const u8' do not have the same in-memory representation", - }); - - ctx.objErrStage1("slice sentinel mismatch", - \\fn foo() [:0]u8 { - \\ var x: []u8 = undefined; - \\ return x; - \\} - \\comptime { _ = foo; } - , &[_][]const u8{ - "tmp.zig:3:12: error: expected type '[:0]u8', found '[]u8'", - "tmp.zig:3:12: note: destination pointer requires a terminating '0' sentinel", - }); - - ctx.objErrStage1("cmpxchg with float", - \\export fn entry() void { - \\ var x: f32 = 0; - \\ _ = @cmpxchgWeak(f32, &x, 1, 2, .SeqCst, .SeqCst); - \\} - , &[_][]const u8{ - "tmp.zig:3:22: error: expected bool, integer, enum or pointer type, found 'f32'", - }); - - ctx.objErrStage1("atomicrmw with float op not .Xchg, .Add or .Sub", - \\export fn entry() void { - \\ var x: f32 = 0; - \\ _ = @atomicRmw(f32, &x, .And, 2, .SeqCst); - \\} - , &[_][]const u8{ - "tmp.zig:3:29: error: @atomicRmw with float only allowed with .Xchg, .Add and .Sub", - }); - - ctx.objErrStage1("intToPtr with misaligned address", - \\pub fn main() void { - \\ var y = @intToPtr([*]align(4) u8, 5); - \\ _ = y; - \\} - , &[_][]const u8{ - "tmp.zig:2:13: error: pointer type '[*]align(4) u8' requires aligned address", - }); - - ctx.objErrStage1("invalid float literal", - \\const std = @import("std"); - \\ - \\pub fn main() void { - \\ var bad_float :f32 = 0.0; - \\ bad_float = bad_float + .20; - \\ std.debug.assert(bad_float < 1.0); - \\} - , &[_][]const u8{ - "tmp.zig:5:29: error: expected expression, found '.'", - }); - - ctx.objErrStage1("invalid exponent in float literal - 1", - \\fn main() void { - \\ var bad: f128 = 0x1.0p1ab1; - \\ _ = bad; - \\} - , &[_][]const u8{ - "tmp.zig:2:21: error: expected expression, found 'invalid bytes'", - "tmp.zig:2:28: note: invalid byte: 'a'", - }); - - ctx.objErrStage1("invalid exponent in float literal - 2", - \\fn main() void { - \\ var bad: f128 = 0x1.0p50F; - \\ _ = bad; - \\} - , &[_][]const u8{ - "tmp.zig:2:21: error: expected expression, found 'invalid bytes'", - "tmp.zig:2:29: note: invalid byte: 'F'", - }); - - ctx.objErrStage1("invalid underscore placement in float literal - 1", - \\fn main() void { - \\ var bad: f128 = 0._0; - \\ _ = bad; - \\} - , &[_][]const u8{ - "tmp.zig:2:21: error: expected expression, found 'invalid bytes'", - "tmp.zig:2:23: note: invalid byte: '_'", - }); - - ctx.objErrStage1("invalid underscore placement in float literal - 2", - \\fn main() void { - \\ var bad: f128 = 0_.0; - \\ _ = bad; - \\} - , &[_][]const u8{ - "tmp.zig:2:21: error: expected expression, found 'invalid bytes'", - "tmp.zig:2:23: note: invalid byte: '.'", - }); - - ctx.objErrStage1("invalid underscore placement in float literal - 3", - \\fn main() void { - \\ var bad: f128 = 0.0_; - \\ _ = bad; - \\} - , &[_][]const u8{ - "tmp.zig:2:21: error: expected expression, found 'invalid bytes'", - "tmp.zig:2:25: note: invalid byte: ';'", - }); - - ctx.objErrStage1("invalid underscore placement in float literal - 4", - \\fn main() void { - \\ var bad: f128 = 1.0e_1; - \\ _ = bad; - \\} - , &[_][]const u8{ - "tmp.zig:2:21: error: expected expression, found 'invalid bytes'", - "tmp.zig:2:25: note: invalid byte: '_'", - }); - - ctx.objErrStage1("invalid underscore placement in float literal - 5", - \\fn main() void { - \\ var bad: f128 = 1.0e+_1; - \\ _ = bad; - \\} - , &[_][]const u8{ - "tmp.zig:2:21: error: expected expression, found 'invalid bytes'", - "tmp.zig:2:26: note: invalid byte: '_'", - }); - - ctx.objErrStage1("invalid underscore placement in float literal - 6", - \\fn main() void { - \\ var bad: f128 = 1.0e-_1; - \\ _ = bad; - \\} - , &[_][]const u8{ - "tmp.zig:2:21: error: expected expression, found 'invalid bytes'", - "tmp.zig:2:26: note: invalid byte: '_'", - }); - - ctx.objErrStage1("invalid underscore placement in float literal - 7", - \\fn main() void { - \\ var bad: f128 = 1.0e-1_; - \\ _ = bad; - \\} - , &[_][]const u8{ - "tmp.zig:2:21: error: expected expression, found 'invalid bytes'", - "tmp.zig:2:28: note: invalid byte: ';'", - }); - - ctx.objErrStage1("invalid underscore placement in float literal - 9", - \\fn main() void { - \\ var bad: f128 = 1__0.0e-1; - \\ _ = bad; - \\} - , &[_][]const u8{ - "tmp.zig:2:21: error: expected expression, found 'invalid bytes'", - "tmp.zig:2:23: note: invalid byte: '_'", - }); - - ctx.objErrStage1("invalid underscore placement in float literal - 10", - \\fn main() void { - \\ var bad: f128 = 1.0__0e-1; - \\ _ = bad; - \\} - , &[_][]const u8{ - "tmp.zig:2:21: error: expected expression, found 'invalid bytes'", - "tmp.zig:2:25: note: invalid byte: '_'", - }); - - ctx.objErrStage1("invalid underscore placement in float literal - 11", - \\fn main() void { - \\ var bad: f128 = 1.0e-1__0; - \\ _ = bad; - \\} - , &[_][]const u8{ - "tmp.zig:2:21: error: expected expression, found 'invalid bytes'", - "tmp.zig:2:28: note: invalid byte: '_'", - }); - - ctx.objErrStage1("invalid underscore placement in float literal - 12", - \\fn main() void { - \\ var bad: f128 = 0_x0.0; - \\ _ = bad; - \\} - , &[_][]const u8{ - "tmp.zig:2:21: error: expected expression, found 'invalid bytes'", - "tmp.zig:2:23: note: invalid byte: 'x'", - }); - - ctx.objErrStage1("invalid underscore placement in float literal - 13", - \\fn main() void { - \\ var bad: f128 = 0x_0.0; - \\ _ = bad; - \\} - , &[_][]const u8{ - "tmp.zig:2:21: error: expected expression, found 'invalid bytes'", - "tmp.zig:2:23: note: invalid byte: '_'", - }); - - ctx.objErrStage1("invalid underscore placement in float literal - 14", - \\fn main() void { - \\ var bad: f128 = 0x0.0_p1; - \\ _ = bad; - \\} - , &[_][]const u8{ - "tmp.zig:2:21: error: expected expression, found 'invalid bytes'", - "tmp.zig:2:27: note: invalid byte: 'p'", - }); - - ctx.objErrStage1("invalid underscore placement in int literal - 1", - \\fn main() void { - \\ var bad: u128 = 0010_; - \\ _ = bad; - \\} - , &[_][]const u8{ - "tmp.zig:2:21: error: expected expression, found 'invalid bytes'", - "tmp.zig:2:26: note: invalid byte: ';'", - }); - - ctx.objErrStage1("invalid underscore placement in int literal - 2", - \\fn main() void { - \\ var bad: u128 = 0b0010_; - \\ _ = bad; - \\} - , &[_][]const u8{ - "tmp.zig:2:21: error: expected expression, found 'invalid bytes'", - "tmp.zig:2:28: note: invalid byte: ';'", - }); - - ctx.objErrStage1("invalid underscore placement in int literal - 3", - \\fn main() void { - \\ var bad: u128 = 0o0010_; - \\ _ = bad; - \\} - , &[_][]const u8{ - "tmp.zig:2:21: error: expected expression, found 'invalid bytes'", - "tmp.zig:2:28: note: invalid byte: ';'", - }); - - ctx.objErrStage1("invalid underscore placement in int literal - 4", - \\fn main() void { - \\ var bad: u128 = 0x0010_; - \\ _ = bad; - \\} - , &[_][]const u8{ - "tmp.zig:2:21: error: expected expression, found 'invalid bytes'", - "tmp.zig:2:28: note: invalid byte: ';'", - }); - - ctx.objErrStage1("comptime struct field, no init value", - \\const Foo = struct { - \\ comptime b: i32, - \\}; - \\export fn entry() void { - \\ var f: Foo = undefined; - \\ _ = f; - \\} - , &[_][]const u8{ - "tmp.zig:2:5: error: comptime field without default initialization value", - }); - - ctx.objErrStage1("bad usage of @call", - \\export fn entry1() void { - \\ @call(.{}, foo, {}); - \\} - \\export fn entry2() void { - \\ comptime @call(.{ .modifier = .never_inline }, foo, .{}); - \\} - \\export fn entry3() void { - \\ comptime @call(.{ .modifier = .never_tail }, foo, .{}); - \\} - \\export fn entry4() void { - \\ @call(.{ .modifier = .never_inline }, bar, .{}); - \\} - \\export fn entry5(c: bool) void { - \\ var baz = if (c) baz1 else baz2; - \\ @call(.{ .modifier = .compile_time }, baz, .{}); - \\} - \\fn foo() void {} - \\fn bar() callconv(.Inline) void {} - \\fn baz1() void {} - \\fn baz2() void {} - , &[_][]const u8{ - "tmp.zig:2:21: error: expected tuple or struct, found 'void'", - "tmp.zig:5:14: error: unable to perform 'never_inline' call at compile-time", - "tmp.zig:8:14: error: unable to perform 'never_tail' call at compile-time", - "tmp.zig:11:5: error: no-inline call of inline function", - "tmp.zig:15:5: error: the specified modifier requires a comptime-known function", - }); - - ctx.objErrStage1("exported async function", - \\export fn foo() callconv(.Async) void {} - , &[_][]const u8{ - "tmp.zig:1:1: error: exported function cannot be async", - }); - - ctx.exeErrStage1("main missing name", - \\pub fn (main) void {} - , &[_][]const u8{ - "tmp.zig:1:5: error: missing function name", - }); - { const case = ctx.obj("call with new stack on unsupported target", .{ .cpu_arch = .wasm32, @@ -1899,361 +181,6 @@ pub fn addCases(ctx: *TestContext) !void { "tmp.zig:12:31: note: destination array requires a terminating '0' sentinel", }); - ctx.objErrStage1("empty switch on an integer", - \\export fn entry() void { - \\ var x: u32 = 0; - \\ switch(x) {} - \\} - , &[_][]const u8{ - "tmp.zig:3:5: error: switch must handle all possibilities", - }); - - ctx.objErrStage1("incorrect return type", - \\ pub export fn entry() void{ - \\ _ = foo(); - \\ } - \\ const A = struct { - \\ a: u32, - \\ }; - \\ fn foo() A { - \\ return bar(); - \\ } - \\ const B = struct { - \\ a: u32, - \\ }; - \\ fn bar() B { - \\ unreachable; - \\ } - , &[_][]const u8{ - "tmp.zig:8:16: error: expected type 'A', found 'B'", - }); - - ctx.objErrStage1("regression test #2980: base type u32 is not type checked properly when assigning a value within a struct", - \\const Foo = struct { - \\ ptr: ?*usize, - \\ uval: u32, - \\}; - \\fn get_uval(x: u32) !u32 { - \\ _ = x; - \\ return error.NotFound; - \\} - \\export fn entry() void { - \\ const afoo = Foo{ - \\ .ptr = null, - \\ .uval = get_uval(42), - \\ }; - \\ _ = afoo; - \\} - , &[_][]const u8{ - "tmp.zig:12:25: error: cannot convert error union to payload type. consider using `try`, `catch`, or `if`. expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(get_uval)).Fn.return_type.?).ErrorUnion.error_set!u32'", - }); - - ctx.objErrStage1("assigning to struct or union fields that are not optionals with a function that returns an optional", - \\fn maybe(is: bool) ?u8 { - \\ if (is) return @as(u8, 10) else return null; - \\} - \\const U = union { - \\ Ye: u8, - \\}; - \\const S = struct { - \\ num: u8, - \\}; - \\export fn entry() void { - \\ var u = U{ .Ye = maybe(false) }; - \\ var s = S{ .num = maybe(false) }; - \\ _ = u; - \\ _ = s; - \\} - , &[_][]const u8{ - "tmp.zig:11:27: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'u8', found '?u8'", - }); - - ctx.objErrStage1("missing result type for phi node", - \\fn foo() !void { - \\ return anyerror.Foo; - \\} - \\export fn entry() void { - \\ foo() catch 0; - \\} - , &[_][]const u8{ - "tmp.zig:5:17: error: integer value 0 cannot be coerced to type 'void'", - }); - - ctx.objErrStage1("atomicrmw with enum op not .Xchg", - \\export fn entry() void { - \\ const E = enum(u8) { - \\ a, - \\ b, - \\ c, - \\ d, - \\ }; - \\ var x: E = .a; - \\ _ = @atomicRmw(E, &x, .Add, .b, .SeqCst); - \\} - , &[_][]const u8{ - "tmp.zig:9:27: error: @atomicRmw with enum only allowed with .Xchg", - }); - - ctx.objErrStage1("disallow coercion from non-null-terminated pointer to null-terminated pointer", - \\extern fn puts(s: [*:0]const u8) c_int; - \\pub fn main() void { - \\ const no_zero_array = [_]u8{'h', 'e', 'l', 'l', 'o'}; - \\ const no_zero_ptr: [*]const u8 = &no_zero_array; - \\ _ = puts(no_zero_ptr); - \\} - , &[_][]const u8{ - "tmp.zig:5:14: error: expected type '[*:0]const u8', found '[*]const u8'", - }); - - ctx.objErrStage1("atomic orderings of atomicStore Acquire or AcqRel", - \\export fn entry() void { - \\ var x: u32 = 0; - \\ @atomicStore(u32, &x, 1, .Acquire); - \\} - , &[_][]const u8{ - "tmp.zig:3:30: error: @atomicStore atomic ordering must not be Acquire or AcqRel", - }); - - ctx.objErrStage1("missing const in slice with nested array type", - \\const Geo3DTex2D = struct { vertices: [][2]f32 }; - \\pub fn getGeo3DTex2D() Geo3DTex2D { - \\ return Geo3DTex2D{ - \\ .vertices = [_][2]f32{ - \\ [_]f32{ -0.5, -0.5}, - \\ }, - \\ }; - \\} - \\export fn entry() void { - \\ var geo_data = getGeo3DTex2D(); - \\ _ = geo_data; - \\} - , &[_][]const u8{ - "tmp.zig:4:30: error: array literal requires address-of operator (&) to coerce to slice type '[][2]f32'", - }); - - ctx.objErrStage1("slicing of global undefined pointer", - \\var buf: *[1]u8 = undefined; - \\export fn entry() void { - \\ _ = buf[0..1]; - \\} - , &[_][]const u8{ - "tmp.zig:3:12: error: non-zero length slice of undefined pointer", - }); - - ctx.objErrStage1("using invalid types in function call raises an error", - \\const MenuEffect = enum {}; - \\fn func(effect: MenuEffect) void { _ = effect; } - \\export fn entry() void { - \\ func(MenuEffect.ThisDoesNotExist); - \\} - , &[_][]const u8{ - "tmp.zig:1:20: error: enum declarations must have at least one tag", - }); - - ctx.objErrStage1("store vector pointer with unknown runtime index", - \\export fn entry() void { - \\ var v: @import("std").meta.Vector(4, i32) = [_]i32{ 1, 5, 3, undefined }; - \\ - \\ var i: u32 = 0; - \\ storev(&v[i], 42); - \\} - \\ - \\fn storev(ptr: anytype, val: i32) void { - \\ ptr.* = val; - \\} - , &[_][]const u8{ - "tmp.zig:9:8: error: unable to determine vector element index of type '*align(16:0:4:?) i32", - }); - - ctx.objErrStage1("load vector pointer with unknown runtime index", - \\export fn entry() void { - \\ var v: @import("std").meta.Vector(4, i32) = [_]i32{ 1, 5, 3, undefined }; - \\ - \\ var i: u32 = 0; - \\ var x = loadv(&v[i]); - \\ _ = x; - \\} - \\ - \\fn loadv(ptr: anytype) i32 { - \\ return ptr.*; - \\} - , &[_][]const u8{ - "tmp.zig:10:12: error: unable to determine vector element index of type '*align(16:0:4:?) i32", - }); - - ctx.objErrStage1("using an unknown len ptr type instead of array", - \\const resolutions = [*][*]const u8{ - \\ "[320 240 ]", - \\ null, - \\}; - \\comptime { - \\ _ = resolutions; - \\} - , &[_][]const u8{ - "tmp.zig:1:21: error: expected array type or [_], found '[*][*]const u8'", - }); - - ctx.objErrStage1("comparison with error union and error value", - \\export fn entry() void { - \\ var number_or_error: anyerror!i32 = error.SomethingAwful; - \\ _ = number_or_error == error.SomethingAwful; - \\} - , &[_][]const u8{ - "tmp.zig:3:25: error: operator not allowed for type 'anyerror!i32'", - }); - - ctx.objErrStage1("switch with overlapping case ranges", - \\export fn entry() void { - \\ var q: u8 = 0; - \\ switch (q) { - \\ 1...2 => {}, - \\ 0...255 => {}, - \\ } - \\} - , &[_][]const u8{ - "tmp.zig:5:9: error: duplicate switch value", - }); - - ctx.objErrStage1("invalid optional type in extern struct", - \\const stroo = extern struct { - \\ moo: ?[*c]u8, - \\}; - \\export fn testf(fluff: *stroo) void { _ = fluff; } - , &[_][]const u8{ - "tmp.zig:2:5: error: extern structs cannot contain fields of type '?[*c]u8'", - }); - - ctx.objErrStage1("attempt to negate a non-integer, non-float or non-vector type", - \\fn foo() anyerror!u32 { - \\ return 1; - \\} - \\ - \\export fn entry() void { - \\ const x = -foo(); - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:6:15: error: negation of type 'anyerror!u32'", - }); - - ctx.objErrStage1("attempt to create 17 bit float type", - \\const builtin = @import("std").builtin; - \\comptime { - \\ _ = @Type(.{ .Float = .{ .bits = 17 } }); - \\} - , &[_][]const u8{ - "tmp.zig:3:16: error: 17-bit float unsupported", - }); - - ctx.objErrStage1("wrong type for @Type", - \\export fn entry() void { - \\ _ = @Type(0); - \\} - , &[_][]const u8{ - "tmp.zig:2:15: error: expected type 'std.builtin.Type', found 'comptime_int'", - }); - - ctx.objErrStage1("@Type with non-constant expression", - \\const builtin = @import("std").builtin; - \\var globalTypeInfo : builtin.Type = undefined; - \\export fn entry() void { - \\ _ = @Type(globalTypeInfo); - \\} - , &[_][]const u8{ - "tmp.zig:4:15: error: unable to evaluate constant expression", - }); - - ctx.objErrStage1("wrong type for argument tuple to @asyncCall", - \\export fn entry1() void { - \\ var frame: @Frame(foo) = undefined; - \\ @asyncCall(&frame, {}, foo, {}); - \\} - \\ - \\fn foo() i32 { - \\ return 0; - \\} - , &[_][]const u8{ - "tmp.zig:3:33: error: expected tuple or struct, found 'void'", - }); - - ctx.objErrStage1("wrong type for result ptr to @asyncCall", - \\export fn entry() void { - \\ _ = async amain(); - \\} - \\fn amain() i32 { - \\ var frame: @Frame(foo) = undefined; - \\ return await @asyncCall(&frame, false, foo, .{}); - \\} - \\fn foo() i32 { - \\ return 1234; - \\} - , &[_][]const u8{ - "tmp.zig:6:37: error: expected type '*i32', found 'bool'", - }); - - ctx.objErrStage1("shift amount has to be an integer type", - \\export fn entry() void { - \\ const x = 1 << &@as(u8, 10); - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:2:21: error: shift amount has to be an integer type, but found '*const u8'", - }); - - ctx.objErrStage1("bit shifting only works on integer types", - \\export fn entry() void { - \\ const x = &@as(u8, 1) << 10; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:2:16: error: bit shifting operation expected integer type, found '*const u8'", - }); - - ctx.objErrStage1("struct depends on itself via optional field", - \\const LhsExpr = struct { - \\ rhsExpr: ?AstObject, - \\}; - \\const AstObject = union { - \\ lhsExpr: LhsExpr, - \\}; - \\export fn entry() void { - \\ const lhsExpr = LhsExpr{ .rhsExpr = null }; - \\ const obj = AstObject{ .lhsExpr = lhsExpr }; - \\ _ = obj; - \\} - , &[_][]const u8{ - "tmp.zig:1:17: error: struct 'LhsExpr' depends on itself", - "tmp.zig:5:5: note: while checking this field", - "tmp.zig:2:5: note: while checking this field", - }); - - ctx.objErrStage1("alignment of enum field specified", - \\const Number = enum { - \\ a, - \\ b align(i32), - \\}; - \\export fn entry1() void { - \\ var x: Number = undefined; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:3:7: error: expected ',' after field", - }); - - ctx.objErrStage1("bad alignment type", - \\export fn entry1() void { - \\ var x: []align(true) i32 = undefined; - \\ _ = x; - \\} - \\export fn entry2() void { - \\ var x: *align(@as(f64, 12.34)) i32 = undefined; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:2:20: error: expected type 'u29', found 'bool'", - "tmp.zig:6:19: error: fractional component prevents float value 12.340000 from being casted to type 'u29'", - }); - { const case = ctx.obj("variable in inline assembly template cannot be found", .{ .cpu_arch = .x86_64, @@ -2274,55 +201,6 @@ pub fn addCases(ctx: *TestContext) !void { }); } - ctx.objErrStage1("indirect recursion of async functions detected", - \\var frame: ?anyframe = null; - \\ - \\export fn a() void { - \\ _ = async rangeSum(10); - \\ while (frame) |f| resume f; - \\} - \\ - \\fn rangeSum(x: i32) i32 { - \\ suspend { - \\ frame = @frame(); - \\ } - \\ frame = null; - \\ - \\ if (x == 0) return 0; - \\ var child = rangeSumIndirect(x - 1); - \\ return child + 1; - \\} - \\ - \\fn rangeSumIndirect(x: i32) i32 { - \\ suspend { - \\ frame = @frame(); - \\ } - \\ frame = null; - \\ - \\ if (x == 0) return 0; - \\ var child = rangeSum(x - 1); - \\ return child + 1; - \\} - , &[_][]const u8{ - "tmp.zig:8:1: error: '@Frame(rangeSum)' depends on itself", - "tmp.zig:15:33: note: when analyzing type '@Frame(rangeSum)' here", - "tmp.zig:26:25: note: when analyzing type '@Frame(rangeSumIndirect)' here", - }); - - ctx.objErrStage1("non-async function pointer eventually is inferred to become async", - \\export fn a() void { - \\ var non_async_fn: fn () void = undefined; - \\ non_async_fn = func; - \\} - \\fn func() void { - \\ suspend {} - \\} - , &[_][]const u8{ - "tmp.zig:5:1: error: 'func' cannot be async", - "tmp.zig:3:20: note: required to be non-async here", - "tmp.zig:6:5: note: suspends here", - }); - { const case = ctx.obj("bad alignment in @asyncCall", .{ .cpu_arch = .aarch64, @@ -2342,633 +220,6 @@ pub fn addCases(ctx: *TestContext) !void { }); } - ctx.objErrStage1("atomic orderings of fence Acquire or stricter", - \\export fn entry() void { - \\ @fence(.Monotonic); - \\} - , &[_][]const u8{ - "tmp.zig:2:12: error: atomic ordering must be Acquire or stricter", - }); - - ctx.objErrStage1("bad alignment in implicit cast from array pointer to slice", - \\export fn a() void { - \\ var x: [10]u8 = undefined; - \\ var y: []align(16) u8 = &x; - \\ _ = y; - \\} - , &[_][]const u8{ - "tmp.zig:3:30: error: expected type '[]align(16) u8', found '*[10]u8'", - }); - - ctx.objErrStage1("result location incompatibility mismatching handle_is_ptr (generic call)", - \\export fn entry() void { - \\ var damn = Container{ - \\ .not_optional = getOptional(i32), - \\ }; - \\ _ = damn; - \\} - \\pub fn getOptional(comptime T: type) ?T { - \\ return 0; - \\} - \\pub const Container = struct { - \\ not_optional: i32, - \\}; - , &[_][]const u8{ - "tmp.zig:3:36: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'i32', found '?i32'", - }); - - ctx.objErrStage1("result location incompatibility mismatching handle_is_ptr", - \\export fn entry() void { - \\ var damn = Container{ - \\ .not_optional = getOptional(), - \\ }; - \\ _ = damn; - \\} - \\pub fn getOptional() ?i32 { - \\ return 0; - \\} - \\pub const Container = struct { - \\ not_optional: i32, - \\}; - , &[_][]const u8{ - "tmp.zig:3:36: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'i32', found '?i32'", - }); - - ctx.objErrStage1("const frame cast to anyframe", - \\export fn a() void { - \\ const f = async func(); - \\ resume f; - \\} - \\export fn b() void { - \\ const f = async func(); - \\ var x: anyframe = &f; - \\ _ = x; - \\} - \\fn func() void { - \\ suspend {} - \\} - , &[_][]const u8{ - "tmp.zig:3:12: error: expected type 'anyframe', found '*const @Frame(func)'", - "tmp.zig:7:24: error: expected type 'anyframe', found '*const @Frame(func)'", - }); - - ctx.objErrStage1("prevent bad implicit casting of anyframe types", - \\export fn a() void { - \\ var x: anyframe = undefined; - \\ var y: anyframe->i32 = x; - \\ _ = y; - \\} - \\export fn b() void { - \\ var x: i32 = undefined; - \\ var y: anyframe->i32 = x; - \\ _ = y; - \\} - \\export fn c() void { - \\ var x: @Frame(func) = undefined; - \\ var y: anyframe->i32 = &x; - \\ _ = y; - \\} - \\fn func() void {} - , &[_][]const u8{ - "tmp.zig:3:28: error: expected type 'anyframe->i32', found 'anyframe'", - "tmp.zig:8:28: error: expected type 'anyframe->i32', found 'i32'", - "tmp.zig:13:29: error: expected type 'anyframe->i32', found '*@Frame(func)'", - }); - - ctx.objErrStage1("wrong frame type used for async call", - \\export fn entry() void { - \\ var frame: @Frame(foo) = undefined; - \\ frame = async bar(); - \\} - \\fn foo() void { - \\ suspend {} - \\} - \\fn bar() void { - \\ suspend {} - \\} - , &[_][]const u8{ - "tmp.zig:3:13: error: expected type '*@Frame(bar)', found '*@Frame(foo)'", - }); - - ctx.objErrStage1("@Frame() of generic function", - \\export fn entry() void { - \\ var frame: @Frame(func) = undefined; - \\ _ = frame; - \\} - \\fn func(comptime T: type) void { - \\ var x: T = undefined; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:2:16: error: @Frame() of generic function", - }); - - ctx.objErrStage1("@frame() causes function to be async", - \\export fn entry() void { - \\ func(); - \\} - \\fn func() void { - \\ _ = @frame(); - \\} - , &[_][]const u8{ - "tmp.zig:1:1: error: function with calling convention 'C' cannot be async", - "tmp.zig:5:9: note: @frame() causes function to be async", - }); - - ctx.objErrStage1("invalid suspend in exported function", - \\export fn entry() void { - \\ var frame = async func(); - \\ var result = await frame; - \\ _ = result; - \\} - \\fn func() void { - \\ suspend {} - \\} - , &[_][]const u8{ - "tmp.zig:1:1: error: function with calling convention 'C' cannot be async", - "tmp.zig:3:18: note: await here is a suspend point", - }); - - ctx.objErrStage1("async function indirectly depends on its own frame", - \\export fn entry() void { - \\ _ = async amain(); - \\} - \\fn amain() callconv(.Async) void { - \\ other(); - \\} - \\fn other() void { - \\ var x: [@sizeOf(@Frame(amain))]u8 = undefined; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:4:1: error: unable to determine async function frame of 'amain'", - "tmp.zig:5:10: note: analysis of function 'other' depends on the frame", - }); - - ctx.objErrStage1("async function depends on its own frame", - \\export fn entry() void { - \\ _ = async amain(); - \\} - \\fn amain() callconv(.Async) void { - \\ var x: [@sizeOf(@Frame(amain))]u8 = undefined; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:4:1: error: cannot resolve '@Frame(amain)': function not fully analyzed yet", - }); - - ctx.objErrStage1("non async function pointer passed to @asyncCall", - \\export fn entry() void { - \\ var ptr = afunc; - \\ var bytes: [100]u8 align(16) = undefined; - \\ _ = @asyncCall(&bytes, {}, ptr, .{}); - \\} - \\fn afunc() void { } - , &[_][]const u8{ - "tmp.zig:4:32: error: expected async function, found 'fn() void'", - }); - - ctx.objErrStage1("runtime-known async function called", - \\export fn entry() void { - \\ _ = async amain(); - \\} - \\fn amain() void { - \\ var ptr = afunc; - \\ _ = ptr(); - \\} - \\fn afunc() callconv(.Async) void {} - , &[_][]const u8{ - "tmp.zig:6:12: error: function is not comptime-known; @asyncCall required", - }); - - ctx.objErrStage1("runtime-known function called with async keyword", - \\export fn entry() void { - \\ var ptr = afunc; - \\ _ = async ptr(); - \\} - \\ - \\fn afunc() callconv(.Async) void { } - , &[_][]const u8{ - "tmp.zig:3:15: error: function is not comptime-known; @asyncCall required", - }); - - ctx.objErrStage1("function with ccc indirectly calling async function", - \\export fn entry() void { - \\ foo(); - \\} - \\fn foo() void { - \\ bar(); - \\} - \\fn bar() void { - \\ suspend {} - \\} - , &[_][]const u8{ - "tmp.zig:1:1: error: function with calling convention 'C' cannot be async", - "tmp.zig:2:8: note: async function call here", - "tmp.zig:5:8: note: async function call here", - "tmp.zig:8:5: note: suspends here", - }); - - ctx.objErrStage1("capture group on switch prong with incompatible payload types", - \\const Union = union(enum) { - \\ A: usize, - \\ B: isize, - \\}; - \\comptime { - \\ var u = Union{ .A = 8 }; - \\ switch (u) { - \\ .A, .B => |e| { - \\ _ = e; - \\ unreachable; - \\ }, - \\ } - \\} - , &[_][]const u8{ - "tmp.zig:8:20: error: capture group with incompatible types", - "tmp.zig:8:9: note: type 'usize' here", - "tmp.zig:8:13: note: type 'isize' here", - }); - - ctx.objErrStage1("wrong type to @hasField", - \\export fn entry() bool { - \\ return @hasField(i32, "hi"); - \\} - , &[_][]const u8{ - "tmp.zig:2:22: error: type 'i32' does not support @hasField", - }); - - ctx.objErrStage1("slice passed as array init type with elems", - \\export fn entry() void { - \\ const x = []u8{1, 2}; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:2:15: error: array literal requires address-of operator (&) to coerce to slice type '[]u8'", - }); - - ctx.objErrStage1("slice passed as array init type", - \\export fn entry() void { - \\ const x = []u8{}; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:2:15: error: array literal requires address-of operator (&) to coerce to slice type '[]u8'", - }); - - ctx.objErrStage1("inferred array size invalid here", - \\export fn entry() void { - \\ const x = [_]u8; - \\ _ = x; - \\} - \\export fn entry2() void { - \\ const S = struct { a: *const [_]u8 }; - \\ var a = .{ S{} }; - \\ _ = a; - \\} - , &[_][]const u8{ - "tmp.zig:2:16: error: unable to infer array size", - "tmp.zig:6:35: error: unable to infer array size", - }); - - ctx.objErrStage1("initializing array with struct syntax", - \\export fn entry() void { - \\ const x = [_]u8{ .y = 2 }; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:2:15: error: initializing array with struct syntax", - }); - - ctx.objErrStage1("compile error in struct init expression", - \\const Foo = struct { - \\ a: i32 = crap, - \\ b: i32, - \\}; - \\export fn entry() void { - \\ var x = Foo{ - \\ .b = 5, - \\ }; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:2:14: error: use of undeclared identifier 'crap'", - }); - - ctx.objErrStage1("undefined as field type is rejected", - \\const Foo = struct { - \\ a: undefined, - \\}; - \\export fn entry1() void { - \\ const foo: Foo = undefined; - \\ _ = foo; - \\} - , &[_][]const u8{ - "tmp.zig:2:8: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("@hasDecl with non-container", - \\export fn entry() void { - \\ _ = @hasDecl(i32, "hi"); - \\} - , &[_][]const u8{ - "tmp.zig:2:18: error: expected struct, enum, or union; found 'i32'", - }); - - ctx.objErrStage1("field access of slices", - \\export fn entry() void { - \\ var slice: []i32 = undefined; - \\ const info = @TypeOf(slice).unknown; - \\ _ = info; - \\} - , &[_][]const u8{ - "tmp.zig:3:32: error: type 'type' does not support field access", - }); - - ctx.objErrStage1("peer cast then implicit cast const pointer to mutable C pointer", - \\export fn func() void { - \\ var strValue: [*c]u8 = undefined; - \\ strValue = strValue orelse ""; - \\} - , &[_][]const u8{ - "tmp.zig:3:32: error: expected type '[*c]u8', found '*const [0:0]u8'", - "tmp.zig:3:32: note: cast discards const qualifier", - }); - - ctx.objErrStage1("overflow in enum value allocation", - \\const Moo = enum(u8) { - \\ Last = 255, - \\ Over, - \\}; - \\pub fn main() void { - \\ var y = Moo.Last; - \\ _ = y; - \\} - , &[_][]const u8{ - "tmp.zig:3:5: error: enumeration value 256 too large for type 'u8'", - }); - - ctx.objErrStage1("attempt to cast enum literal to error", - \\export fn entry() void { - \\ switch (error.Hi) { - \\ .Hi => {}, - \\ } - \\} - , &[_][]const u8{ - "tmp.zig:3:9: error: expected type 'error{Hi}', found '@Type(.EnumLiteral)'", - }); - - ctx.objErrStage1("@sizeOf bad type", - \\export fn entry() usize { - \\ return @sizeOf(@TypeOf(null)); - \\} - , &[_][]const u8{ - "tmp.zig:2:20: error: no size available for type '@Type(.Null)'", - }); - - ctx.objErrStage1("generic function where return type is self-referenced", - \\fn Foo(comptime T: type) Foo(T) { - \\ return struct{ x: T }; - \\} - \\export fn entry() void { - \\ const t = Foo(u32) { - \\ .x = 1 - \\ }; - \\ _ = t; - \\} - , &[_][]const u8{ - "tmp.zig:1:29: error: evaluation exceeded 1000 backwards branches", - }); - - ctx.objErrStage1("@ptrToInt 0 to non optional pointer", - \\export fn entry() void { - \\ var b = @intToPtr(*i32, 0); - \\ _ = b; - \\} - , &[_][]const u8{ - "tmp.zig:2:13: error: pointer type '*i32' does not allow address zero", - }); - - ctx.objErrStage1("cast enum literal to enum but it doesn't match", - \\const Foo = enum { - \\ a, - \\ b, - \\}; - \\export fn entry() void { - \\ const x: Foo = .c; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:6:20: error: enum 'Foo' has no field named 'c'", - "tmp.zig:1:13: note: 'Foo' declared here", - }); - - ctx.objErrStage1("discarding error value", - \\export fn entry() void { - \\ _ = foo(); - \\} - \\fn foo() !void { - \\ return error.OutOfMemory; - \\} - , &[_][]const u8{ - "tmp.zig:2:12: error: error is discarded. consider using `try`, `catch`, or `if`", - }); - - ctx.objErrStage1("volatile on global assembly", - \\comptime { - \\ asm volatile (""); - \\} - , &[_][]const u8{ - "tmp.zig:2:9: error: volatile is meaningless on global assembly", - }); - - ctx.objErrStage1("invalid multiple dereferences", - \\export fn a() void { - \\ var box = Box{ .field = 0 }; - \\ box.*.field = 1; - \\} - \\export fn b() void { - \\ var box = Box{ .field = 0 }; - \\ var boxPtr = &box; - \\ boxPtr.*.*.field = 1; - \\} - \\pub const Box = struct { - \\ field: i32, - \\}; - , &[_][]const u8{ - "tmp.zig:3:8: error: attempt to dereference non-pointer type 'Box'", - "tmp.zig:8:13: error: attempt to dereference non-pointer type 'Box'", - }); - - ctx.objErrStage1("usingnamespace with wrong type", - \\usingnamespace void; - , &[_][]const u8{ - "tmp.zig:1:1: error: expected struct, enum, or union; found 'void'", - }); - - ctx.objErrStage1("ignored expression in while continuation", - \\export fn a() void { - \\ while (true) : (bad()) {} - \\} - \\export fn b() void { - \\ var x: anyerror!i32 = 1234; - \\ while (x) |_| : (bad()) {} else |_| {} - \\} - \\export fn c() void { - \\ var x: ?i32 = 1234; - \\ while (x) |_| : (bad()) {} - \\} - \\fn bad() anyerror!void { - \\ return error.Bad; - \\} - , &[_][]const u8{ - "tmp.zig:2:24: error: error is ignored. consider using `try`, `catch`, or `if`", - "tmp.zig:6:25: error: error is ignored. consider using `try`, `catch`, or `if`", - "tmp.zig:10:25: error: error is ignored. consider using `try`, `catch`, or `if`", - }); - - ctx.objErrStage1("empty while loop body", - \\export fn a() void { - \\ while(true); - \\} - , &[_][]const u8{ - "tmp.zig:2:16: error: expected block or assignment, found ';'", - }); - - ctx.objErrStage1("empty for loop body", - \\export fn a() void { - \\ for(undefined) |x|; - \\} - , &[_][]const u8{ - "tmp.zig:2:23: error: expected block or assignment, found ';'", - }); - - ctx.objErrStage1("empty if body", - \\export fn a() void { - \\ if(true); - \\} - , &[_][]const u8{ - "tmp.zig:2:13: error: expected block or assignment, found ';'", - }); - - ctx.objErrStage1("import outside package path", - \\comptime{ - \\ _ = @import("../a.zig"); - \\} - , &[_][]const u8{ - "tmp.zig:2:9: error: import of file outside package path: '../a.zig'", - }); - - ctx.objErrStage1("bogus compile var", - \\const x = @import("builtin").bogus; - \\export fn entry() usize { return @sizeOf(@TypeOf(x)); } - , &[_][]const u8{ - "tmp.zig:1:29: error: container 'builtin' has no member called 'bogus'", - }); - - ctx.objErrStage1("wrong panic signature, runtime function", - \\test "" {} - \\ - \\pub fn panic() void {} - \\ - , &[_][]const u8{ - "error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn() void'", - }); - - ctx.objErrStage1("wrong panic signature, generic function", - \\pub fn panic(comptime msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn { - \\ _ = msg; _ = error_return_trace; - \\ while (true) {} - \\} - \\const builtin = @import("std").builtin; - , &[_][]const u8{ - "error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn([]const u8,anytype) anytype'", - "note: only one of the functions is generic", - }); - - ctx.objErrStage1("direct struct loop", - \\const A = struct { a : A, }; - \\export fn entry() usize { return @sizeOf(A); } - , &[_][]const u8{ - "tmp.zig:1:11: error: struct 'A' depends on itself", - }); - - ctx.objErrStage1("indirect struct loop", - \\const A = struct { b : B, }; - \\const B = struct { c : C, }; - \\const C = struct { a : A, }; - \\export fn entry() usize { return @sizeOf(A); } - , &[_][]const u8{ - "tmp.zig:1:11: error: struct 'A' depends on itself", - }); - - ctx.objErrStage1("instantiating an undefined value for an invalid struct that contains itself", - \\const Foo = struct { - \\ x: Foo, - \\}; - \\ - \\var foo: Foo = undefined; - \\ - \\export fn entry() usize { - \\ return @sizeOf(@TypeOf(foo.x)); - \\} - , &[_][]const u8{ - "tmp.zig:1:13: error: struct 'Foo' depends on itself", - }); - - ctx.objErrStage1("enum field value references enum", - \\pub const Foo = enum(c_int) { - \\ A = Foo.B, - \\ C = D, - \\}; - \\export fn entry() void { - \\ var s: Foo = Foo.E; - \\ _ = s; - \\} - \\const D = 1; - , &[_][]const u8{ - "tmp.zig:1:17: error: enum 'Foo' depends on itself", - }); - - ctx.objErrStage1("top level decl dependency loop", - \\const a : @TypeOf(b) = 0; - \\const b : @TypeOf(a) = 0; - \\export fn entry() void { - \\ const c = a + b; - \\ _ = c; - \\} - , &[_][]const u8{ - "tmp.zig:2:19: error: dependency loop detected", - }); - - ctx.testErrStage1("not an enum type", - \\export fn entry() void { - \\ var self: Error = undefined; - \\ switch (self) { - \\ InvalidToken => |x| return x.token, - \\ ExpectedVarDeclOrFn => |x| return x.token, - \\ } - \\} - \\const Error = union(enum) { - \\ A: InvalidToken, - \\ B: ExpectedVarDeclOrFn, - \\}; - \\const InvalidToken = struct {}; - \\const ExpectedVarDeclOrFn = struct {}; - , &[_][]const u8{ - "tmp.zig:4:9: error: expected type '@typeInfo(Error).Union.tag_type.?', found 'type'", - }); - - ctx.testErrStage1("binary OR operator on error sets", - \\pub const A = error.A; - \\pub const AB = A | error.B; - \\export fn entry() void { - \\ var x: AB = undefined; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:2:18: error: invalid operands to binary expression: 'error{A}' and 'error{B}'", - }); - if (builtin.os.tag == .linux) { ctx.testErrStage1("implicit dependency on libc", \\extern "c" fn exit(u8) void; @@ -2990,1048 +241,6 @@ pub fn addCases(ctx: *TestContext) !void { }); } - ctx.testErrStage1("comptime vector overflow shows the index", - \\comptime { - \\ var a: @import("std").meta.Vector(4, u8) = [_]u8{ 1, 2, 255, 4 }; - \\ var b: @import("std").meta.Vector(4, u8) = [_]u8{ 5, 6, 1, 8 }; - \\ var x = a + b; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:4:15: error: operation caused overflow", - "tmp.zig:4:15: note: when computing vector element at index 2", - }); - - ctx.testErrStage1("packed struct with fields of not allowed types", - \\const A = packed struct { - \\ x: anyerror, - \\}; - \\const B = packed struct { - \\ x: [2]u24, - \\}; - \\const C = packed struct { - \\ x: [1]anyerror, - \\}; - \\const D = packed struct { - \\ x: [1]S, - \\}; - \\const E = packed struct { - \\ x: [1]U, - \\}; - \\const F = packed struct { - \\ x: ?anyerror, - \\}; - \\const G = packed struct { - \\ x: Enum, - \\}; - \\export fn entry1() void { - \\ var a: A = undefined; - \\ _ = a; - \\} - \\export fn entry2() void { - \\ var b: B = undefined; - \\ _ = b; - \\} - \\export fn entry3() void { - \\ var r: C = undefined; - \\ _ = r; - \\} - \\export fn entry4() void { - \\ var d: D = undefined; - \\ _ = d; - \\} - \\export fn entry5() void { - \\ var e: E = undefined; - \\ _ = e; - \\} - \\export fn entry6() void { - \\ var f: F = undefined; - \\ _ = f; - \\} - \\export fn entry7() void { - \\ var g: G = undefined; - \\ _ = g; - \\} - \\const S = struct { - \\ x: i32, - \\}; - \\const U = struct { - \\ A: i32, - \\ B: u32, - \\}; - \\const Enum = enum { - \\ A, - \\ B, - \\}; - , &[_][]const u8{ - "tmp.zig:2:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation", - "tmp.zig:5:5: error: array of 'u24' not allowed in packed struct due to padding bits (must be padded from 48 to 64 bits)", - "tmp.zig:8:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation", - "tmp.zig:11:5: error: non-packed, non-extern struct 'S' not allowed in packed struct; no guaranteed in-memory representation", - "tmp.zig:14:5: error: non-packed, non-extern struct 'U' not allowed in packed struct; no guaranteed in-memory representation", - "tmp.zig:17:5: error: type '?anyerror' not allowed in packed struct; no guaranteed in-memory representation", - "tmp.zig:20:5: error: type 'Enum' not allowed in packed struct; no guaranteed in-memory representation", - "tmp.zig:57:14: note: enum declaration does not specify an integer tag type", - }); - - ctx.objErrStage1("deduplicate undeclared identifier", - \\export fn a() void { - \\ x += 1; - \\} - \\export fn b() void { - \\ x += 1; - \\} - , &[_][]const u8{ - "tmp.zig:2:5: error: use of undeclared identifier 'x'", - }); - - ctx.objErrStage1("export generic function", - \\export fn foo(num: anytype) i32 { - \\ _ = num; - \\ return 0; - \\} - , &[_][]const u8{ - "tmp.zig:1:15: error: parameter of type 'anytype' not allowed in function with calling convention 'C'", - }); - - ctx.objErrStage1("C pointer to anyopaque", - \\export fn a() void { - \\ var x: *anyopaque = undefined; - \\ var y: [*c]anyopaque = x; - \\ _ = y; - \\} - , &[_][]const u8{ - "tmp.zig:3:16: error: C pointers cannot point to opaque types", - }); - - ctx.objErrStage1("directly embedding opaque type in struct and union", - \\const O = opaque {}; - \\const Foo = struct { - \\ o: O, - \\}; - \\const Bar = union { - \\ One: i32, - \\ Two: O, - \\}; - \\export fn a() void { - \\ var foo: Foo = undefined; - \\ _ = foo; - \\} - \\export fn b() void { - \\ var bar: Bar = undefined; - \\ _ = bar; - \\} - \\export fn c() void { - \\ var baz: *opaque {} = undefined; - \\ const qux = .{baz.*}; - \\ _ = qux; - \\} - , &[_][]const u8{ - "tmp.zig:3:5: error: opaque types have unknown size and therefore cannot be directly embedded in structs", - "tmp.zig:7:5: error: opaque types have unknown size and therefore cannot be directly embedded in unions", - "tmp.zig:19:22: error: opaque types have unknown size and therefore cannot be directly embedded in structs", - }); - - ctx.objErrStage1("implicit cast between C pointer and Zig pointer - bad const/align/child", - \\export fn a() void { - \\ var x: [*c]u8 = undefined; - \\ var y: *align(4) u8 = x; - \\ _ = y; - \\} - \\export fn b() void { - \\ var x: [*c]const u8 = undefined; - \\ var y: *u8 = x; - \\ _ = y; - \\} - \\export fn c() void { - \\ var x: [*c]u8 = undefined; - \\ var y: *u32 = x; - \\ _ = y; - \\} - \\export fn d() void { - \\ var y: *align(1) u32 = undefined; - \\ var x: [*c]u32 = y; - \\ _ = x; - \\} - \\export fn e() void { - \\ var y: *const u8 = undefined; - \\ var x: [*c]u8 = y; - \\ _ = x; - \\} - \\export fn f() void { - \\ var y: *u8 = undefined; - \\ var x: [*c]u32 = y; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:3:27: error: cast increases pointer alignment", - "tmp.zig:8:18: error: cast discards const qualifier", - "tmp.zig:13:19: error: expected type '*u32', found '[*c]u8'", - "tmp.zig:13:19: note: pointer type child 'u8' cannot cast into pointer type child 'u32'", - "tmp.zig:18:22: error: cast increases pointer alignment", - "tmp.zig:23:21: error: cast discards const qualifier", - "tmp.zig:28:22: error: expected type '[*c]u32', found '*u8'", - }); - - ctx.objErrStage1("implicit casting null c pointer to zig pointer", - \\comptime { - \\ var c_ptr: [*c]u8 = 0; - \\ var zig_ptr: *u8 = c_ptr; - \\ _ = zig_ptr; - \\} - , &[_][]const u8{ - "tmp.zig:3:24: error: null pointer casted to type '*u8'", - }); - - ctx.objErrStage1("implicit casting undefined c pointer to zig pointer", - \\comptime { - \\ var c_ptr: [*c]u8 = undefined; - \\ var zig_ptr: *u8 = c_ptr; - \\ _ = zig_ptr; - \\} - , &[_][]const u8{ - "tmp.zig:3:24: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("implicit casting C pointers which would mess up null semantics", - \\export fn entry() void { - \\ var slice: []const u8 = "aoeu"; - \\ const opt_many_ptr: [*]const u8 = slice.ptr; - \\ var ptr_opt_many_ptr = &opt_many_ptr; - \\ var c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr; - \\ ptr_opt_many_ptr = c_ptr; - \\} - \\export fn entry2() void { - \\ var buf: [4]u8 = "aoeu".*; - \\ var slice: []u8 = &buf; - \\ var opt_many_ptr: [*]u8 = slice.ptr; - \\ var ptr_opt_many_ptr = &opt_many_ptr; - \\ var c_ptr: [*c][*c]const u8 = ptr_opt_many_ptr; - \\ _ = c_ptr; - \\} - , &[_][]const u8{ - "tmp.zig:6:24: error: expected type '*const [*]const u8', found '[*c]const [*c]const u8'", - "tmp.zig:6:24: note: pointer type child '[*c]const u8' cannot cast into pointer type child '[*]const u8'", - "tmp.zig:6:24: note: '[*c]const u8' could have null values which are illegal in type '[*]const u8'", - "tmp.zig:13:35: error: expected type '[*c][*c]const u8', found '*[*]u8'", - "tmp.zig:13:35: note: pointer type child '[*]u8' cannot cast into pointer type child '[*c]const u8'", - "tmp.zig:13:35: note: mutable '[*c]const u8' allows illegal null values stored to type '[*]u8'", - }); - - ctx.objErrStage1("implicit casting too big integers to C pointers", - \\export fn a() void { - \\ var ptr: [*c]u8 = (1 << 64) + 1; - \\ _ = ptr; - \\} - \\export fn b() void { - \\ var x: u65 = 0x1234; - \\ var ptr: [*c]u8 = x; - \\ _ = ptr; - \\} - , &[_][]const u8{ - "tmp.zig:2:33: error: integer value 18446744073709551617 cannot be coerced to type 'usize'", - "tmp.zig:7:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8'", - }); - - ctx.objErrStage1("C pointer pointing to non C ABI compatible type or has align attr", - \\const Foo = struct {}; - \\export fn a() void { - \\ const T = [*c]Foo; - \\ var t: T = undefined; - \\ _ = t; - \\} - , &[_][]const u8{ - "tmp.zig:3:19: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'", - }); - - ctx.objErrStage1("compile log statement warning deduplication in generic fn", - \\export fn entry() void { - \\ inner(1); - \\ inner(2); - \\} - \\fn inner(comptime n: usize) void { - \\ comptime var i = 0; - \\ inline while (i < n) : (i += 1) { @compileLog("!@#$"); } - \\} - , &[_][]const u8{ - "tmp.zig:7:39: error: found compile log statement", - }); - - ctx.objErrStage1("assign to invalid dereference", - \\export fn entry() void { - \\ 'a'.* = 1; - \\} - , &[_][]const u8{ - "tmp.zig:2:8: error: attempt to dereference non-pointer type 'comptime_int'", - }); - - ctx.objErrStage1("take slice of invalid dereference", - \\export fn entry() void { - \\ const x = 'a'.*[0..]; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:2:18: error: attempt to dereference non-pointer type 'comptime_int'", - }); - - ctx.objErrStage1("@truncate undefined value", - \\export fn entry() void { - \\ var z = @truncate(u8, @as(u16, undefined)); - \\ _ = z; - \\} - , &[_][]const u8{ - "tmp.zig:2:27: error: use of undefined value here causes undefined behavior", - }); - - ctx.testErrStage1("return invalid type from test", - \\test "example" { return 1; } - , &[_][]const u8{ - "tmp.zig:1:25: error: expected type 'void', found 'comptime_int'", - }); - - ctx.objErrStage1("threadlocal qualifier on const", - \\threadlocal const x: i32 = 1234; - \\export fn entry() i32 { - \\ return x; - \\} - , &[_][]const u8{ - "tmp.zig:1:1: error: threadlocal variable cannot be constant", - }); - - ctx.objErrStage1("@bitCast same size but bit count mismatch", - \\export fn entry(byte: u8) void { - \\ var oops = @bitCast(u7, byte); - \\ _ = oops; - \\} - , &[_][]const u8{ - "tmp.zig:2:25: error: destination type 'u7' has 7 bits but source type 'u8' has 8 bits", - }); - - ctx.objErrStage1("@bitCast with different sizes inside an expression", - \\export fn entry() void { - \\ var foo = (@bitCast(u8, @as(f32, 1.0)) == 0xf); - \\ _ = foo; - \\} - , &[_][]const u8{ - "tmp.zig:2:25: error: destination type 'u8' has size 1 but source type 'f32' has size 4", - }); - - ctx.objErrStage1("attempted `&&`", - \\export fn entry(a: bool, b: bool) i32 { - \\ if (a && b) { - \\ return 1234; - \\ } - \\ return 5678; - \\} - , &[_][]const u8{ - "tmp.zig:2:11: error: ambiguous use of '&&'; use 'and' for logical AND, or change whitespace to ' & &' for bitwise AND", - }); - - ctx.objErrStage1("attempted `||` on boolean values", - \\export fn entry(a: bool, b: bool) i32 { - \\ if (a || b) { - \\ return 1234; - \\ } - \\ return 5678; - \\} - , &[_][]const u8{ - "tmp.zig:2:9: error: expected error set type, found 'bool'", - "tmp.zig:2:11: note: `||` merges error sets; `or` performs boolean OR", - }); - - ctx.objErrStage1("compile log a pointer to an opaque value", - \\export fn entry() void { - \\ @compileLog(@ptrCast(*const anyopaque, &entry)); - \\} - , &[_][]const u8{ - "tmp.zig:2:5: error: found compile log statement", - }); - - ctx.objErrStage1("duplicate boolean switch value", - \\comptime { - \\ const x = switch (true) { - \\ true => false, - \\ false => true, - \\ true => false, - \\ }; - \\ _ = x; - \\} - \\comptime { - \\ const x = switch (true) { - \\ false => true, - \\ true => false, - \\ false => true, - \\ }; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:5:9: error: duplicate switch value", - "tmp.zig:13:9: error: duplicate switch value", - }); - - ctx.objErrStage1("missing boolean switch value", - \\comptime { - \\ const x = switch (true) { - \\ true => false, - \\ }; - \\ _ = x; - \\} - \\comptime { - \\ const x = switch (true) { - \\ false => true, - \\ }; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:2:15: error: switch must handle all possibilities", - "tmp.zig:8:15: error: switch must handle all possibilities", - }); - - ctx.objErrStage1("reading past end of pointer casted array", - \\comptime { - \\ const array: [4]u8 = "aoeu".*; - \\ const sub_array = array[1..]; - \\ const int_ptr = @ptrCast(*const u24, sub_array); - \\ const deref = int_ptr.*; - \\ _ = deref; - \\} - , &[_][]const u8{ - "tmp.zig:5:26: error: attempt to read 4 bytes from [4]u8 at index 1 which is 3 bytes", - }); - - ctx.objErrStage1("error note for function parameter incompatibility", - \\fn do_the_thing(func: fn (arg: i32) void) void { _ = func; } - \\fn bar(arg: bool) void { _ = arg; } - \\export fn entry() void { - \\ do_the_thing(bar); - \\} - , &[_][]const u8{ - "tmp.zig:4:18: error: expected type 'fn(i32) void', found 'fn(bool) void", - "tmp.zig:4:18: note: parameter 0: 'bool' cannot cast into 'i32'", - }); - ctx.objErrStage1("cast negative value to unsigned integer", - \\comptime { - \\ const value: i32 = -1; - \\ const unsigned = @intCast(u32, value); - \\ _ = unsigned; - \\} - \\export fn entry1() void { - \\ const value: i32 = -1; - \\ const unsigned: u32 = value; - \\ _ = unsigned; - \\} - , &[_][]const u8{ - "tmp.zig:3:22: error: attempt to cast negative value to unsigned integer", - "tmp.zig:8:27: error: cannot cast negative value -1 to unsigned integer type 'u32'", - }); - - ctx.objErrStage1("integer cast truncates bits", - \\export fn entry1() void { - \\ const spartan_count: u16 = 300; - \\ const byte = @intCast(u8, spartan_count); - \\ _ = byte; - \\} - \\export fn entry2() void { - \\ const spartan_count: u16 = 300; - \\ const byte: u8 = spartan_count; - \\ _ = byte; - \\} - \\export fn entry3() void { - \\ var spartan_count: u16 = 300; - \\ var byte: u8 = spartan_count; - \\ _ = byte; - \\} - \\export fn entry4() void { - \\ var signed: i8 = -1; - \\ var unsigned: u64 = signed; - \\ _ = unsigned; - \\} - , &[_][]const u8{ - "tmp.zig:3:18: error: cast from 'u16' to 'u8' truncates bits", - "tmp.zig:8:22: error: integer value 300 cannot be coerced to type 'u8'", - "tmp.zig:13:20: error: expected type 'u8', found 'u16'", - "tmp.zig:13:20: note: unsigned 8-bit int cannot represent all possible unsigned 16-bit values", - "tmp.zig:18:25: error: expected type 'u64', found 'i8'", - "tmp.zig:18:25: note: unsigned 64-bit int cannot represent all possible signed 8-bit values", - }); - - ctx.objErrStage1("comptime implicit cast f64 to f32", - \\export fn entry() void { - \\ const x: f64 = 16777217; - \\ const y: f32 = x; - \\ _ = y; - \\} - , &[_][]const u8{ - "tmp.zig:3:20: error: cast of value 16777217.000000 to type 'f32' loses information", - }); - - ctx.objErrStage1("implicit cast from f64 to f32", - \\var x: f64 = 1.0; - \\var y: f32 = x; - \\ - \\export fn entry() usize { return @sizeOf(@TypeOf(y)); } - , &[_][]const u8{ - "tmp.zig:2:14: error: expected type 'f32', found 'f64'", - }); - - ctx.objErrStage1("exceeded maximum bit width of integer", - \\export fn entry1() void { - \\ const T = u65536; - \\ _ = T; - \\} - \\export fn entry2() void { - \\ var x: i65536 = 1; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:2:15: error: primitive integer type 'u65536' exceeds maximum bit width of 65535", - "tmp.zig:6:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535", - }); - - ctx.objErrStage1("compile error when evaluating return type of inferred error set", - \\const Car = struct { - \\ foo: *SymbolThatDoesNotExist, - \\ pub fn init() !Car {} - \\}; - \\export fn entry() void { - \\ const car = Car.init(); - \\ _ = car; - \\} - , &[_][]const u8{ - "tmp.zig:2:11: error: use of undeclared identifier 'SymbolThatDoesNotExist'", - }); - - ctx.objErrStage1("don't implicit cast double pointer to *anyopaque", - \\export fn entry() void { - \\ var a: u32 = 1; - \\ var ptr: *align(@alignOf(u32)) anyopaque = &a; - \\ var b: *u32 = @ptrCast(*u32, ptr); - \\ var ptr2: *anyopaque = &b; - \\ _ = ptr2; - \\} - , &[_][]const u8{ - "tmp.zig:5:29: error: expected type '*anyopaque', found '**u32'", - }); - - ctx.objErrStage1("runtime index into comptime type slice", - \\const Struct = struct { - \\ a: u32, - \\}; - \\fn getIndex() usize { - \\ return 2; - \\} - \\export fn entry() void { - \\ const index = getIndex(); - \\ const field = @typeInfo(Struct).Struct.fields[index]; - \\ _ = field; - \\} - , &[_][]const u8{ - "tmp.zig:9:51: error: values of type 'std.builtin.Type.StructField' must be comptime known, but index value is runtime known", - }); - - ctx.objErrStage1("compile log statement inside function which must be comptime evaluated", - \\fn Foo(comptime T: type) type { - \\ @compileLog(@typeName(T)); - \\ return T; - \\} - \\export fn entry() void { - \\ _ = Foo(i32); - \\ _ = @typeName(Foo(i32)); - \\} - , &[_][]const u8{ - "tmp.zig:2:5: error: found compile log statement", - }); - - ctx.objErrStage1("comptime slice of an undefined slice", - \\comptime { - \\ var a: []u8 = undefined; - \\ var b = a[0..10]; - \\ _ = b; - \\} - , &[_][]const u8{ - "tmp.zig:3:14: error: slice of undefined", - }); - - ctx.objErrStage1("implicit cast const array to mutable slice", - \\export fn entry() void { - \\ const buffer: [1]u8 = [_]u8{8}; - \\ const sliceA: []u8 = &buffer; - \\ _ = sliceA; - \\} - , &[_][]const u8{ - "tmp.zig:3:27: error: cannot cast pointer to array literal to slice type '[]u8'", - "tmp.zig:3:27: note: cast discards const qualifier", - }); - - ctx.objErrStage1("deref slice and get len field", - \\export fn entry() void { - \\ var a: []u8 = undefined; - \\ _ = a.*.len; - \\} - , &[_][]const u8{ - "tmp.zig:3:10: error: attempt to dereference non-pointer type '[]u8'", - }); - - ctx.objErrStage1("@ptrCast a 0 bit type to a non- 0 bit type", - \\export fn entry() bool { - \\ var x: u0 = 0; - \\ const p = @ptrCast(?*u0, &x); - \\ return p == null; - \\} - , &[_][]const u8{ - "tmp.zig:3:15: error: '*u0' and '?*u0' do not have the same in-memory representation", - "tmp.zig:3:31: note: '*u0' has no in-memory bits", - "tmp.zig:3:24: note: '?*u0' has in-memory bits", - }); - - ctx.objErrStage1("comparing a non-optional pointer against null", - \\export fn entry() void { - \\ var x: i32 = 1; - \\ _ = &x == null; - \\} - , &[_][]const u8{ - "tmp.zig:3:12: error: comparison of '*i32' with null", - }); - - ctx.objErrStage1("non error sets used in merge error sets operator", - \\export fn foo() void { - \\ const Errors = u8 || u16; - \\ _ = Errors; - \\} - \\export fn bar() void { - \\ const Errors = error{} || u16; - \\ _ = Errors; - \\} - , &[_][]const u8{ - "tmp.zig:2:20: error: expected error set type, found type 'u8'", - "tmp.zig:2:23: note: `||` merges error sets; `or` performs boolean OR", - "tmp.zig:6:31: error: expected error set type, found type 'u16'", - "tmp.zig:6:28: note: `||` merges error sets; `or` performs boolean OR", - }); - - ctx.objErrStage1("variable initialization compile error then referenced", - \\fn Undeclared() type { - \\ return T; - \\} - \\fn Gen() type { - \\ const X = Undeclared(); - \\ return struct { - \\ x: X, - \\ }; - \\} - \\export fn entry() void { - \\ const S = Gen(); - \\ _ = S; - \\} - , &[_][]const u8{ - "tmp.zig:2:12: error: use of undeclared identifier 'T'", - }); - - ctx.objErrStage1("refer to the type of a generic function", - \\export fn entry() void { - \\ const Func = fn (type) void; - \\ const f: Func = undefined; - \\ f(i32); - \\} - , &[_][]const u8{ - "tmp.zig:4:5: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("accessing runtime parameter from outer function", - \\fn outer(y: u32) fn (u32) u32 { - \\ const st = struct { - \\ fn get(z: u32) u32 { - \\ return z + y; - \\ } - \\ }; - \\ return st.get; - \\} - \\export fn entry() void { - \\ var func = outer(10); - \\ var x = func(3); - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:4:24: error: 'y' not accessible from inner function", - "tmp.zig:3:28: note: crossed function definition here", - "tmp.zig:1:10: note: declared here", - }); - - ctx.objErrStage1("non int passed to @intToFloat", - \\export fn entry() void { - \\ const x = @intToFloat(f32, 1.1); - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:2:32: error: expected int type, found 'comptime_float'", - }); - - ctx.objErrStage1("non float passed to @floatToInt", - \\export fn entry() void { - \\ const x = @floatToInt(i32, @as(i32, 54)); - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:2:32: error: expected float type, found 'i32'", - }); - - ctx.objErrStage1("out of range comptime_int passed to @floatToInt", - \\export fn entry() void { - \\ const x = @floatToInt(i8, 200); - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:2:31: error: integer value 200 cannot be coerced to type 'i8'", - }); - - ctx.objErrStage1("load too many bytes from comptime reinterpreted pointer", - \\export fn entry() void { - \\ const float: f32 = 5.99999999999994648725e-01; - \\ const float_ptr = &float; - \\ const int_ptr = @ptrCast(*const i64, float_ptr); - \\ const int_val = int_ptr.*; - \\ _ = int_val; - \\} - , &[_][]const u8{ - "tmp.zig:5:28: error: attempt to read 8 bytes from pointer to f32 which is 4 bytes", - }); - - ctx.objErrStage1("invalid type used in array type", - \\const Item = struct { - \\ field: SomeNonexistentType, - \\}; - \\var items: [100]Item = undefined; - \\export fn entry() void { - \\ const a = items[0]; - \\ _ = a; - \\} - , &[_][]const u8{ - "tmp.zig:2:12: error: use of undeclared identifier 'SomeNonexistentType'", - }); - - ctx.objErrStage1("comptime continue inside runtime catch", - \\export fn entry() void { - \\ const ints = [_]u8{ 1, 2 }; - \\ inline for (ints) |_| { - \\ bad() catch continue; - \\ } - \\} - \\fn bad() !void { - \\ return error.Bad; - \\} - , &[_][]const u8{ - "tmp.zig:4:21: error: comptime control flow inside runtime block", - "tmp.zig:4:15: note: runtime block created here", - }); - - ctx.objErrStage1("comptime continue inside runtime switch", - \\export fn entry() void { - \\ var p: i32 = undefined; - \\ comptime var q = true; - \\ inline while (q) { - \\ switch (p) { - \\ 11 => continue, - \\ else => {}, - \\ } - \\ q = false; - \\ } - \\} - , &[_][]const u8{ - "tmp.zig:6:19: error: comptime control flow inside runtime block", - "tmp.zig:5:9: note: runtime block created here", - }); - - ctx.objErrStage1("comptime continue inside runtime while error", - \\export fn entry() void { - \\ var p: anyerror!usize = undefined; - \\ comptime var q = true; - \\ outer: inline while (q) { - \\ while (p) |_| { - \\ continue :outer; - \\ } else |_| {} - \\ q = false; - \\ } - \\} - , &[_][]const u8{ - "tmp.zig:6:13: error: comptime control flow inside runtime block", - "tmp.zig:5:9: note: runtime block created here", - }); - - ctx.objErrStage1("comptime continue inside runtime while optional", - \\export fn entry() void { - \\ var p: ?usize = undefined; - \\ comptime var q = true; - \\ outer: inline while (q) { - \\ while (p) |_| continue :outer; - \\ q = false; - \\ } - \\} - , &[_][]const u8{ - "tmp.zig:5:23: error: comptime control flow inside runtime block", - "tmp.zig:5:9: note: runtime block created here", - }); - - ctx.objErrStage1("comptime continue inside runtime while bool", - \\export fn entry() void { - \\ var p: usize = undefined; - \\ comptime var q = true; - \\ outer: inline while (q) { - \\ while (p == 11) continue :outer; - \\ q = false; - \\ } - \\} - , &[_][]const u8{ - "tmp.zig:5:25: error: comptime control flow inside runtime block", - "tmp.zig:5:9: note: runtime block created here", - }); - - ctx.objErrStage1("comptime continue inside runtime if error", - \\export fn entry() void { - \\ var p: anyerror!i32 = undefined; - \\ comptime var q = true; - \\ inline while (q) { - \\ if (p) |_| continue else |_| {} - \\ q = false; - \\ } - \\} - , &[_][]const u8{ - "tmp.zig:5:20: error: comptime control flow inside runtime block", - "tmp.zig:5:9: note: runtime block created here", - }); - - ctx.objErrStage1("comptime continue inside runtime if optional", - \\export fn entry() void { - \\ var p: ?i32 = undefined; - \\ comptime var q = true; - \\ inline while (q) { - \\ if (p) |_| continue; - \\ q = false; - \\ } - \\} - , &[_][]const u8{ - "tmp.zig:5:20: error: comptime control flow inside runtime block", - "tmp.zig:5:9: note: runtime block created here", - }); - - ctx.objErrStage1("comptime continue inside runtime if bool", - \\export fn entry() void { - \\ var p: usize = undefined; - \\ comptime var q = true; - \\ inline while (q) { - \\ if (p == 11) continue; - \\ q = false; - \\ } - \\} - , &[_][]const u8{ - "tmp.zig:5:22: error: comptime control flow inside runtime block", - "tmp.zig:5:9: note: runtime block created here", - }); - - ctx.objErrStage1("switch with invalid expression parameter", - \\export fn entry() void { - \\ Test(i32); - \\} - \\fn Test(comptime T: type) void { - \\ const x = switch (T) { - \\ []u8 => |x| x, - \\ i32 => |x| x, - \\ else => unreachable, - \\ }; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:7:17: error: switch on type 'type' provides no expression parameter", - }); - - ctx.objErrStage1("function prototype with no body", - \\fn foo() void; - \\export fn entry() void { - \\ foo(); - \\} - , &[_][]const u8{ - "tmp.zig:1:1: error: non-extern function has no body", - }); - - ctx.objErrStage1("@frame() called outside of function definition", - \\var handle_undef: anyframe = undefined; - \\var handle_dummy: anyframe = @frame(); - \\export fn entry() bool { - \\ return handle_undef == handle_dummy; - \\} - , &[_][]const u8{ - "tmp.zig:2:30: error: @frame() called outside of function definition", - }); - - ctx.objErrStage1("`_` is not a declarable symbol", - \\export fn f1() usize { - \\ var _: usize = 2; - \\ return _; - \\} - , &[_][]const u8{ - "tmp.zig:2:9: error: '_' used as an identifier without @\"_\" syntax", - }); - - ctx.objErrStage1("`_` should not be usable inside for", - \\export fn returns() void { - \\ for ([_]void{}) |_, i| { - \\ for ([_]void{}) |_, j| { - \\ return _; - \\ } - \\ } - \\} - , &[_][]const u8{ - "tmp.zig:4:20: error: '_' used as an identifier without @\"_\" syntax", - }); - - ctx.objErrStage1("`_` should not be usable inside while", - \\export fn returns() void { - \\ while (optionalReturn()) |_| { - \\ while (optionalReturn()) |_| { - \\ return _; - \\ } - \\ } - \\} - \\fn optionalReturn() ?u32 { - \\ return 1; - \\} - , &[_][]const u8{ - "tmp.zig:4:20: error: '_' used as an identifier without @\"_\" syntax", - }); - - ctx.objErrStage1("`_` should not be usable inside while else", - \\export fn returns() void { - \\ while (optionalReturnError()) |_| { - \\ while (optionalReturnError()) |_| { - \\ return; - \\ } else |_| { - \\ if (_ == error.optionalReturnError) return; - \\ } - \\ } - \\} - \\fn optionalReturnError() !?u32 { - \\ return error.optionalReturnError; - \\} - , &[_][]const u8{ - "tmp.zig:6:17: error: '_' used as an identifier without @\"_\" syntax", - }); - - ctx.objErrStage1("while loop body expression ignored", - \\fn returns() usize { - \\ return 2; - \\} - \\export fn f1() void { - \\ while (true) returns(); - \\} - \\export fn f2() void { - \\ var x: ?i32 = null; - \\ while (x) |_| returns(); - \\} - \\export fn f3() void { - \\ var x: anyerror!i32 = error.Bad; - \\ while (x) |_| returns() else |_| unreachable; - \\} - , &[_][]const u8{ - "tmp.zig:5:25: error: expression value is ignored", - "tmp.zig:9:26: error: expression value is ignored", - "tmp.zig:13:26: error: expression value is ignored", - }); - - ctx.objErrStage1("missing parameter name of generic function", - \\fn dump(anytype) void {} - \\export fn entry() void { - \\ var a: u8 = 9; - \\ dump(a); - \\} - , &[_][]const u8{ - "tmp.zig:1:9: error: missing parameter name", - }); - - ctx.objErrStage1("non-inline for loop on a type that requires comptime", - \\const Foo = struct { - \\ name: []const u8, - \\ T: type, - \\}; - \\export fn entry() void { - \\ const xx: [2]Foo = undefined; - \\ for (xx) |f| { _ = f;} - \\} - , &[_][]const u8{ - "tmp.zig:7:5: error: values of type 'Foo' must be comptime known, but index value is runtime known", - }); - - ctx.objErrStage1("generic fn as parameter without comptime keyword", - \\fn f(_: fn (anytype) void) void {} - \\fn g(_: anytype) void {} - \\export fn entry() void { - \\ f(g); - \\} - , &[_][]const u8{ - "tmp.zig:1:9: error: parameter of type 'fn(anytype) anytype' must be declared comptime", - }); - - ctx.objErrStage1("optional pointer to void in extern struct", - \\const Foo = extern struct { - \\ x: ?*const void, - \\}; - \\const Bar = extern struct { - \\ foo: Foo, - \\ y: i32, - \\}; - \\export fn entry(bar: *Bar) void {_ = bar;} - , &[_][]const u8{ - "tmp.zig:2:5: error: extern structs cannot contain fields of type '?*const void'", - }); - - ctx.objErrStage1("use of comptime-known undefined function value", - \\const Cmd = struct { - \\ exec: fn () void, - \\}; - \\export fn entry() void { - \\ const command = Cmd{ .exec = undefined }; - \\ command.exec(); - \\} - , &[_][]const u8{ - "tmp.zig:6:12: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("use of comptime-known undefined function value", - \\const Cmd = struct { - \\ exec: fn () void, - \\}; - \\export fn entry() void { - \\ const command = Cmd{ .exec = undefined }; - \\ command.exec(); - \\} - , &[_][]const u8{ - "tmp.zig:6:12: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("bad @alignCast at comptime", - \\comptime { - \\ const ptr = @intToPtr(*align(1) i32, 0x1); - \\ const aligned = @alignCast(4, ptr); - \\ _ = aligned; - \\} - , &[_][]const u8{ - "tmp.zig:3:35: error: pointer address 0x1 is not aligned to 4 bytes", - }); - - ctx.objErrStage1("@ptrToInt on *void", - \\export fn entry() bool { - \\ return @ptrToInt(&{}) == @ptrToInt(&{}); - \\} - , &[_][]const u8{ - "tmp.zig:2:23: error: pointer to size 0 type has no address", - }); - - ctx.objErrStage1("@popCount - non-integer", - \\export fn entry(x: f32) u32 { - \\ return @popCount(f32, x); - \\} - , &[_][]const u8{ - "tmp.zig:2:22: error: expected integer type, found 'f32'", - }); - { const case = ctx.obj("wrong same named struct", .{}); case.backend = .stage1; @@ -4066,2558 +275,6 @@ pub fn addCases(ctx: *TestContext) !void { }); } - ctx.objErrStage1("@floatToInt comptime safety", - \\comptime { - \\ _ = @floatToInt(i8, @as(f32, -129.1)); - \\} - \\comptime { - \\ _ = @floatToInt(u8, @as(f32, -1.1)); - \\} - \\comptime { - \\ _ = @floatToInt(u8, @as(f32, 256.1)); - \\} - , &[_][]const u8{ - "tmp.zig:2:9: error: integer value '-129' cannot be stored in type 'i8'", - "tmp.zig:5:9: error: integer value '-1' cannot be stored in type 'u8'", - "tmp.zig:8:9: error: integer value '256' cannot be stored in type 'u8'", - }); - - ctx.objErrStage1("use anyopaque as return type of fn ptr", - \\export fn entry() void { - \\ const a: fn () anyopaque = undefined; - \\ _ = a; - \\} - , &[_][]const u8{ - "tmp.zig:2:20: error: return type cannot be opaque", - }); - - ctx.objErrStage1("use implicit casts to assign null to non-nullable pointer", - \\export fn entry() void { - \\ var x: i32 = 1234; - \\ var p: *i32 = &x; - \\ var pp: *?*i32 = &p; - \\ pp.* = null; - \\ var y = p.*; - \\ _ = y; - \\} - , &[_][]const u8{ - "tmp.zig:4:23: error: expected type '*?*i32', found '**i32'", - }); - - ctx.objErrStage1("attempted implicit cast from T to [*]const T", - \\export fn entry() void { - \\ const x: [*]const bool = true; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:2:30: error: expected type '[*]const bool', found 'bool'", - }); - - ctx.objErrStage1("dereference unknown length pointer", - \\export fn entry(x: [*]i32) i32 { - \\ return x.*; - \\} - , &[_][]const u8{ - "tmp.zig:2:13: error: index syntax required for unknown-length pointer type '[*]i32'", - }); - - ctx.objErrStage1("field access of unknown length pointer", - \\const Foo = extern struct { - \\ a: i32, - \\}; - \\ - \\export fn entry(foo: [*]Foo) void { - \\ foo.a += 1; - \\} - , &[_][]const u8{ - "tmp.zig:6:8: error: type '[*]Foo' does not support field access", - }); - - ctx.objErrStage1("unknown length pointer to opaque", - \\export const T = [*]opaque {}; - , &[_][]const u8{ - "tmp.zig:1:21: error: unknown-length pointer to opaque", - }); - - ctx.objErrStage1("error when evaluating return type", - \\const Foo = struct { - \\ map: @as(i32, i32), - \\ - \\ fn init() Foo { - \\ return undefined; - \\ } - \\}; - \\export fn entry() void { - \\ var rule_set = try Foo.init(); - \\ _ = rule_set; - \\} - , &[_][]const u8{ - "tmp.zig:2:19: error: expected type 'i32', found 'type'", - }); - - ctx.objErrStage1("slicing single-item pointer", - \\export fn entry(ptr: *i32) void { - \\ const slice = ptr[0..2]; - \\ _ = slice; - \\} - , &[_][]const u8{ - "tmp.zig:2:22: error: slice of single-item pointer", - }); - - ctx.objErrStage1("indexing single-item pointer", - \\export fn entry(ptr: *i32) i32 { - \\ return ptr[1]; - \\} - , &[_][]const u8{ - "tmp.zig:2:15: error: index of single-item pointer", - }); - - ctx.objErrStage1("nested error set mismatch", - \\const NextError = error{NextError}; - \\const OtherError = error{OutOfMemory}; - \\ - \\export fn entry() void { - \\ const a: ?NextError!i32 = foo(); - \\ _ = a; - \\} - \\ - \\fn foo() ?OtherError!i32 { - \\ return null; - \\} - , &[_][]const u8{ - "tmp.zig:5:34: error: expected type '?NextError!i32', found '?OtherError!i32'", - "tmp.zig:5:34: note: optional type child 'OtherError!i32' cannot cast into optional type child 'NextError!i32'", - "tmp.zig:5:34: note: error set 'OtherError' cannot cast into error set 'NextError'", - "tmp.zig:2:26: note: 'error.OutOfMemory' not a member of destination error set", - }); - - ctx.objErrStage1("invalid deref on switch target", - \\comptime { - \\ var tile = Tile.Empty; - \\ switch (tile.*) { - \\ Tile.Empty => {}, - \\ Tile.Filled => {}, - \\ } - \\} - \\const Tile = enum { - \\ Empty, - \\ Filled, - \\}; - , &[_][]const u8{ - "tmp.zig:3:17: error: attempt to dereference non-pointer type 'Tile'", - }); - - ctx.objErrStage1("invalid field access in comptime", - \\comptime { var x = doesnt_exist.whatever; _ = x; } - , &[_][]const u8{ - "tmp.zig:1:20: error: use of undeclared identifier 'doesnt_exist'", - }); - - ctx.objErrStage1("suspend inside suspend block", - \\export fn entry() void { - \\ _ = async foo(); - \\} - \\fn foo() void { - \\ suspend { - \\ suspend { - \\ } - \\ } - \\} - , &[_][]const u8{ - "tmp.zig:6:9: error: cannot suspend inside suspend block", - "tmp.zig:5:5: note: other suspend block here", - }); - - ctx.objErrStage1("assign inline fn to non-comptime var", - \\export fn entry() void { - \\ var a = b; - \\ _ = a; - \\} - \\fn b() callconv(.Inline) void { } - , &[_][]const u8{ - "tmp.zig:2:5: error: functions marked inline must be stored in const or comptime var", - "tmp.zig:5:1: note: declared here", - }); - - ctx.objErrStage1("wrong type passed to @panic", - \\export fn entry() void { - \\ var e = error.Foo; - \\ @panic(e); - \\} - , &[_][]const u8{ - "tmp.zig:3:12: error: expected type '[]const u8', found 'error{Foo}'", - }); - - ctx.objErrStage1("@tagName used on union with no associated enum tag", - \\const FloatInt = extern union { - \\ Float: f32, - \\ Int: i32, - \\}; - \\export fn entry() void { - \\ var fi = FloatInt{.Float = 123.45}; - \\ var tagName = @tagName(fi); - \\ _ = tagName; - \\} - , &[_][]const u8{ - "tmp.zig:7:19: error: union has no associated enum", - "tmp.zig:1:18: note: declared here", - }); - - ctx.objErrStage1("returning error from void async function", - \\export fn entry() void { - \\ _ = async amain(); - \\} - \\fn amain() callconv(.Async) void { - \\ return error.ShouldBeCompileError; - \\} - , &[_][]const u8{ - "tmp.zig:5:17: error: expected type 'void', found 'error{ShouldBeCompileError}'", - }); - - ctx.objErrStage1("@ptrCast discards const qualifier", - \\export fn entry() void { - \\ const x: i32 = 1234; - \\ const y = @ptrCast(*i32, &x); - \\ _ = y; - \\} - , &[_][]const u8{ - "tmp.zig:3:15: error: cast discards const qualifier", - }); - - ctx.objErrStage1("comptime slice of undefined pointer non-zero len", - \\export fn entry() void { - \\ const slice = @as([*]i32, undefined)[0..1]; - \\ _ = slice; - \\} - , &[_][]const u8{ - "tmp.zig:2:41: error: non-zero length slice of undefined pointer", - }); - - ctx.objErrStage1("type checking function pointers", - \\fn a(b: fn (*const u8) void) void { - \\ b('a'); - \\} - \\fn c(d: u8) void {_ = d;} - \\export fn entry() void { - \\ a(c); - \\} - , &[_][]const u8{ - "tmp.zig:6:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void'", - }); - - ctx.objErrStage1("no else prong on switch on global error set", - \\export fn entry() void { - \\ foo(error.A); - \\} - \\fn foo(a: anyerror) void { - \\ switch (a) { - \\ error.A => {}, - \\ } - \\} - , &[_][]const u8{ - "tmp.zig:5:5: error: else prong required when switching on type 'anyerror'", - }); - - ctx.objErrStage1("error not handled in switch", - \\export fn entry() void { - \\ foo(452) catch |err| switch (err) { - \\ error.Foo => {}, - \\ }; - \\} - \\fn foo(x: i32) !void { - \\ switch (x) { - \\ 0 ... 10 => return error.Foo, - \\ 11 ... 20 => return error.Bar, - \\ 21 ... 30 => return error.Baz, - \\ else => {}, - \\ } - \\} - , &[_][]const u8{ - "tmp.zig:2:26: error: error.Baz not handled in switch", - "tmp.zig:2:26: error: error.Bar not handled in switch", - }); - - ctx.objErrStage1("duplicate error in switch", - \\export fn entry() void { - \\ foo(452) catch |err| switch (err) { - \\ error.Foo => {}, - \\ error.Bar => {}, - \\ error.Foo => {}, - \\ else => {}, - \\ }; - \\} - \\fn foo(x: i32) !void { - \\ switch (x) { - \\ 0 ... 10 => return error.Foo, - \\ 11 ... 20 => return error.Bar, - \\ else => {}, - \\ } - \\} - , &[_][]const u8{ - "tmp.zig:5:14: error: duplicate switch value: '@typeInfo(@typeInfo(@TypeOf(foo)).Fn.return_type.?).ErrorUnion.error_set.Foo'", - "tmp.zig:3:14: note: other value here", - }); - - ctx.objErrStage1("invalid cast from integral type to enum", - \\const E = enum(usize) { One, Two }; - \\ - \\export fn entry() void { - \\ foo(1); - \\} - \\ - \\fn foo(x: usize) void { - \\ switch (x) { - \\ E.One => {}, - \\ } - \\} - , &[_][]const u8{ - "tmp.zig:9:10: error: expected type 'usize', found 'E'", - }); - - ctx.objErrStage1("range operator in switch used on error set", - \\export fn entry() void { - \\ try foo(452) catch |err| switch (err) { - \\ error.A ... error.B => {}, - \\ else => {}, - \\ }; - \\} - \\fn foo(x: i32) !void { - \\ switch (x) { - \\ 0 ... 10 => return error.Foo, - \\ 11 ... 20 => return error.Bar, - \\ else => {}, - \\ } - \\} - , &[_][]const u8{ - "tmp.zig:3:17: error: operator not allowed for errors", - }); - - ctx.objErrStage1("inferring error set of function pointer", - \\comptime { - \\ const z: ?fn()!void = null; - \\} - , &[_][]const u8{ - "tmp.zig:2:19: error: function prototype may not have inferred error set", - }); - - ctx.objErrStage1("access non-existent member of error set", - \\const Foo = error{A}; - \\comptime { - \\ const z = Foo.Bar; - \\ _ = z; - \\} - , &[_][]const u8{ - "tmp.zig:3:18: error: no error named 'Bar' in 'Foo'", - }); - - ctx.objErrStage1("error union operator with non error set LHS", - \\comptime { - \\ const z = i32!i32; - \\ var x: z = undefined; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:2:15: error: expected error set type, found type 'i32'", - }); - - ctx.objErrStage1("error equality but sets have no common members", - \\const Set1 = error{A, C}; - \\const Set2 = error{B, D}; - \\export fn entry() void { - \\ foo(Set1.A); - \\} - \\fn foo(x: Set1) void { - \\ if (x == Set2.B) { - \\ - \\ } - \\} - , &[_][]const u8{ - "tmp.zig:7:11: error: error sets 'Set1' and 'Set2' have no common errors", - }); - - ctx.objErrStage1("only equality binary operator allowed for error sets", - \\comptime { - \\ const z = error.A > error.B; - \\ _ = z; - \\} - , &[_][]const u8{ - "tmp.zig:2:23: error: operator not allowed for errors", - }); - - ctx.objErrStage1("explicit error set cast known at comptime violates error sets", - \\const Set1 = error {A, B}; - \\const Set2 = error {A, C}; - \\comptime { - \\ var x = Set1.B; - \\ var y = @errSetCast(Set2, x); - \\ _ = y; - \\} - , &[_][]const u8{ - "tmp.zig:5:13: error: error.B not a member of error set 'Set2'", - }); - - ctx.objErrStage1("cast error union of global error set to error union of smaller error set", - \\const SmallErrorSet = error{A}; - \\export fn entry() void { - \\ var x: SmallErrorSet!i32 = foo(); - \\ _ = x; - \\} - \\fn foo() anyerror!i32 { - \\ return error.B; - \\} - , &[_][]const u8{ - "tmp.zig:3:35: error: expected type 'SmallErrorSet!i32', found 'anyerror!i32'", - "tmp.zig:3:35: note: error set 'anyerror' cannot cast into error set 'SmallErrorSet'", - "tmp.zig:3:35: note: cannot cast global error set into smaller set", - }); - - ctx.objErrStage1("cast global error set to error set", - \\const SmallErrorSet = error{A}; - \\export fn entry() void { - \\ var x: SmallErrorSet = foo(); - \\ _ = x; - \\} - \\fn foo() anyerror { - \\ return error.B; - \\} - , &[_][]const u8{ - "tmp.zig:3:31: error: expected type 'SmallErrorSet', found 'anyerror'", - "tmp.zig:3:31: note: cannot cast global error set into smaller set", - }); - ctx.objErrStage1("recursive inferred error set", - \\export fn entry() void { - \\ foo() catch unreachable; - \\} - \\fn foo() !void { - \\ try foo(); - \\} - , &[_][]const u8{ - "tmp.zig:5:5: error: cannot resolve inferred error set '@typeInfo(@typeInfo(@TypeOf(foo)).Fn.return_type.?).ErrorUnion.error_set': function 'foo' not fully analyzed yet", - }); - - ctx.objErrStage1("implicit cast of error set not a subset", - \\const Set1 = error{A, B}; - \\const Set2 = error{A, C}; - \\export fn entry() void { - \\ foo(Set1.B); - \\} - \\fn foo(set1: Set1) void { - \\ var x: Set2 = set1; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:7:19: error: expected type 'Set2', found 'Set1'", - "tmp.zig:1:23: note: 'error.B' not a member of destination error set", - }); - - ctx.objErrStage1("int to err global invalid number", - \\const Set1 = error{ - \\ A, - \\ B, - \\}; - \\comptime { - \\ var x: u16 = 3; - \\ var y = @intToError(x); - \\ _ = y; - \\} - , &[_][]const u8{ - "tmp.zig:7:13: error: integer value 3 represents no error", - }); - - ctx.objErrStage1("int to err non global invalid number", - \\const Set1 = error{ - \\ A, - \\ B, - \\}; - \\const Set2 = error{ - \\ A, - \\ C, - \\}; - \\comptime { - \\ var x = @errorToInt(Set1.B); - \\ var y = @errSetCast(Set2, @intToError(x)); - \\ _ = y; - \\} - , &[_][]const u8{ - "tmp.zig:11:13: error: error.B not a member of error set 'Set2'", - }); - - ctx.objErrStage1("duplicate error value in error set", - \\const Foo = error { - \\ Bar, - \\ Bar, - \\}; - \\export fn entry() void { - \\ const a: Foo = undefined; - \\ _ = a; - \\} - , &[_][]const u8{ - "tmp.zig:3:5: error: duplicate error set field 'Bar'", - "tmp.zig:2:5: note: previous declaration here", - }); - - ctx.objErrStage1("cast negative integer literal to usize", - \\export fn entry() void { - \\ const x = @as(usize, -10); - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:2:26: error: cannot cast negative value -10 to unsigned integer type 'usize'", - }); - - ctx.objErrStage1("use invalid number literal as array index", - \\var v = 25; - \\export fn entry() void { - \\ var arr: [v]u8 = undefined; - \\ _ = arr; - \\} - , &[_][]const u8{ - "tmp.zig:1:1: error: unable to infer variable type", - }); - - ctx.objErrStage1("duplicate struct field", - \\const Foo = struct { - \\ Bar: i32, - \\ Bar: usize, - \\}; - \\export fn entry() void { - \\ const a: Foo = undefined; - \\ _ = a; - \\} - , &[_][]const u8{ - "tmp.zig:3:5: error: duplicate struct field: 'Bar'", - "tmp.zig:2:5: note: other field here", - }); - - ctx.objErrStage1("duplicate union field", - \\const Foo = union { - \\ Bar: i32, - \\ Bar: usize, - \\}; - \\export fn entry() void { - \\ const a: Foo = undefined; - \\ _ = a; - \\} - , &[_][]const u8{ - "tmp.zig:3:5: error: duplicate union field: 'Bar'", - "tmp.zig:2:5: note: other field here", - }); - - ctx.objErrStage1("duplicate enum field", - \\const Foo = enum { - \\ Bar, - \\ Bar, - \\}; - \\ - \\export fn entry() void { - \\ const a: Foo = undefined; - \\ _ = a; - \\} - , &[_][]const u8{ - "tmp.zig:3:5: error: duplicate enum field: 'Bar'", - "tmp.zig:2:5: note: other field here", - }); - - ctx.objErrStage1("calling function with naked calling convention", - \\export fn entry() void { - \\ foo(); - \\} - \\fn foo() callconv(.Naked) void { } - , &[_][]const u8{ - "tmp.zig:2:5: error: unable to call function with naked calling convention", - "tmp.zig:4:1: note: declared here", - }); - - ctx.objErrStage1("function with invalid return type", - \\export fn foo() boid {} - , &[_][]const u8{ - "tmp.zig:1:17: error: use of undeclared identifier 'boid'", - }); - - ctx.objErrStage1("function with non-extern non-packed enum parameter", - \\const Foo = enum { A, B, C }; - \\export fn entry(foo: Foo) void { _ = foo; } - , &[_][]const u8{ - "tmp.zig:2:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'", - }); - - ctx.objErrStage1("function with non-extern non-packed struct parameter", - \\const Foo = struct { - \\ A: i32, - \\ B: f32, - \\ C: bool, - \\}; - \\export fn entry(foo: Foo) void { _ = foo; } - , &[_][]const u8{ - "tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'", - }); - - ctx.objErrStage1("function with non-extern non-packed union parameter", - \\const Foo = union { - \\ A: i32, - \\ B: f32, - \\ C: bool, - \\}; - \\export fn entry(foo: Foo) void { _ = foo; } - , &[_][]const u8{ - "tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'", - }); - - ctx.objErrStage1("switch on enum with 1 field with no prongs", - \\const Foo = enum { M }; - \\ - \\export fn entry() void { - \\ var f = Foo.M; - \\ switch (f) {} - \\} - , &[_][]const u8{ - "tmp.zig:5:5: error: enumeration value 'Foo.M' not handled in switch", - }); - - ctx.objErrStage1("shift by negative comptime integer", - \\comptime { - \\ var a = 1 >> -1; - \\ _ = a; - \\} - , &[_][]const u8{ - "tmp.zig:2:18: error: shift by negative value -1", - }); - - ctx.objErrStage1("@panic called at compile time", - \\export fn entry() void { - \\ comptime { - \\ @panic("aoeu",); - \\ } - \\} - , &[_][]const u8{ - "tmp.zig:3:9: error: encountered @panic at compile-time", - }); - - ctx.objErrStage1("wrong return type for main", - \\pub fn main() f32 { } - , &[_][]const u8{ - "error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'", - }); - - ctx.objErrStage1("double ?? on main return value", - \\pub fn main() ??void { - \\} - , &[_][]const u8{ - "error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'", - }); - - ctx.objErrStage1("bad identifier in function with struct defined inside function which references local const", - \\export fn entry() void { - \\ const BlockKind = u32; - \\ - \\ const Block = struct { - \\ kind: BlockKind, - \\ }; - \\ - \\ bogus; - \\ - \\ _ = Block; - \\} - , &[_][]const u8{ - "tmp.zig:8:5: error: use of undeclared identifier 'bogus'", - }); - - ctx.objErrStage1("labeled break not found", - \\export fn entry() void { - \\ blah: while (true) { - \\ while (true) { - \\ break :outer; - \\ } - \\ } - \\} - , &[_][]const u8{ - "tmp.zig:4:20: error: label not found: 'outer'", - }); - - ctx.objErrStage1("labeled continue not found", - \\export fn entry() void { - \\ var i: usize = 0; - \\ blah: while (i < 10) : (i += 1) { - \\ while (true) { - \\ continue :outer; - \\ } - \\ } - \\} - , &[_][]const u8{ - "tmp.zig:5:23: error: label not found: 'outer'", - }); - - ctx.objErrStage1("attempt to use 0 bit type in extern fn", - \\extern fn foo(ptr: fn(*void) callconv(.C) void) void; - \\ - \\export fn entry() void { - \\ foo(bar); - \\} - \\ - \\fn bar(x: *void) callconv(.C) void { _ = x; } - \\export fn entry2() void { - \\ bar(&{}); - \\} - , &[_][]const u8{ - "tmp.zig:1:23: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'C'", - "tmp.zig:7:11: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'C'", - }); - - ctx.objErrStage1("implicit semicolon - block statement", - \\export fn entry() void { - \\ {} - \\ var good = {}; - \\ ({}) - \\ var bad = {}; - \\} - , &[_][]const u8{ - "tmp.zig:4:9: error: expected ';' after statement", - }); - - ctx.objErrStage1("implicit semicolon - block expr", - \\export fn entry() void { - \\ _ = {}; - \\ var good = {}; - \\ _ = {} - \\ var bad = {}; - \\} - , &[_][]const u8{ - "tmp.zig:4:11: error: expected ';' after statement", - }); - - ctx.objErrStage1("implicit semicolon - comptime statement", - \\export fn entry() void { - \\ comptime {} - \\ var good = {}; - \\ comptime ({}) - \\ var bad = {}; - \\} - , &[_][]const u8{ - "tmp.zig:4:18: error: expected ';' after statement", - }); - - ctx.objErrStage1("implicit semicolon - comptime expression", - \\export fn entry() void { - \\ _ = comptime {}; - \\ var good = {}; - \\ _ = comptime {} - \\ var bad = {}; - \\} - , &[_][]const u8{ - "tmp.zig:4:20: error: expected ';' after statement", - }); - - ctx.objErrStage1("implicit semicolon - defer", - \\export fn entry() void { - \\ defer {} - \\ var good = {}; - \\ defer ({}) - \\ var bad = {}; - \\} - , &[_][]const u8{ - "tmp.zig:4:15: error: expected ';' after statement", - }); - - ctx.objErrStage1("implicit semicolon - if statement", - \\export fn entry() void { - \\ if(true) {} - \\ var good = {}; - \\ if(true) ({}) - \\ var bad = {}; - \\} - , &[_][]const u8{ - "tmp.zig:4:18: error: expected ';' or 'else' after statement", - }); - - ctx.objErrStage1("implicit semicolon - if expression", - \\export fn entry() void { - \\ _ = if(true) {}; - \\ var good = {}; - \\ _ = if(true) {} - \\ var bad = {}; - \\} - , &[_][]const u8{ - "tmp.zig:4:20: error: expected ';' after statement", - }); - - ctx.objErrStage1("implicit semicolon - if-else statement", - \\export fn entry() void { - \\ if(true) {} else {} - \\ var good = {}; - \\ if(true) ({}) else ({}) - \\ var bad = {}; - \\} - , &[_][]const u8{ - "tmp.zig:4:28: error: expected ';' after statement", - }); - - ctx.objErrStage1("implicit semicolon - if-else expression", - \\export fn entry() void { - \\ _ = if(true) {} else {}; - \\ var good = {}; - \\ _ = if(true) {} else {} - \\ var bad = {}; - \\} - , &[_][]const u8{ - "tmp.zig:4:28: error: expected ';' after statement", - }); - - ctx.objErrStage1("implicit semicolon - if-else-if statement", - \\export fn entry() void { - \\ if(true) {} else if(true) {} - \\ var good = {}; - \\ if(true) ({}) else if(true) ({}) - \\ var bad = {}; - \\} - , &[_][]const u8{ - "tmp.zig:4:37: error: expected ';' or 'else' after statement", - }); - - ctx.objErrStage1("implicit semicolon - if-else-if expression", - \\export fn entry() void { - \\ _ = if(true) {} else if(true) {}; - \\ var good = {}; - \\ _ = if(true) {} else if(true) {} - \\ var bad = {}; - \\} - , &[_][]const u8{ - "tmp.zig:4:37: error: expected ';' after statement", - }); - - ctx.objErrStage1("implicit semicolon - if-else-if-else statement", - \\export fn entry() void { - \\ if(true) {} else if(true) {} else {} - \\ var good = {}; - \\ if(true) ({}) else if(true) ({}) else ({}) - \\ var bad = {}; - \\} - , &[_][]const u8{ - "tmp.zig:4:47: error: expected ';' after statement", - }); - - ctx.objErrStage1("implicit semicolon - if-else-if-else expression", - \\export fn entry() void { - \\ _ = if(true) {} else if(true) {} else {}; - \\ var good = {}; - \\ _ = if(true) {} else if(true) {} else {} - \\ var bad = {}; - \\} - , &[_][]const u8{ - "tmp.zig:4:45: error: expected ';' after statement", - }); - - ctx.objErrStage1("implicit semicolon - test statement", - \\export fn entry() void { - \\ if (foo()) |_| {} - \\ var good = {}; - \\ if (foo()) |_| ({}) - \\ var bad = {}; - \\} - , &[_][]const u8{ - "tmp.zig:4:24: error: expected ';' or 'else' after statement", - }); - - ctx.objErrStage1("implicit semicolon - test expression", - \\export fn entry() void { - \\ _ = if (foo()) |_| {}; - \\ var good = {}; - \\ _ = if (foo()) |_| {} - \\ var bad = {}; - \\} - , &[_][]const u8{ - "tmp.zig:4:26: error: expected ';' after statement", - }); - - ctx.objErrStage1("implicit semicolon - while statement", - \\export fn entry() void { - \\ while(true) {} - \\ var good = {}; - \\ while(true) 1 - \\ var bad = {}; - \\} - , &[_][]const u8{ - "tmp.zig:4:18: error: expected ';' or 'else' after statement", - }); - - ctx.objErrStage1("implicit semicolon - while expression", - \\export fn entry() void { - \\ _ = while(true) {}; - \\ var good = {}; - \\ _ = while(true) {} - \\ var bad = {}; - \\} - , &[_][]const u8{ - "tmp.zig:4:23: error: expected ';' after statement", - }); - - ctx.objErrStage1("implicit semicolon - while-continue statement", - \\export fn entry() void { - \\ while(true):({}) {} - \\ var good = {}; - \\ while(true):({}) ({}) - \\ var bad = {}; - \\} - , &[_][]const u8{ - "tmp.zig:4:26: error: expected ';' or 'else' after statement", - }); - - ctx.objErrStage1("implicit semicolon - while-continue expression", - \\export fn entry() void { - \\ _ = while(true):({}) {}; - \\ var good = {}; - \\ _ = while(true):({}) {} - \\ var bad = {}; - \\} - , &[_][]const u8{ - "tmp.zig:4:28: error: expected ';' after statement", - }); - - ctx.objErrStage1("implicit semicolon - for statement", - \\export fn entry() void { - \\ for(foo()) |_| {} - \\ var good = {}; - \\ for(foo()) |_| ({}) - \\ var bad = {}; - \\} - , &[_][]const u8{ - "tmp.zig:4:24: error: expected ';' or 'else' after statement", - }); - - ctx.objErrStage1("implicit semicolon - for expression", - \\export fn entry() void { - \\ _ = for(foo()) |_| {}; - \\ var good = {}; - \\ _ = for(foo()) |_| {} - \\ var bad = {}; - \\} - , &[_][]const u8{ - "tmp.zig:4:26: error: expected ';' after statement", - }); - - ctx.objErrStage1("multiple function definitions", - \\fn a() void {} - \\fn a() void {} - \\export fn entry() void { a(); } - , &[_][]const u8{ - "tmp.zig:2:1: error: redeclaration of 'a'", - "tmp.zig:1:1: note: other declaration here", - }); - - ctx.objErrStage1("unreachable with return", - \\fn a() noreturn {return;} - \\export fn entry() void { a(); } - , &[_][]const u8{ - "tmp.zig:1:18: error: expected type 'noreturn', found 'void'", - }); - - ctx.objErrStage1("control reaches end of non-void function", - \\fn a() i32 {} - \\export fn entry() void { _ = a(); } - , &[_][]const u8{ - "tmp.zig:1:12: error: expected type 'i32', found 'void'", - }); - - ctx.objErrStage1("undefined function call", - \\export fn a() void { - \\ b(); - \\} - , &[_][]const u8{ - "tmp.zig:2:5: error: use of undeclared identifier 'b'", - }); - - ctx.objErrStage1("wrong number of arguments", - \\export fn a() void { - \\ c(1); - \\} - \\fn c(d: i32, e: i32, f: i32) void { _ = d; _ = e; _ = f; } - , &[_][]const u8{ - "tmp.zig:2:6: error: expected 3 argument(s), found 1", - }); - - ctx.objErrStage1("invalid type", - \\fn a() bogus {} - \\export fn entry() void { _ = a(); } - , &[_][]const u8{ - "tmp.zig:1:8: error: use of undeclared identifier 'bogus'", - }); - - ctx.objErrStage1("pointer to noreturn", - \\fn a() *noreturn {} - \\export fn entry() void { _ = a(); } - , &[_][]const u8{ - "tmp.zig:1:9: error: pointer to noreturn not allowed", - }); - - ctx.objErrStage1("unreachable code", - \\export fn a() void { - \\ return; - \\ b(); - \\} - \\ - \\fn b() void {} - , &[_][]const u8{ - "tmp.zig:3:6: error: unreachable code", - "tmp.zig:2:5: note: control flow is diverted here", - }); - - ctx.objErrStage1("unreachable code - nested returns", - \\export fn a() i32 { - \\ return return 1; - \\} - , &[_][]const u8{ - "tmp.zig:2:5: error: unreachable code", - "tmp.zig:2:12: note: control flow is diverted here", - }); - - ctx.objErrStage1("unreachable code - double break", - \\export fn a() void { - \\ const b = blk: { - \\ break :blk break :blk @as(u32, 1); - \\ }; - \\} - , &[_][]const u8{ - "tmp.zig:3:9: error: unreachable code", - "tmp.zig:3:20: note: control flow is diverted here", - }); - - ctx.objErrStage1("chained comparison operators", - \\export fn a(value: u32) bool { - \\ return 1 < value < 1000; - \\} - , &[_][]const u8{ - "tmp.zig:2:22: error: comparison operators cannot be chained", - }); - - ctx.objErrStage1("bad import", - \\const bogus = @import("bogus-does-not-exist.zig",); - , &[_][]const u8{ - "tmp.zig:1:23: error: unable to load '${DIR}bogus-does-not-exist.zig': FileNotFound", - }); - - ctx.objErrStage1("undeclared identifier", - \\export fn a() void { - \\ return - \\ b + - \\ c; - \\} - , &[_][]const u8{ - "tmp.zig:3:5: error: use of undeclared identifier 'b'", - }); - - ctx.objErrStage1("parameter redeclaration", - \\fn f(a : i32, a : i32) void { - \\} - \\export fn entry() void { f(1, 2); } - , &[_][]const u8{ - "tmp.zig:1:15: error: redeclaration of function parameter 'a'", - "tmp.zig:1:6: note: previous declaration here", - }); - - ctx.objErrStage1("local variable redeclaration", - \\export fn f() void { - \\ const a : i32 = 0; - \\ var a = 0; - \\} - , &[_][]const u8{ - "tmp.zig:3:9: error: redeclaration of local constant 'a'", - "tmp.zig:2:11: note: previous declaration here", - }); - - ctx.objErrStage1("local variable redeclares parameter", - \\fn f(a : i32) void { - \\ const a = 0; - \\} - \\export fn entry() void { f(1); } - , &[_][]const u8{ - "tmp.zig:2:11: error: redeclaration of function parameter 'a'", - "tmp.zig:1:6: note: previous declaration here", - }); - - ctx.objErrStage1("variable has wrong type", - \\export fn f() i32 { - \\ const a = "a"; - \\ return a; - \\} - , &[_][]const u8{ - "tmp.zig:3:12: error: expected type 'i32', found '*const [1:0]u8'", - }); - - ctx.objErrStage1("if condition is bool, not int", - \\export fn f() void { - \\ if (0) {} - \\} - , &[_][]const u8{ - "tmp.zig:2:9: error: expected type 'bool', found 'comptime_int'", - }); - - ctx.objErrStage1("assign unreachable", - \\export fn f() void { - \\ const a = return; - \\} - , &[_][]const u8{ - "tmp.zig:2:5: error: unreachable code", - "tmp.zig:2:15: note: control flow is diverted here", - }); - - ctx.objErrStage1("unreachable variable", - \\export fn f() void { - \\ const a: noreturn = {}; - \\ _ = a; - \\} - , &[_][]const u8{ - "tmp.zig:2:25: error: expected type 'noreturn', found 'void'", - }); - - ctx.objErrStage1("unreachable parameter", - \\fn f(a: noreturn) void { _ = a; } - \\export fn entry() void { f(); } - , &[_][]const u8{ - "tmp.zig:1:9: error: parameter of type 'noreturn' not allowed", - }); - - ctx.objErrStage1("assign to constant variable", - \\export fn f() void { - \\ const a = 3; - \\ a = 4; - \\} - , &[_][]const u8{ - "tmp.zig:3:9: error: cannot assign to constant", - }); - - ctx.objErrStage1("use of undeclared identifier", - \\export fn f() void { - \\ b = 3; - \\} - , &[_][]const u8{ - "tmp.zig:2:5: error: use of undeclared identifier 'b'", - }); - - ctx.objErrStage1("const is a statement, not an expression", - \\export fn f() void { - \\ (const a = 0); - \\} - , &[_][]const u8{ - "tmp.zig:2:6: error: expected expression, found 'const'", - }); - - ctx.objErrStage1("array access of undeclared identifier", - \\export fn f() void { - \\ i[i] = i[i]; - \\} - , &[_][]const u8{ - "tmp.zig:2:5: error: use of undeclared identifier 'i'", - }); - - ctx.objErrStage1("array access of non array", - \\export fn f() void { - \\ var bad : bool = undefined; - \\ bad[0] = bad[0]; - \\} - \\export fn g() void { - \\ var bad : bool = undefined; - \\ _ = bad[0]; - \\} - , &[_][]const u8{ - "tmp.zig:3:8: error: array access of non-array type 'bool'", - "tmp.zig:7:12: error: array access of non-array type 'bool'", - }); - - ctx.objErrStage1("array access with non integer index", - \\export fn f() void { - \\ var array = "aoeu"; - \\ var bad = false; - \\ array[bad] = array[bad]; - \\} - \\export fn g() void { - \\ var array = "aoeu"; - \\ var bad = false; - \\ _ = array[bad]; - \\} - , &[_][]const u8{ - "tmp.zig:4:11: error: expected type 'usize', found 'bool'", - "tmp.zig:9:15: error: expected type 'usize', found 'bool'", - }); - - ctx.objErrStage1("write to const global variable", - \\const x : i32 = 99; - \\fn f() void { - \\ x = 1; - \\} - \\export fn entry() void { f(); } - , &[_][]const u8{ - "tmp.zig:3:9: error: cannot assign to constant", - }); - - ctx.objErrStage1("missing else clause", - \\fn f(b: bool) void { - \\ const x : i32 = if (b) h: { break :h 1; }; - \\ _ = x; - \\} - \\fn g(b: bool) void { - \\ const y = if (b) h: { break :h @as(i32, 1); }; - \\ _ = y; - \\} - \\export fn entry() void { f(true); g(true); } - , &[_][]const u8{ - "tmp.zig:2:21: error: expected type 'i32', found 'void'", - "tmp.zig:6:15: error: incompatible types: 'i32' and 'void'", - }); - - ctx.objErrStage1("invalid struct field", - \\const A = struct { x : i32, }; - \\export fn f() void { - \\ var a : A = undefined; - \\ a.foo = 1; - \\ const y = a.bar; - \\ _ = y; - \\} - \\export fn g() void { - \\ var a : A = undefined; - \\ const y = a.bar; - \\ _ = y; - \\} - , &[_][]const u8{ - "tmp.zig:4:6: error: no member named 'foo' in struct 'A'", - "tmp.zig:10:16: error: no member named 'bar' in struct 'A'", - }); - - ctx.objErrStage1("redefinition of struct", - \\const A = struct { x : i32, }; - \\const A = struct { y : i32, }; - , &[_][]const u8{ - "tmp.zig:2:1: error: redeclaration of 'A'", - "tmp.zig:1:1: note: other declaration here", - }); - - ctx.objErrStage1("redefinition of enums", - \\const A = enum {x}; - \\const A = enum {x}; - , &[_][]const u8{ - "tmp.zig:2:1: error: redeclaration of 'A'", - "tmp.zig:1:1: note: other declaration here", - }); - - ctx.objErrStage1("redefinition of global variables", - \\var a : i32 = 1; - \\var a : i32 = 2; - , &[_][]const u8{ - "tmp.zig:2:1: error: redeclaration of 'a'", - "tmp.zig:1:1: note: other declaration here", - }); - - ctx.objErrStage1("duplicate field in struct value expression", - \\const A = struct { - \\ x : i32, - \\ y : i32, - \\ z : i32, - \\}; - \\export fn f() void { - \\ const a = A { - \\ .z = 1, - \\ .y = 2, - \\ .x = 3, - \\ .z = 4, - \\ }; - \\ _ = a; - \\} - , &[_][]const u8{ - "tmp.zig:11:9: error: duplicate field", - }); - - ctx.objErrStage1("missing field in struct value expression", - \\const A = struct { - \\ x : i32, - \\ y : i32, - \\ z : i32, - \\}; - \\export fn f() void { - \\ // we want the error on the '{' not the 'A' because - \\ // the A could be a complicated expression - \\ const a = A { - \\ .z = 4, - \\ .y = 2, - \\ }; - \\ _ = a; - \\} - , &[_][]const u8{ - "tmp.zig:9:17: error: missing field: 'x'", - }); - - ctx.objErrStage1("invalid field in struct value expression", - \\const A = struct { - \\ x : i32, - \\ y : i32, - \\ z : i32, - \\}; - \\export fn f() void { - \\ const a = A { - \\ .z = 4, - \\ .y = 2, - \\ .foo = 42, - \\ }; - \\ _ = a; - \\} - , &[_][]const u8{ - "tmp.zig:10:9: error: no member named 'foo' in struct 'A'", - }); - - ctx.objErrStage1("invalid break expression", - \\export fn f() void { - \\ break; - \\} - , &[_][]const u8{ - "tmp.zig:2:5: error: break expression outside loop", - }); - - ctx.objErrStage1("invalid continue expression", - \\export fn f() void { - \\ continue; - \\} - , &[_][]const u8{ - "tmp.zig:2:5: error: continue expression outside loop", - }); - - ctx.objErrStage1("invalid maybe type", - \\export fn f() void { - \\ if (true) |x| { _ = x; } - \\} - , &[_][]const u8{ - "tmp.zig:2:9: error: expected optional type, found 'bool'", - }); - - ctx.objErrStage1("cast unreachable", - \\fn f() i32 { - \\ return @as(i32, return 1); - \\} - \\export fn entry() void { _ = f(); } - , &[_][]const u8{ - "tmp.zig:2:12: error: unreachable code", - "tmp.zig:2:21: note: control flow is diverted here", - }); - - ctx.objErrStage1("invalid builtin fn", - \\fn f() @bogus(foo) { - \\} - \\export fn entry() void { _ = f(); } - , &[_][]const u8{ - "tmp.zig:1:8: error: invalid builtin function: '@bogus'", - }); - - ctx.objErrStage1("noalias on non pointer param", - \\fn f(noalias x: i32) void { _ = x; } - \\export fn entry() void { f(1234); } - , &[_][]const u8{ - "tmp.zig:1:6: error: noalias on non-pointer parameter", - }); - - ctx.objErrStage1("struct init syntax for array", - \\const foo = [3]u16{ .x = 1024 }; - \\comptime { - \\ _ = foo; - \\} - , &[_][]const u8{ - "tmp.zig:1:13: error: initializing array with struct syntax", - }); - - ctx.objErrStage1("type variables must be constant", - \\var foo = u8; - \\export fn entry() foo { - \\ return 1; - \\} - , &[_][]const u8{ - "tmp.zig:1:1: error: variable of type 'type' must be constant", - }); - - ctx.objErrStage1("parameter shadowing global", - \\const Foo = struct {}; - \\fn f(Foo: i32) void {} - \\export fn entry() void { - \\ f(1234); - \\} - , &[_][]const u8{ - "tmp.zig:2:6: error: local shadows declaration of 'Foo'", - "tmp.zig:1:1: note: declared here", - }); - - ctx.objErrStage1("local variable shadowing global", - \\const Foo = struct {}; - \\const Bar = struct {}; - \\ - \\export fn entry() void { - \\ var Bar : i32 = undefined; - \\ _ = Bar; - \\} - , &[_][]const u8{ - "tmp.zig:5:9: error: local shadows declaration of 'Bar'", - "tmp.zig:2:1: note: declared here", - }); - - ctx.objErrStage1("local shadows global that occurs later", - \\pub fn main() void { - \\ var foo = true; - \\ _ = foo; - \\} - \\fn foo() void {} - , &[_][]const u8{ - "tmp.zig:2:9: error: local shadows declaration of 'foo'", - "tmp.zig:5:1: note: declared here", - }); - - ctx.objErrStage1("switch expression - missing enumeration prong", - \\const Number = enum { - \\ One, - \\ Two, - \\ Three, - \\ Four, - \\}; - \\fn f(n: Number) i32 { - \\ switch (n) { - \\ Number.One => 1, - \\ Number.Two => 2, - \\ Number.Three => @as(i32, 3), - \\ } - \\} - \\ - \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } - , &[_][]const u8{ - "tmp.zig:8:5: error: enumeration value 'Number.Four' not handled in switch", - }); - - ctx.objErrStage1("switch expression - duplicate enumeration prong", - \\const Number = enum { - \\ One, - \\ Two, - \\ Three, - \\ Four, - \\}; - \\fn f(n: Number) i32 { - \\ switch (n) { - \\ Number.One => 1, - \\ Number.Two => 2, - \\ Number.Three => @as(i32, 3), - \\ Number.Four => 4, - \\ Number.Two => 2, - \\ } - \\} - \\ - \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } - , &[_][]const u8{ - "tmp.zig:13:15: error: duplicate switch value", - "tmp.zig:10:15: note: other value here", - }); - - ctx.objErrStage1("switch expression - duplicate enumeration prong when else present", - \\const Number = enum { - \\ One, - \\ Two, - \\ Three, - \\ Four, - \\}; - \\fn f(n: Number) i32 { - \\ switch (n) { - \\ Number.One => 1, - \\ Number.Two => 2, - \\ Number.Three => @as(i32, 3), - \\ Number.Four => 4, - \\ Number.Two => 2, - \\ else => 10, - \\ } - \\} - \\ - \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } - , &[_][]const u8{ - "tmp.zig:13:15: error: duplicate switch value", - "tmp.zig:10:15: note: other value here", - }); - - ctx.objErrStage1("switch expression - multiple else prongs", - \\fn f(x: u32) void { - \\ const value: bool = switch (x) { - \\ 1234 => false, - \\ else => true, - \\ else => true, - \\ }; - \\} - \\export fn entry() void { - \\ f(1234); - \\} - , &[_][]const u8{ - "tmp.zig:5:9: error: multiple else prongs in switch expression", - }); - - ctx.objErrStage1("switch expression - non exhaustive integer prongs", - \\fn foo(x: u8) void { - \\ switch (x) { - \\ 0 => {}, - \\ } - \\} - \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } - , &[_][]const u8{ - "tmp.zig:2:5: error: switch must handle all possibilities", - }); - - ctx.objErrStage1("switch expression - duplicate or overlapping integer value", - \\fn foo(x: u8) u8 { - \\ return switch (x) { - \\ 0 ... 100 => @as(u8, 0), - \\ 101 ... 200 => 1, - \\ 201, 203 ... 207 => 2, - \\ 206 ... 255 => 3, - \\ }; - \\} - \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } - , &[_][]const u8{ - "tmp.zig:6:9: error: duplicate switch value", - "tmp.zig:5:14: note: previous value here", - }); - - ctx.objErrStage1("switch expression - duplicate type", - \\fn foo(comptime T: type, x: T) u8 { - \\ _ = x; - \\ return switch (T) { - \\ u32 => 0, - \\ u64 => 1, - \\ u32 => 2, - \\ else => 3, - \\ }; - \\} - \\export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); } - , &[_][]const u8{ - "tmp.zig:6:9: error: duplicate switch value", - "tmp.zig:4:9: note: previous value here", - }); - - ctx.objErrStage1("switch expression - duplicate type (struct alias)", - \\const Test = struct { - \\ bar: i32, - \\}; - \\const Test2 = Test; - \\fn foo(comptime T: type, x: T) u8 { - \\ _ = x; - \\ return switch (T) { - \\ Test => 0, - \\ u64 => 1, - \\ Test2 => 2, - \\ else => 3, - \\ }; - \\} - \\export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); } - , &[_][]const u8{ - "tmp.zig:10:9: error: duplicate switch value", - "tmp.zig:8:9: note: previous value here", - }); - - ctx.objErrStage1("switch expression - switch on pointer type with no else", - \\fn foo(x: *u8) void { - \\ switch (x) { - \\ &y => {}, - \\ } - \\} - \\const y: u8 = 100; - \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } - , &[_][]const u8{ - "tmp.zig:2:5: error: else prong required when switching on type '*u8'", - }); - - ctx.objErrStage1("global variable initializer must be constant expression", - \\extern fn foo() i32; - \\const x = foo(); - \\export fn entry() i32 { return x; } - , &[_][]const u8{ - "tmp.zig:2:11: error: unable to evaluate constant expression", - }); - - ctx.objErrStage1("array concatenation with wrong type", - \\const src = "aoeu"; - \\const derp: usize = 1234; - \\const a = derp ++ "foo"; - \\ - \\export fn entry() usize { return @sizeOf(@TypeOf(a)); } - , &[_][]const u8{ - "tmp.zig:3:11: error: expected array, found 'usize'", - }); - - ctx.objErrStage1("non compile time array concatenation", - \\fn f() []u8 { - \\ return s ++ "foo"; - \\} - \\var s: [10]u8 = undefined; - \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } - , &[_][]const u8{ - "tmp.zig:2:12: error: unable to evaluate constant expression", - }); - - ctx.objErrStage1("@cImport with bogus include", - \\const c = @cImport(@cInclude("bogus.h")); - \\export fn entry() usize { return @sizeOf(@TypeOf(c.bogo)); } - , &[_][]const u8{ - "tmp.zig:1:11: error: C import failed", - ".h:1:10: note: 'bogus.h' file not found", - }); - - ctx.objErrStage1("address of number literal", - \\const x = 3; - \\const y = &x; - \\fn foo() *const i32 { return y; } - \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } - , &[_][]const u8{ - "tmp.zig:3:30: error: expected type '*const i32', found '*const comptime_int'", - }); - - ctx.objErrStage1("integer overflow error", - \\const x : u8 = 300; - \\export fn entry() usize { return @sizeOf(@TypeOf(x)); } - , &[_][]const u8{ - "tmp.zig:1:16: error: integer value 300 cannot be coerced to type 'u8'", - }); - - ctx.objErrStage1("invalid shift amount error", - \\const x : u8 = 2; - \\fn f() u16 { - \\ return x << 8; - \\} - \\export fn entry() u16 { return f(); } - , &[_][]const u8{ - "tmp.zig:3:17: error: integer value 8 cannot be coerced to type 'u3'", - }); - - ctx.objErrStage1("missing function call param", - \\const Foo = struct { - \\ a: i32, - \\ b: i32, - \\ - \\ fn member_a(foo: *const Foo) i32 { - \\ return foo.a; - \\ } - \\ fn member_b(foo: *const Foo) i32 { - \\ return foo.b; - \\ } - \\}; - \\ - \\const member_fn_type = @TypeOf(Foo.member_a); - \\const members = [_]member_fn_type { - \\ Foo.member_a, - \\ Foo.member_b, - \\}; - \\ - \\fn f(foo: *const Foo, index: usize) void { - \\ const result = members[index](); - \\ _ = foo; - \\ _ = result; - \\} - \\ - \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } - , &[_][]const u8{ - "tmp.zig:20:34: error: expected 1 argument(s), found 0", - }); - - ctx.objErrStage1("missing function name", - \\fn () void {} - \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } - , &[_][]const u8{ - "tmp.zig:1:1: error: missing function name", - }); - - ctx.objErrStage1("missing param name", - \\fn f(i32) void {} - \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } - , &[_][]const u8{ - "tmp.zig:1:6: error: missing parameter name", - }); - - ctx.objErrStage1("wrong function type", - \\const fns = [_]fn() void { a, b, c }; - \\fn a() i32 {return 0;} - \\fn b() i32 {return 1;} - \\fn c() i32 {return 2;} - \\export fn entry() usize { return @sizeOf(@TypeOf(fns)); } - , &[_][]const u8{ - "tmp.zig:1:28: error: expected type 'fn() void', found 'fn() i32'", - }); - - ctx.objErrStage1("extern function pointer mismatch", - \\const fns = [_](fn(i32)i32) { a, b, c }; - \\pub fn a(x: i32) i32 {return x + 0;} - \\pub fn b(x: i32) i32 {return x + 1;} - \\export fn c(x: i32) i32 {return x + 2;} - \\ - \\export fn entry() usize { return @sizeOf(@TypeOf(fns)); } - , &[_][]const u8{ - "tmp.zig:1:37: error: expected type 'fn(i32) i32', found 'fn(i32) callconv(.C) i32'", - }); - - ctx.objErrStage1("colliding invalid top level functions", - \\fn func() bogus {} - \\fn func() bogus {} - \\export fn entry() usize { return @sizeOf(@TypeOf(func)); } - , &[_][]const u8{ - "tmp.zig:2:1: error: redeclaration of 'func'", - "tmp.zig:1:1: note: other declaration here", - }); - - ctx.objErrStage1("non constant expression in array size", - \\const Foo = struct { - \\ y: [get()]u8, - \\}; - \\var global_var: usize = 1; - \\fn get() usize { return global_var; } - \\ - \\export fn entry() usize { return @sizeOf(@TypeOf(Foo)); } - , &[_][]const u8{ - "tmp.zig:5:25: error: cannot store runtime value in compile time variable", - "tmp.zig:2:12: note: called from here", - }); - - ctx.objErrStage1("addition with non numbers", - \\const Foo = struct { - \\ field: i32, - \\}; - \\const x = Foo {.field = 1} + Foo {.field = 2}; - \\ - \\export fn entry() usize { return @sizeOf(@TypeOf(x)); } - , &[_][]const u8{ - "tmp.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'", - }); - - ctx.objErrStage1("division by zero", - \\const lit_int_x = 1 / 0; - \\const lit_float_x = 1.0 / 0.0; - \\const int_x = @as(u32, 1) / @as(u32, 0); - \\const float_x = @as(f32, 1.0) / @as(f32, 0.0); - \\ - \\export fn entry1() usize { return @sizeOf(@TypeOf(lit_int_x)); } - \\export fn entry2() usize { return @sizeOf(@TypeOf(lit_float_x)); } - \\export fn entry3() usize { return @sizeOf(@TypeOf(int_x)); } - \\export fn entry4() usize { return @sizeOf(@TypeOf(float_x)); } - , &[_][]const u8{ - "tmp.zig:1:21: error: division by zero", - "tmp.zig:2:25: error: division by zero", - "tmp.zig:3:27: error: division by zero", - "tmp.zig:4:31: error: division by zero", - }); - - ctx.objErrStage1("normal string with newline", - \\const foo = "a - \\b"; - , &[_][]const u8{ - "tmp.zig:1:13: error: expected expression, found 'invalid bytes'", - "tmp.zig:1:15: note: invalid byte: '\\n'", - }); - - ctx.objErrStage1("invalid comparison for function pointers", - \\fn foo() void {} - \\const invalid = foo > foo; - \\ - \\export fn entry() usize { return @sizeOf(@TypeOf(invalid)); } - , &[_][]const u8{ - "tmp.zig:2:21: error: operator not allowed for type 'fn() void'", - }); - - ctx.objErrStage1("generic function instance with non-constant expression", - \\fn foo(comptime x: i32, y: i32) i32 { return x + y; } - \\fn test1(a: i32, b: i32) i32 { - \\ return foo(a, b); - \\} - \\ - \\export fn entry() usize { return @sizeOf(@TypeOf(test1)); } - , &[_][]const u8{ - "tmp.zig:3:16: error: runtime value cannot be passed to comptime arg", - }); - - ctx.objErrStage1("assign null to non-optional pointer", - \\const a: *u8 = null; - \\ - \\export fn entry() usize { return @sizeOf(@TypeOf(a)); } - , &[_][]const u8{ - "tmp.zig:1:16: error: expected type '*u8', found '@Type(.Null)'", - }); - - ctx.objErrStage1("indexing an array of size zero", - \\const array = [_]u8{}; - \\export fn foo() void { - \\ const pointer = &array[0]; - \\ _ = pointer; - \\} - , &[_][]const u8{ - "tmp.zig:3:27: error: accessing a zero length array is not allowed", - }); - - ctx.objErrStage1("indexing an array of size zero with runtime index", - \\const array = [_]u8{}; - \\export fn foo() void { - \\ var index: usize = 0; - \\ const pointer = &array[index]; - \\ _ = pointer; - \\} - , &[_][]const u8{ - "tmp.zig:4:27: error: accessing a zero length array is not allowed", - }); - - ctx.objErrStage1("compile time division by zero", - \\const y = foo(0); - \\fn foo(x: u32) u32 { - \\ return 1 / x; - \\} - \\ - \\export fn entry() usize { return @sizeOf(@TypeOf(y)); } - , &[_][]const u8{ - "tmp.zig:3:14: error: division by zero", - }); - - ctx.objErrStage1("branch on undefined value", - \\const x = if (undefined) true else false; - \\ - \\export fn entry() usize { return @sizeOf(@TypeOf(x)); } - , &[_][]const u8{ - "tmp.zig:1:15: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("div on undefined value", - \\comptime { - \\ var a: i64 = undefined; - \\ _ = a / a; - \\} - , &[_][]const u8{ - "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("div assign on undefined value", - \\comptime { - \\ var a: i64 = undefined; - \\ a /= a; - \\} - , &[_][]const u8{ - "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("mod on undefined value", - \\comptime { - \\ var a: i64 = undefined; - \\ _ = a % a; - \\} - , &[_][]const u8{ - "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("mod assign on undefined value", - \\comptime { - \\ var a: i64 = undefined; - \\ a %= a; - \\} - , &[_][]const u8{ - "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("add on undefined value", - \\comptime { - \\ var a: i64 = undefined; - \\ _ = a + a; - \\} - , &[_][]const u8{ - "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("add assign on undefined value", - \\comptime { - \\ var a: i64 = undefined; - \\ a += a; - \\} - , &[_][]const u8{ - "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("add wrap on undefined value", - \\comptime { - \\ var a: i64 = undefined; - \\ _ = a +% a; - \\} - , &[_][]const u8{ - "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("add wrap assign on undefined value", - \\comptime { - \\ var a: i64 = undefined; - \\ a +%= a; - \\} - , &[_][]const u8{ - "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("sub on undefined value", - \\comptime { - \\ var a: i64 = undefined; - \\ _ = a - a; - \\} - , &[_][]const u8{ - "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("sub assign on undefined value", - \\comptime { - \\ var a: i64 = undefined; - \\ a -= a; - \\} - , &[_][]const u8{ - "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("sub wrap on undefined value", - \\comptime { - \\ var a: i64 = undefined; - \\ _ = a -% a; - \\} - , &[_][]const u8{ - "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("sub wrap assign on undefined value", - \\comptime { - \\ var a: i64 = undefined; - \\ a -%= a; - \\} - , &[_][]const u8{ - "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("mult on undefined value", - \\comptime { - \\ var a: i64 = undefined; - \\ _ = a * a; - \\} - , &[_][]const u8{ - "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("mult assign on undefined value", - \\comptime { - \\ var a: i64 = undefined; - \\ a *= a; - \\} - , &[_][]const u8{ - "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("mult wrap on undefined value", - \\comptime { - \\ var a: i64 = undefined; - \\ _ = a *% a; - \\} - , &[_][]const u8{ - "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("mult wrap assign on undefined value", - \\comptime { - \\ var a: i64 = undefined; - \\ a *%= a; - \\} - , &[_][]const u8{ - "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("shift left on undefined value", - \\comptime { - \\ var a: i64 = undefined; - \\ _ = a << 2; - \\} - , &[_][]const u8{ - "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("shift left assign on undefined value", - \\comptime { - \\ var a: i64 = undefined; - \\ a <<= 2; - \\} - , &[_][]const u8{ - "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("shift right on undefined value", - \\comptime { - \\ var a: i64 = undefined; - \\ _ = a >> 2; - \\} - , &[_][]const u8{ - "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("shift left assign on undefined value", - \\comptime { - \\ var a: i64 = undefined; - \\ a >>= 2; - \\} - , &[_][]const u8{ - "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("bin and on undefined value", - \\comptime { - \\ var a: i64 = undefined; - \\ _ = a & a; - \\} - , &[_][]const u8{ - "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("bin and assign on undefined value", - \\comptime { - \\ var a: i64 = undefined; - \\ a &= a; - \\} - , &[_][]const u8{ - "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("bin or on undefined value", - \\comptime { - \\ var a: i64 = undefined; - \\ _ = a | a; - \\} - , &[_][]const u8{ - "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("bin or assign on undefined value", - \\comptime { - \\ var a: i64 = undefined; - \\ a |= a; - \\} - , &[_][]const u8{ - "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("bin xor on undefined value", - \\comptime { - \\ var a: i64 = undefined; - \\ _ = a ^ a; - \\} - , &[_][]const u8{ - "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("bin xor assign on undefined value", - \\comptime { - \\ var a: i64 = undefined; - \\ a ^= a; - \\} - , &[_][]const u8{ - "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("comparison operators with undefined value", - \\// operator == - \\comptime { - \\ var a: i64 = undefined; - \\ var x: i32 = 0; - \\ if (a == a) x += 1; - \\} - \\// operator != - \\comptime { - \\ var a: i64 = undefined; - \\ var x: i32 = 0; - \\ if (a != a) x += 1; - \\} - \\// operator > - \\comptime { - \\ var a: i64 = undefined; - \\ var x: i32 = 0; - \\ if (a > a) x += 1; - \\} - \\// operator < - \\comptime { - \\ var a: i64 = undefined; - \\ var x: i32 = 0; - \\ if (a < a) x += 1; - \\} - \\// operator >= - \\comptime { - \\ var a: i64 = undefined; - \\ var x: i32 = 0; - \\ if (a >= a) x += 1; - \\} - \\// operator <= - \\comptime { - \\ var a: i64 = undefined; - \\ var x: i32 = 0; - \\ if (a <= a) x += 1; - \\} - , &[_][]const u8{ - "tmp.zig:5:11: error: use of undefined value here causes undefined behavior", - "tmp.zig:11:11: error: use of undefined value here causes undefined behavior", - "tmp.zig:17:11: error: use of undefined value here causes undefined behavior", - "tmp.zig:23:11: error: use of undefined value here causes undefined behavior", - "tmp.zig:29:11: error: use of undefined value here causes undefined behavior", - "tmp.zig:35:11: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("and on undefined value", - \\comptime { - \\ var a: bool = undefined; - \\ _ = a and a; - \\} - , &[_][]const u8{ - "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("or on undefined value", - \\comptime { - \\ var a: bool = undefined; - \\ _ = a or a; - \\} - , &[_][]const u8{ - "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("negate on undefined value", - \\comptime { - \\ var a: i64 = undefined; - \\ _ = -a; - \\} - , &[_][]const u8{ - "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("negate wrap on undefined value", - \\comptime { - \\ var a: i64 = undefined; - \\ _ = -%a; - \\} - , &[_][]const u8{ - "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("bin not on undefined value", - \\comptime { - \\ var a: i64 = undefined; - \\ _ = ~a; - \\} - , &[_][]const u8{ - "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("bool not on undefined value", - \\comptime { - \\ var a: bool = undefined; - \\ _ = !a; - \\} - , &[_][]const u8{ - "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("orelse on undefined value", - \\comptime { - \\ var a: ?bool = undefined; - \\ _ = a orelse false; - \\} - , &[_][]const u8{ - "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("catch on undefined value", - \\comptime { - \\ var a: anyerror!bool = undefined; - \\ _ = a catch false; - \\} - , &[_][]const u8{ - "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("deref on undefined value", - \\comptime { - \\ var a: *u8 = undefined; - \\ _ = a.*; - \\} - , &[_][]const u8{ - "tmp.zig:3:9: error: attempt to dereference undefined value", - }); - - ctx.objErrStage1("endless loop in function evaluation", - \\const seventh_fib_number = fibonacci(7); - \\fn fibonacci(x: i32) i32 { - \\ return fibonacci(x - 1) + fibonacci(x - 2); - \\} - \\ - \\export fn entry() usize { return @sizeOf(@TypeOf(seventh_fib_number)); } - , &[_][]const u8{ - "tmp.zig:3:21: error: evaluation exceeded 1000 backwards branches", - }); - - ctx.objErrStage1("@embedFile with bogus file", - \\const resource = @embedFile("bogus.txt",); - \\ - \\export fn entry() usize { return @sizeOf(@TypeOf(resource)); } - , &[_][]const u8{ - "tmp.zig:1:29: error: unable to find '", - }); - - ctx.objErrStage1("non-const expression in struct literal outside function", - \\const Foo = struct { - \\ x: i32, - \\}; - \\const a = Foo {.x = get_it()}; - \\extern fn get_it() i32; - \\ - \\export fn entry() usize { return @sizeOf(@TypeOf(a)); } - , &[_][]const u8{ - "tmp.zig:4:21: error: unable to evaluate constant expression", - }); - - ctx.objErrStage1("non-const expression function call with struct return value outside function", - \\const Foo = struct { - \\ x: i32, - \\}; - \\const a = get_it(); - \\fn get_it() Foo { - \\ global_side_effect = true; - \\ return Foo {.x = 13}; - \\} - \\var global_side_effect = false; - \\ - \\export fn entry() usize { return @sizeOf(@TypeOf(a)); } - , &[_][]const u8{ - "tmp.zig:6:26: error: unable to evaluate constant expression", - }); - - ctx.objErrStage1("undeclared identifier error should mark fn as impure", - \\export fn foo() void { - \\ test_a_thing(); - \\} - \\fn test_a_thing() void { - \\ bad_fn_call(); - \\} - , &[_][]const u8{ - "tmp.zig:5:5: error: use of undeclared identifier 'bad_fn_call'", - }); - - ctx.objErrStage1("illegal comparison of types", - \\fn bad_eql_1(a: []u8, b: []u8) bool { - \\ return a == b; - \\} - \\const EnumWithData = union(enum) { - \\ One: void, - \\ Two: i32, - \\}; - \\fn bad_eql_2(a: *const EnumWithData, b: *const EnumWithData) bool { - \\ return a.* == b.*; - \\} - \\ - \\export fn entry1() usize { return @sizeOf(@TypeOf(bad_eql_1)); } - \\export fn entry2() usize { return @sizeOf(@TypeOf(bad_eql_2)); } - , &[_][]const u8{ - "tmp.zig:2:14: error: operator not allowed for type '[]u8'", - "tmp.zig:9:16: error: operator not allowed for type 'EnumWithData'", - }); - - ctx.objErrStage1("non-const switch number literal", - \\export fn foo() void { - \\ const x = switch (bar()) { - \\ 1, 2 => 1, - \\ 3, 4 => 2, - \\ else => 3, - \\ }; - \\ _ = x; - \\} - \\fn bar() i32 { - \\ return 2; - \\} - , &[_][]const u8{ - "tmp.zig:5:17: error: cannot store runtime value in type 'comptime_int'", - }); - - ctx.objErrStage1("atomic orderings of cmpxchg - failure stricter than success", - \\const AtomicOrder = @import("std").builtin.AtomicOrder; - \\export fn f() void { - \\ var x: i32 = 1234; - \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {} - \\} - , &[_][]const u8{ - "tmp.zig:4:81: error: failure atomic ordering must be no stricter than success", - }); - - ctx.objErrStage1("atomic orderings of cmpxchg - success Monotonic or stricter", - \\const AtomicOrder = @import("std").builtin.AtomicOrder; - \\export fn f() void { - \\ var x: i32 = 1234; - \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {} - \\} - , &[_][]const u8{ - "tmp.zig:4:58: error: success atomic ordering must be Monotonic or stricter", - }); - - ctx.objErrStage1("negation overflow in function evaluation", - \\const y = neg(-128); - \\fn neg(x: i8) i8 { - \\ return -x; - \\} - \\ - \\export fn entry() usize { return @sizeOf(@TypeOf(y)); } - , &[_][]const u8{ - "tmp.zig:3:12: error: negation caused overflow", - }); - - ctx.objErrStage1("add overflow in function evaluation", - \\const y = add(65530, 10); - \\fn add(a: u16, b: u16) u16 { - \\ return a + b; - \\} - \\ - \\export fn entry() usize { return @sizeOf(@TypeOf(y)); } - , &[_][]const u8{ - "tmp.zig:3:14: error: operation caused overflow", - }); - - ctx.objErrStage1("sub overflow in function evaluation", - \\const y = sub(10, 20); - \\fn sub(a: u16, b: u16) u16 { - \\ return a - b; - \\} - \\ - \\export fn entry() usize { return @sizeOf(@TypeOf(y)); } - , &[_][]const u8{ - "tmp.zig:3:14: error: operation caused overflow", - }); - - ctx.objErrStage1("mul overflow in function evaluation", - \\const y = mul(300, 6000); - \\fn mul(a: u16, b: u16) u16 { - \\ return a * b; - \\} - \\ - \\export fn entry() usize { return @sizeOf(@TypeOf(y)); } - , &[_][]const u8{ - "tmp.zig:3:14: error: operation caused overflow", - }); - - ctx.objErrStage1("truncate sign mismatch", - \\export fn entry1() i8 { - \\ var x: u32 = 10; - \\ return @truncate(i8, x); - \\} - \\export fn entry2() u8 { - \\ var x: i32 = -10; - \\ return @truncate(u8, x); - \\} - \\export fn entry3() i8 { - \\ comptime var x: u32 = 10; - \\ return @truncate(i8, x); - \\} - \\export fn entry4() u8 { - \\ comptime var x: i32 = -10; - \\ return @truncate(u8, x); - \\} - , &[_][]const u8{ - "tmp.zig:3:26: error: expected signed integer type, found 'u32'", - "tmp.zig:7:26: error: expected unsigned integer type, found 'i32'", - "tmp.zig:11:26: error: expected signed integer type, found 'u32'", - "tmp.zig:15:26: error: expected unsigned integer type, found 'i32'", - }); - - ctx.objErrStage1("try in function with non error return type", - \\export fn f() void { - \\ try something(); - \\} - \\fn something() anyerror!void { } - , &[_][]const u8{ - "tmp.zig:2:5: error: expected type 'void', found 'anyerror'", - }); - - ctx.objErrStage1("invalid pointer for var type", - \\extern fn ext() usize; - \\var bytes: [ext()]u8 = undefined; - \\export fn f() void { - \\ for (bytes) |*b, i| { - \\ b.* = @as(u8, i); - \\ } - \\} - , &[_][]const u8{ - "tmp.zig:2:13: error: unable to evaluate constant expression", - }); - - ctx.objErrStage1("export function with comptime parameter", - \\export fn foo(comptime x: i32, y: i32) i32{ - \\ return x + y; - \\} - , &[_][]const u8{ - "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C'", - }); - - ctx.objErrStage1("extern function with comptime parameter", - \\extern fn foo(comptime x: i32, y: i32) i32; - \\fn f() i32 { - \\ return foo(1, 2); - \\} - \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } - , &[_][]const u8{ - "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C'", - }); - - ctx.objErrStage1("non-pure function returns type", - \\var a: u32 = 0; - \\pub fn List(comptime T: type) type { - \\ a += 1; - \\ return SmallList(T, 8); - \\} - \\ - \\pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) type { - \\ return struct { - \\ items: []T, - \\ length: usize, - \\ prealloc_items: [STATIC_SIZE]T, - \\ }; - \\} - \\ - \\export fn function_with_return_type_type() void { - \\ var list: List(i32) = undefined; - \\ list.length = 10; - \\} - , &[_][]const u8{ - "tmp.zig:3:7: error: unable to evaluate constant expression", - }); - - ctx.objErrStage1("bogus method call on slice", - \\var self = "aoeu"; - \\fn f(m: []const u8) void { - \\ m.copy(u8, self[0..], m); - \\} - \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } - , &[_][]const u8{ - "tmp.zig:3:6: error: no member named 'copy' in '[]const u8'", - }); - - ctx.objErrStage1("wrong number of arguments for method fn call", - \\const Foo = struct { - \\ fn method(self: *const Foo, a: i32) void {_ = self; _ = a;} - \\}; - \\fn f(foo: *const Foo) void { - \\ - \\ foo.method(1, 2); - \\} - \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } - , &[_][]const u8{ - "tmp.zig:6:15: error: expected 2 argument(s), found 3", - }); - - ctx.objErrStage1("assign through constant pointer", - \\export fn f() void { - \\ var cstr = "Hat"; - \\ cstr[0] = 'W'; - \\} - , &[_][]const u8{ - "tmp.zig:3:13: error: cannot assign to constant", - }); - - ctx.objErrStage1("assign through constant slice", - \\export fn f() void { - \\ var cstr: []const u8 = "Hat"; - \\ cstr[0] = 'W'; - \\} - , &[_][]const u8{ - "tmp.zig:3:13: error: cannot assign to constant", - }); - - ctx.objErrStage1("main function with bogus args type", - \\pub fn main(args: [][]bogus) !void {_ = args;} - , &[_][]const u8{ - "tmp.zig:1:23: error: use of undeclared identifier 'bogus'", - }); - - ctx.objErrStage1("misspelled type with pointer only reference", - \\const JasonHM = u8; - \\const JasonList = *JsonNode; - \\ - \\const JsonOA = union(enum) { - \\ JSONArray: JsonList, - \\ JSONObject: JasonHM, - \\}; - \\ - \\const JsonType = union(enum) { - \\ JSONNull: void, - \\ JSONInteger: isize, - \\ JSONDouble: f64, - \\ JSONBool: bool, - \\ JSONString: []u8, - \\ JSONArray: void, - \\ JSONObject: void, - \\}; - \\ - \\pub const JsonNode = struct { - \\ kind: JsonType, - \\ jobject: ?JsonOA, - \\}; - \\ - \\fn foo() void { - \\ var jll: JasonList = undefined; - \\ jll.init(1234); - \\ var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} }; - \\ _ = jd; - \\} - \\ - \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } - , &[_][]const u8{ - "tmp.zig:5:16: error: use of undeclared identifier 'JsonList'", - }); - - ctx.objErrStage1("method call with first arg type primitive", - \\const Foo = struct { - \\ x: i32, - \\ - \\ fn init(x: i32) Foo { - \\ return Foo { - \\ .x = x, - \\ }; - \\ } - \\}; - \\ - \\export fn f() void { - \\ const derp = Foo.init(3); - \\ - \\ derp.init(); - \\} - , &[_][]const u8{ - "tmp.zig:14:5: error: expected type 'i32', found 'Foo'", - }); - - ctx.objErrStage1("method call with first arg type wrong container", - \\pub const List = struct { - \\ len: usize, - \\ allocator: *Allocator, - \\ - \\ pub fn init(allocator: *Allocator) List { - \\ return List { - \\ .len = 0, - \\ .allocator = allocator, - \\ }; - \\ } - \\}; - \\ - \\pub var global_allocator = Allocator { - \\ .field = 1234, - \\}; - \\ - \\pub const Allocator = struct { - \\ field: i32, - \\}; - \\ - \\export fn foo() void { - \\ var x = List.init(&global_allocator); - \\ x.init(); - \\} - , &[_][]const u8{ - "tmp.zig:23:5: error: expected type '*Allocator', found '*List'", - }); - - ctx.objErrStage1("binary not on number literal", - \\const TINY_QUANTUM_SHIFT = 4; - \\const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT; - \\var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1); - \\ - \\export fn entry() usize { return @sizeOf(@TypeOf(block_aligned_stuff)); } - , &[_][]const u8{ - "tmp.zig:3:60: error: unable to perform binary not operation on type 'comptime_int'", - }); - { const case = ctx.obj("multiple files with private function error", .{}); case.backend = .stage1; @@ -6684,223 +341,6 @@ pub fn addCases(ctx: *TestContext) !void { }); } - ctx.objErrStage1("container init with non-type", - \\const zero: i32 = 0; - \\const a = zero{1}; - \\ - \\export fn entry() usize { return @sizeOf(@TypeOf(a)); } - , &[_][]const u8{ - "tmp.zig:2:11: error: expected type 'type', found 'i32'", - }); - - ctx.objErrStage1("assign to constant field", - \\const Foo = struct { - \\ field: i32, - \\}; - \\export fn derp() void { - \\ const f = Foo {.field = 1234,}; - \\ f.field = 0; - \\} - , &[_][]const u8{ - "tmp.zig:6:15: error: cannot assign to constant", - }); - - ctx.objErrStage1("return from defer expression", - \\pub fn testTrickyDefer() !void { - \\ defer canFail() catch {}; - \\ - \\ defer try canFail(); - \\ - \\ const a = maybeInt() orelse return; - \\} - \\ - \\fn canFail() anyerror!void { } - \\ - \\pub fn maybeInt() ?i32 { - \\ return 0; - \\} - \\ - \\export fn entry() usize { return @sizeOf(@TypeOf(testTrickyDefer)); } - , &[_][]const u8{ - "tmp.zig:4:11: error: 'try' not allowed inside defer expression", - }); - - ctx.objErrStage1("assign too big number to u16", - \\export fn foo() void { - \\ var vga_mem: u16 = 0xB8000; - \\ _ = vga_mem; - \\} - , &[_][]const u8{ - "tmp.zig:2:24: error: integer value 753664 cannot be coerced to type 'u16'", - }); - - ctx.objErrStage1("global variable alignment non power of 2", - \\const some_data: [100]u8 align(3) = undefined; - \\export fn entry() usize { return @sizeOf(@TypeOf(some_data)); } - , &[_][]const u8{ - "tmp.zig:1:32: error: alignment value 3 is not a power of 2", - }); - - ctx.objErrStage1("function alignment non power of 2", - \\extern fn foo() align(3) void; - \\export fn entry() void { return foo(); } - , &[_][]const u8{ - "tmp.zig:1:23: error: alignment value 3 is not a power of 2", - }); - - ctx.objErrStage1("compile log", - \\export fn foo() void { - \\ comptime bar(12, "hi",); - \\} - \\fn bar(a: i32, b: []const u8) void { - \\ @compileLog("begin",); - \\ @compileLog("a", a, "b", b); - \\ @compileLog("end",); - \\} - , &[_][]const u8{ - "tmp.zig:5:5: error: found compile log statement", - "tmp.zig:6:5: error: found compile log statement", - "tmp.zig:7:5: error: found compile log statement", - }); - - ctx.objErrStage1("casting bit offset pointer to regular pointer", - \\const BitField = packed struct { - \\ a: u3, - \\ b: u3, - \\ c: u2, - \\}; - \\ - \\fn foo(bit_field: *const BitField) u3 { - \\ return bar(&bit_field.b); - \\} - \\ - \\fn bar(x: *const u3) u3 { - \\ return x.*; - \\} - \\ - \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } - , &[_][]const u8{ - "tmp.zig:8:26: error: expected type '*const u3', found '*align(:3:1) const u3'", - }); - - ctx.objErrStage1("referring to a struct that is invalid", - \\const UsbDeviceRequest = struct { - \\ Type: u8, - \\}; - \\ - \\export fn foo() void { - \\ comptime assert(@sizeOf(UsbDeviceRequest) == 0x8); - \\} - \\ - \\fn assert(ok: bool) void { - \\ if (!ok) unreachable; - \\} - , &[_][]const u8{ - "tmp.zig:10:14: error: reached unreachable code", - }); - - ctx.objErrStage1("control flow uses comptime var at runtime", - \\export fn foo() void { - \\ comptime var i = 0; - \\ while (i < 5) : (i += 1) { - \\ bar(); - \\ } - \\} - \\ - \\fn bar() void { } - , &[_][]const u8{ - "tmp.zig:3:5: error: control flow attempts to use compile-time variable at runtime", - "tmp.zig:3:24: note: compile-time variable assigned here", - }); - - ctx.objErrStage1("ignored return value", - \\export fn foo() void { - \\ bar(); - \\} - \\fn bar() i32 { return 0; } - , &[_][]const u8{ - "tmp.zig:2:8: error: expression value is ignored", - }); - - ctx.objErrStage1("ignored assert-err-ok return value", - \\export fn foo() void { - \\ bar() catch unreachable; - \\} - \\fn bar() anyerror!i32 { return 0; } - , &[_][]const u8{ - "tmp.zig:2:11: error: expression value is ignored", - }); - - ctx.objErrStage1("ignored statement value", - \\export fn foo() void { - \\ 1; - \\} - , &[_][]const u8{ - "tmp.zig:2:5: error: expression value is ignored", - }); - - ctx.objErrStage1("ignored comptime statement value", - \\export fn foo() void { - \\ comptime {1;} - \\} - , &[_][]const u8{ - "tmp.zig:2:15: error: expression value is ignored", - }); - - ctx.objErrStage1("ignored comptime value", - \\export fn foo() void { - \\ comptime 1; - \\} - , &[_][]const u8{ - "tmp.zig:2:5: error: expression value is ignored", - }); - - ctx.objErrStage1("ignored deferred statement value", - \\export fn foo() void { - \\ defer {1;} - \\} - , &[_][]const u8{ - "tmp.zig:2:12: error: expression value is ignored", - }); - - ctx.objErrStage1("ignored deferred function call", - \\export fn foo() void { - \\ defer bar(); - \\} - \\fn bar() anyerror!i32 { return 0; } - , &[_][]const u8{ - "tmp.zig:2:14: error: error is ignored. consider using `try`, `catch`, or `if`", - }); - - ctx.objErrStage1("dereference an array", - \\var s_buffer: [10]u8 = undefined; - \\pub fn pass(in: []u8) []u8 { - \\ var out = &s_buffer; - \\ out.*.* = in[0]; - \\ return out.*[0..1]; - \\} - \\ - \\export fn entry() usize { return @sizeOf(@TypeOf(pass)); } - , &[_][]const u8{ - "tmp.zig:4:10: error: attempt to dereference non-pointer type '[10]u8'", - }); - - ctx.objErrStage1("pass const ptr to mutable ptr fn", - \\fn foo() bool { - \\ const a = @as([]const u8, "a",); - \\ const b = &a; - \\ return ptrEql(b, b); - \\} - \\fn ptrEql(a: *[]const u8, b: *[]const u8) bool { - \\ _ = a; _ = b; - \\ return true; - \\} - \\ - \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } - , &[_][]const u8{ - "tmp.zig:4:19: error: expected type '*[]const u8', found '*const []const u8'", - }); - { const case = ctx.obj("export collision", .{}); case.backend = .stage1; @@ -6922,236 +362,18 @@ pub fn addCases(ctx: *TestContext) !void { }); } - ctx.objErrStage1("implicit cast from array to mutable slice", - \\var global_array: [10]i32 = undefined; - \\fn foo(param: []i32) void {_ = param;} - \\export fn entry() void { - \\ foo(global_array); - \\} - , &[_][]const u8{ - "tmp.zig:4:9: error: expected type '[]i32', found '[10]i32'", + ctx.objErrStage1("non-printable invalid character", "\xff\xfe" ++ + "fn foo() bool {\r\n" ++ + " return true;\r\n" ++ + "}\r\n", &[_][]const u8{ + "tmp.zig:1:1: error: expected test, comptime, var decl, or container field, found 'invalid bytes'", + "tmp.zig:1:1: note: invalid byte: '\\xff'", }); - ctx.objErrStage1("ptrcast to non-pointer", - \\export fn entry(a: *i32) usize { - \\ return @ptrCast(usize, a); - \\} - , &[_][]const u8{ - "tmp.zig:2:21: error: expected pointer, found 'usize'", - }); - - ctx.objErrStage1("asm at compile time", - \\comptime { - \\ doSomeAsm(); - \\} - \\ - \\fn doSomeAsm() void { - \\ asm volatile ( - \\ \\.globl aoeu; - \\ \\.type aoeu, @function; - \\ \\.set aoeu, derp; - \\ ); - \\} - , &[_][]const u8{ - "tmp.zig:6:5: error: unable to evaluate constant expression", - }); - - ctx.objErrStage1("invalid member of builtin enum", - \\const builtin = @import("std").builtin; - \\export fn entry() void { - \\ const foo = builtin.Mode.x86; - \\ _ = foo; - \\} - , &[_][]const u8{ - "tmp.zig:3:29: error: container 'std.builtin.Mode' has no member called 'x86'", - }); - - ctx.objErrStage1("int to ptr of 0 bits", - \\export fn foo() void { - \\ var x: usize = 0x1000; - \\ var y: *void = @intToPtr(*void, x); - \\ _ = y; - \\} - , &[_][]const u8{ - "tmp.zig:3:30: error: type '*void' has 0 bits and cannot store information", - }); - - ctx.objErrStage1("@fieldParentPtr - non struct", - \\const Foo = i32; - \\export fn foo(a: *i32) *Foo { - \\ return @fieldParentPtr(Foo, "a", a); - \\} - , &[_][]const u8{ - "tmp.zig:3:28: error: expected struct type, found 'i32'", - }); - - ctx.objErrStage1("@fieldParentPtr - bad field name", - \\const Foo = extern struct { - \\ derp: i32, - \\}; - \\export fn foo(a: *i32) *Foo { - \\ return @fieldParentPtr(Foo, "a", a); - \\} - , &[_][]const u8{ - "tmp.zig:5:33: error: struct 'Foo' has no field 'a'", - }); - - ctx.objErrStage1("@fieldParentPtr - field pointer is not pointer", - \\const Foo = extern struct { - \\ a: i32, - \\}; - \\export fn foo(a: i32) *Foo { - \\ return @fieldParentPtr(Foo, "a", a); - \\} - , &[_][]const u8{ - "tmp.zig:5:38: error: expected pointer, found 'i32'", - }); - - ctx.objErrStage1("@fieldParentPtr - comptime field ptr not based on struct", - \\const Foo = struct { - \\ a: i32, - \\ b: i32, - \\}; - \\const foo = Foo { .a = 1, .b = 2, }; - \\ - \\comptime { - \\ const field_ptr = @intToPtr(*i32, 0x1234); - \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", field_ptr); - \\ _ = another_foo_ptr; - \\} - , &[_][]const u8{ - "tmp.zig:9:55: error: pointer value not based on parent struct", - }); - - ctx.objErrStage1("@fieldParentPtr - comptime wrong field index", - \\const Foo = struct { - \\ a: i32, - \\ b: i32, - \\}; - \\const foo = Foo { .a = 1, .b = 2, }; - \\ - \\comptime { - \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", &foo.a); - \\ _ = another_foo_ptr; - \\} - , &[_][]const u8{ - "tmp.zig:8:29: error: field 'b' has index 1 but pointer value is index 0 of struct 'Foo'", - }); - - ctx.objErrStage1("@offsetOf - non struct", - \\const Foo = i32; - \\export fn foo() usize { - \\ return @offsetOf(Foo, "a",); - \\} - , &[_][]const u8{ - "tmp.zig:3:22: error: expected struct type, found 'i32'", - }); - - ctx.objErrStage1("@offsetOf - bad field name", - \\const Foo = struct { - \\ derp: i32, - \\}; - \\export fn foo() usize { - \\ return @offsetOf(Foo, "a",); - \\} - , &[_][]const u8{ - "tmp.zig:5:27: error: struct 'Foo' has no field 'a'", - }); - - ctx.exeErrStage1("missing main fn in executable", - \\ - , &[_][]const u8{ - "error: root source file has no member called 'main'", - }); - - ctx.exeErrStage1("private main fn", - \\fn main() void {} - , &[_][]const u8{ - "error: 'main' is private", - "tmp.zig:1:1: note: declared here", - }); - - ctx.objErrStage1("setting a section on a local variable", - \\export fn entry() i32 { - \\ var foo: i32 linksection(".text2") = 1234; - \\ return foo; - \\} - , &[_][]const u8{ - "tmp.zig:2:30: error: cannot set section of local variable 'foo'", - }); - - ctx.objErrStage1("ambiguous decl reference", - \\fn foo() void {} - \\fn bar() void { - \\ const S = struct { - \\ fn baz() void { - \\ foo(); - \\ } - \\ fn foo() void {} - \\ }; - \\ S.baz(); - \\} - \\export fn entry() void { - \\ bar(); - \\} - , &[_][]const u8{ - "tmp.zig:5:13: error: ambiguous reference", - "tmp.zig:7:9: note: declared here", - "tmp.zig:1:1: note: also declared here", - }); - - ctx.objErrStage1("while expected bool, got optional", - \\export fn foo() void { - \\ while (bar()) {} - \\} - \\fn bar() ?i32 { return 1; } - , &[_][]const u8{ - "tmp.zig:2:15: error: expected type 'bool', found '?i32'", - }); - - ctx.objErrStage1("while expected bool, got error union", - \\export fn foo() void { - \\ while (bar()) {} - \\} - \\fn bar() anyerror!i32 { return 1; } - , &[_][]const u8{ - "tmp.zig:2:15: error: expected type 'bool', found 'anyerror!i32'", - }); - - ctx.objErrStage1("while expected optional, got bool", - \\export fn foo() void { - \\ while (bar()) |x| {_ = x;} - \\} - \\fn bar() bool { return true; } - , &[_][]const u8{ - "tmp.zig:2:15: error: expected optional type, found 'bool'", - }); - - ctx.objErrStage1("while expected optional, got error union", - \\export fn foo() void { - \\ while (bar()) |x| {_ = x;} - \\} - \\fn bar() anyerror!i32 { return 1; } - , &[_][]const u8{ - "tmp.zig:2:15: error: expected optional type, found 'anyerror!i32'", - }); - - ctx.objErrStage1("while expected error union, got bool", - \\export fn foo() void { - \\ while (bar()) |x| {_ = x;} else |err| {_ = err;} - \\} - \\fn bar() bool { return true; } - , &[_][]const u8{ - "tmp.zig:2:15: error: expected error union type, found 'bool'", - }); - - ctx.objErrStage1("while expected error union, got optional", - \\export fn foo() void { - \\ while (bar()) |x| {_ = x;} else |err| {_ = err;} - \\} - \\fn bar() ?i32 { return 1; } - , &[_][]const u8{ - "tmp.zig:2:15: error: expected error union type, found '?i32'", + ctx.objErrStage1("non-printable invalid character with escape alternative", "fn foo() bool {\n" ++ + "\treturn true;\n" ++ + "}\n", &[_][]const u8{ + "tmp.zig:2:1: error: invalid character: '\\t'", }); // TODO test this in stage2, but we won't even try in stage1 @@ -7182,1620 +404,6 @@ pub fn addCases(ctx: *TestContext) !void { // "tmp.zig:4:1: error: unable to inline function", //}); - ctx.objErrStage1("signed integer division", - \\export fn foo(a: i32, b: i32) i32 { - \\ return a / b; - \\} - , &[_][]const u8{ - "tmp.zig:2:14: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact", - }); - - ctx.objErrStage1("signed integer remainder division", - \\export fn foo(a: i32, b: i32) i32 { - \\ return a % b; - \\} - , &[_][]const u8{ - "tmp.zig:2:14: error: remainder division with 'i32' and 'i32': signed integers and floats must use @rem or @mod", - }); - - ctx.objErrStage1("compile-time division by zero", - \\comptime { - \\ const a: i32 = 1; - \\ const b: i32 = 0; - \\ const c = a / b; - \\ _ = c; - \\} - , &[_][]const u8{ - "tmp.zig:4:17: error: division by zero", - }); - - ctx.objErrStage1("compile-time remainder division by zero", - \\comptime { - \\ const a: i32 = 1; - \\ const b: i32 = 0; - \\ const c = a % b; - \\ _ = c; - \\} - , &[_][]const u8{ - "tmp.zig:4:17: error: division by zero", - }); - - ctx.objErrStage1("@setRuntimeSafety twice for same scope", - \\export fn foo() void { - \\ @setRuntimeSafety(false); - \\ @setRuntimeSafety(false); - \\} - , &[_][]const u8{ - "tmp.zig:3:5: error: runtime safety set twice for same scope", - "tmp.zig:2:5: note: first set here", - }); - - ctx.objErrStage1("@setFloatMode twice for same scope", - \\export fn foo() void { - \\ @setFloatMode(@import("std").builtin.FloatMode.Optimized); - \\ @setFloatMode(@import("std").builtin.FloatMode.Optimized); - \\} - , &[_][]const u8{ - "tmp.zig:3:5: error: float mode set twice for same scope", - "tmp.zig:2:5: note: first set here", - }); - - ctx.objErrStage1("array access of type", - \\export fn foo() void { - \\ var b: u8[40] = undefined; - \\ _ = b; - \\} - , &[_][]const u8{ - "tmp.zig:2:14: error: array access of non-array type 'type'", - }); - - ctx.objErrStage1("cannot break out of defer expression", - \\export fn foo() void { - \\ while (true) { - \\ defer { - \\ break; - \\ } - \\ } - \\} - , &[_][]const u8{ - "tmp.zig:4:13: error: cannot break out of defer expression", - }); - - ctx.objErrStage1("cannot continue out of defer expression", - \\export fn foo() void { - \\ while (true) { - \\ defer { - \\ continue; - \\ } - \\ } - \\} - , &[_][]const u8{ - "tmp.zig:4:13: error: cannot continue out of defer expression", - }); - - ctx.objErrStage1("calling a generic function only known at runtime", - \\var foos = [_]fn(anytype) void { foo1, foo2 }; - \\ - \\fn foo1(arg: anytype) void {_ = arg;} - \\fn foo2(arg: anytype) void {_ = arg;} - \\ - \\pub fn main() !void { - \\ foos[0](true); - \\} - , &[_][]const u8{ - "tmp.zig:7:9: error: calling a generic function requires compile-time known function value", - }); - - ctx.objErrStage1("@compileError shows traceback of references that caused it", - \\const foo = @compileError("aoeu",); - \\ - \\const bar = baz + foo; - \\const baz = 1; - \\ - \\export fn entry() i32 { - \\ return bar; - \\} - , &[_][]const u8{ - "tmp.zig:1:13: error: aoeu", - }); - - ctx.objErrStage1("float literal too large error", - \\comptime { - \\ const a = 0x1.0p18495; - \\ _ = a; - \\} - , &[_][]const u8{ - "tmp.zig:2:15: error: float literal out of range of any type", - }); - - ctx.objErrStage1("float literal too small error (denormal)", - \\comptime { - \\ const a = 0x1.0p-19000; - \\ _ = a; - \\} - , &[_][]const u8{ - "tmp.zig:2:15: error: float literal out of range of any type", - }); - - ctx.objErrStage1("explicit cast float literal to integer when there is a fraction component", - \\export fn entry() i32 { - \\ return @as(i32, 12.34); - \\} - , &[_][]const u8{ - "tmp.zig:2:21: error: fractional component prevents float value 12.340000 from being casted to type 'i32'", - }); - - ctx.objErrStage1("non pointer given to @ptrToInt", - \\export fn entry(x: i32) usize { - \\ return @ptrToInt(x); - \\} - , &[_][]const u8{ - "tmp.zig:2:22: error: expected pointer, found 'i32'", - }); - - ctx.objErrStage1("@shlExact shifts out 1 bits", - \\comptime { - \\ const x = @shlExact(@as(u8, 0b01010101), 2); - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:2:15: error: operation caused overflow", - }); - - ctx.objErrStage1("@shrExact shifts out 1 bits", - \\comptime { - \\ const x = @shrExact(@as(u8, 0b10101010), 2); - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:2:15: error: exact shift shifted out 1 bits", - }); - - ctx.objErrStage1("shifting without int type or comptime known", - \\export fn entry(x: u8) u8 { - \\ return 0x11 << x; - \\} - , &[_][]const u8{ - "tmp.zig:2:17: error: LHS of shift must be a fixed-width integer type, or RHS must be compile-time known", - }); - - ctx.objErrStage1("shifting RHS is log2 of LHS int bit width", - \\export fn entry(x: u8, y: u8) u8 { - \\ return x << y; - \\} - , &[_][]const u8{ - "tmp.zig:2:17: error: expected type 'u3', found 'u8'", - }); - - ctx.objErrStage1("locally shadowing a primitive type", - \\export fn foo() void { - \\ const u8 = u16; - \\ const a: u8 = 300; - \\ _ = a; - \\} - , &[_][]const u8{ - "tmp.zig:2:11: error: name shadows primitive 'u8'", - "tmp.zig:2:11: note: consider using @\"u8\" to disambiguate", - }); - - ctx.objErrStage1("primitives take precedence over declarations", - \\const @"u8" = u16; - \\export fn entry() void { - \\ const a: u8 = 300; - \\ _ = a; - \\} - , &[_][]const u8{ - "tmp.zig:3:19: error: integer value 300 cannot be coerced to type 'u8'", - }); - - ctx.objErrStage1("declaration with same name as primitive must use special syntax", - \\const u8 = u16; - \\export fn entry() void { - \\ const a: u8 = 300; - \\ _ = a; - \\} - , &[_][]const u8{ - "tmp.zig:1:7: error: name shadows primitive 'u8'", - "tmp.zig:1:7: note: consider using @\"u8\" to disambiguate", - }); - - ctx.objErrStage1("implicitly increasing pointer alignment", - \\const Foo = packed struct { - \\ a: u8, - \\ b: u32, - \\}; - \\ - \\export fn entry() void { - \\ var foo = Foo { .a = 1, .b = 10 }; - \\ bar(&foo.b); - \\} - \\ - \\fn bar(x: *u32) void { - \\ x.* += 1; - \\} - , &[_][]const u8{ - "tmp.zig:8:13: error: expected type '*u32', found '*align(1) u32'", - }); - - ctx.objErrStage1("implicitly increasing slice alignment", - \\const Foo = packed struct { - \\ a: u8, - \\ b: u32, - \\}; - \\ - \\export fn entry() void { - \\ var foo = Foo { .a = 1, .b = 10 }; - \\ foo.b += 1; - \\ bar(@as(*[1]u32, &foo.b)[0..]); - \\} - \\ - \\fn bar(x: []u32) void { - \\ x[0] += 1; - \\} - , &[_][]const u8{ - "tmp.zig:9:26: error: cast increases pointer alignment", - "tmp.zig:9:26: note: '*align(1) u32' has alignment 1", - "tmp.zig:9:26: note: '*[1]u32' has alignment 4", - }); - - ctx.objErrStage1("increase pointer alignment in @ptrCast", - \\export fn entry() u32 { - \\ var bytes: [4]u8 = [_]u8{0x01, 0x02, 0x03, 0x04}; - \\ const ptr = @ptrCast(*u32, &bytes[0]); - \\ return ptr.*; - \\} - , &[_][]const u8{ - "tmp.zig:3:17: error: cast increases pointer alignment", - "tmp.zig:3:38: note: '*u8' has alignment 1", - "tmp.zig:3:26: note: '*u32' has alignment 4", - }); - - ctx.objErrStage1("@alignCast expects pointer or slice", - \\export fn entry() void { - \\ @alignCast(4, @as(u32, 3)); - \\} - , &[_][]const u8{ - "tmp.zig:2:19: error: expected pointer or slice, found 'u32'", - }); - - ctx.objErrStage1("passing an under-aligned function pointer", - \\export fn entry() void { - \\ testImplicitlyDecreaseFnAlign(alignedSmall, 1234); - \\} - \\fn testImplicitlyDecreaseFnAlign(ptr: fn () align(8) i32, answer: i32) void { - \\ if (ptr() != answer) unreachable; - \\} - \\fn alignedSmall() align(4) i32 { return 1234; } - , &[_][]const u8{ - "tmp.zig:2:35: error: expected type 'fn() align(8) i32', found 'fn() align(4) i32'", - }); - - ctx.objErrStage1("passing a not-aligned-enough pointer to cmpxchg", - \\const AtomicOrder = @import("std").builtin.AtomicOrder; - \\export fn entry() bool { - \\ var x: i32 align(1) = 1234; - \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) {} - \\ return x == 5678; - \\} - , &[_][]const u8{ - "tmp.zig:4:32: error: expected type '*i32', found '*align(1) i32'", - }); - - ctx.objErrStage1("wrong size to an array literal", - \\comptime { - \\ const array = [2]u8{1, 2, 3}; - \\ _ = array; - \\} - , &[_][]const u8{ - "tmp.zig:2:31: error: index 2 outside array of size 2", - }); - - ctx.objErrStage1("wrong pointer coerced to pointer to opaque {}", - \\const Derp = opaque {}; - \\extern fn bar(d: *Derp) void; - \\export fn foo() void { - \\ var x = @as(u8, 1); - \\ bar(@ptrCast(*anyopaque, &x)); - \\} - , &[_][]const u8{ - "tmp.zig:5:9: error: expected type '*Derp', found '*anyopaque'", - }); - - ctx.objErrStage1("non-const variables of things that require const variables", - \\export fn entry1() void { - \\ var m2 = &2; - \\ _ = m2; - \\} - \\export fn entry2() void { - \\ var a = undefined; - \\ _ = a; - \\} - \\export fn entry3() void { - \\ var b = 1; - \\ _ = b; - \\} - \\export fn entry4() void { - \\ var c = 1.0; - \\ _ = c; - \\} - \\export fn entry5() void { - \\ var d = null; - \\ _ = d; - \\} - \\export fn entry6(opaque_: *Opaque) void { - \\ var e = opaque_.*; - \\ _ = e; - \\} - \\export fn entry7() void { - \\ var f = i32; - \\ _ = f; - \\} - \\export fn entry8() void { - \\ var h = (Foo {}).bar; - \\ _ = h; - \\} - \\const Opaque = opaque {}; - \\const Foo = struct { - \\ fn bar(self: *const Foo) void {_ = self;} - \\}; - , &[_][]const u8{ - "tmp.zig:2:4: error: variable of type '*const comptime_int' must be const or comptime", - "tmp.zig:6:4: error: variable of type '@Type(.Undefined)' must be const or comptime", - "tmp.zig:10:4: error: variable of type 'comptime_int' must be const or comptime", - "tmp.zig:10:4: note: to modify this variable at runtime, it must be given an explicit fixed-size number type", - "tmp.zig:14:4: error: variable of type 'comptime_float' must be const or comptime", - "tmp.zig:14:4: note: to modify this variable at runtime, it must be given an explicit fixed-size number type", - "tmp.zig:18:4: error: variable of type '@Type(.Null)' must be const or comptime", - "tmp.zig:22:4: error: variable of type 'Opaque' not allowed", - "tmp.zig:26:4: error: variable of type 'type' must be const or comptime", - "tmp.zig:30:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime", - }); - - ctx.objErrStage1("variable with type 'noreturn'", - \\export fn entry9() void { - \\ var z: noreturn = return; - \\} - , &[_][]const u8{ - "tmp.zig:2:5: error: unreachable code", - "tmp.zig:2:23: note: control flow is diverted here", - }); - - ctx.objErrStage1("wrong types given to atomic order args in cmpxchg", - \\export fn entry() void { - \\ var x: i32 = 1234; - \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, @as(u32, 1234), @as(u32, 1234))) {} - \\} - , &[_][]const u8{ - "tmp.zig:3:47: error: expected type 'std.builtin.AtomicOrder', found 'u32'", - }); - - ctx.objErrStage1("wrong types given to @export", - \\fn entry() callconv(.C) void { } - \\comptime { - \\ @export(entry, .{.name = "entry", .linkage = @as(u32, 1234) }); - \\} - , &[_][]const u8{ - "tmp.zig:3:59: error: expected type 'std.builtin.GlobalLinkage', found 'comptime_int'", - }); - - ctx.objErrStage1("struct with invalid field", - \\const std = @import("std",); - \\const Allocator = std.mem.Allocator; - \\const ArrayList = std.ArrayList; - \\ - \\const HeaderWeight = enum { - \\ H1, H2, H3, H4, H5, H6, - \\}; - \\ - \\const MdText = ArrayList(u8); - \\ - \\const MdNode = union(enum) { - \\ Header: struct { - \\ text: MdText, - \\ weight: HeaderValue, - \\ }, - \\}; - \\ - \\export fn entry() void { - \\ const a = MdNode.Header { - \\ .text = MdText.init(std.testing.allocator), - \\ .weight = HeaderWeight.H1, - \\ }; - \\ _ = a; - \\} - , &[_][]const u8{ - "tmp.zig:14:17: error: use of undeclared identifier 'HeaderValue'", - }); - - ctx.objErrStage1("@setAlignStack outside function", - \\comptime { - \\ @setAlignStack(16); - \\} - , &[_][]const u8{ - "tmp.zig:2:5: error: @setAlignStack outside function", - }); - - ctx.objErrStage1("@setAlignStack in naked function", - \\export fn entry() callconv(.Naked) void { - \\ @setAlignStack(16); - \\} - , &[_][]const u8{ - "tmp.zig:2:5: error: @setAlignStack in naked function", - }); - - ctx.objErrStage1("@setAlignStack in inline function", - \\export fn entry() void { - \\ foo(); - \\} - \\fn foo() callconv(.Inline) void { - \\ @setAlignStack(16); - \\} - , &[_][]const u8{ - "tmp.zig:5:5: error: @setAlignStack in inline function", - }); - - ctx.objErrStage1("@setAlignStack set twice", - \\export fn entry() void { - \\ @setAlignStack(16); - \\ @setAlignStack(16); - \\} - , &[_][]const u8{ - "tmp.zig:3:5: error: alignstack set twice", - "tmp.zig:2:5: note: first set here", - }); - - ctx.objErrStage1("@setAlignStack too big", - \\export fn entry() void { - \\ @setAlignStack(511 + 1); - \\} - , &[_][]const u8{ - "tmp.zig:2:5: error: attempt to @setAlignStack(512); maximum is 256", - }); - - ctx.objErrStage1("storing runtime value in compile time variable then using it", - \\const Mode = @import("std").builtin.Mode; - \\ - \\fn Free(comptime filename: []const u8) TestCase { - \\ return TestCase { - \\ .filename = filename, - \\ .problem_type = ProblemType.Free, - \\ }; - \\} - \\ - \\fn LibC(comptime filename: []const u8) TestCase { - \\ return TestCase { - \\ .filename = filename, - \\ .problem_type = ProblemType.LinkLibC, - \\ }; - \\} - \\ - \\const TestCase = struct { - \\ filename: []const u8, - \\ problem_type: ProblemType, - \\}; - \\ - \\const ProblemType = enum { - \\ Free, - \\ LinkLibC, - \\}; - \\ - \\export fn entry() void { - \\ const tests = [_]TestCase { - \\ Free("001"), - \\ Free("002"), - \\ LibC("078"), - \\ Free("116"), - \\ Free("117"), - \\ }; - \\ - \\ for ([_]Mode { Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast }) |mode| { - \\ _ = mode; - \\ inline for (tests) |test_case| { - \\ const foo = test_case.filename ++ ".zig"; - \\ _ = foo; - \\ } - \\ } - \\} - , &[_][]const u8{ - "tmp.zig:38:29: error: cannot store runtime value in compile time variable", - }); - - ctx.objErrStage1("invalid legacy unicode escape", - \\export fn entry() void { - \\ const a = '\U1234'; - \\} - , &[_][]const u8{ - "tmp.zig:2:15: error: expected expression, found 'invalid bytes'", - "tmp.zig:2:18: note: invalid byte: '1'", - }); - - ctx.objErrStage1("invalid empty unicode escape", - \\export fn entry() void { - \\ const a = '\u{}'; - \\} - , &[_][]const u8{ - "tmp.zig:2:19: error: empty unicode escape sequence", - }); - - ctx.objErrStage1("non-printable invalid character", "\xff\xfe" ++ - "fn foo() bool {\r\n" ++ - " return true;\r\n" ++ - "}\r\n", &[_][]const u8{ - "tmp.zig:1:1: error: expected test, comptime, var decl, or container field, found 'invalid bytes'", - "tmp.zig:1:1: note: invalid byte: '\\xff'", - }); - - ctx.objErrStage1("non-printable invalid character with escape alternative", "fn foo() bool {\n" ++ - "\treturn true;\n" ++ - "}\n", &[_][]const u8{ - "tmp.zig:2:1: error: invalid character: '\\t'", - }); - - ctx.objErrStage1("calling var args extern function, passing array instead of pointer", - \\export fn entry() void { - \\ foo("hello".*,); - \\} - \\pub extern fn foo(format: *const u8, ...) void; - , &[_][]const u8{ - "tmp.zig:2:16: error: expected type '*const u8', found '[5:0]u8'", - }); - - ctx.objErrStage1("constant inside comptime function has compile error", - \\const ContextAllocator = MemoryPool(usize); - \\ - \\pub fn MemoryPool(comptime T: type) type { - \\ const free_list_t = @compileError("aoeu",); - \\ - \\ return struct { - \\ free_list: free_list_t, - \\ }; - \\} - \\ - \\export fn entry() void { - \\ var allocator: ContextAllocator = undefined; - \\} - , &[_][]const u8{ - "tmp.zig:4:5: error: unreachable code", - "tmp.zig:4:25: note: control flow is diverted here", - "tmp.zig:12:9: error: unused local variable", - }); - - ctx.objErrStage1("specify enum tag type that is too small", - \\const Small = enum (u2) { - \\ One, - \\ Two, - \\ Three, - \\ Four, - \\ Five, - \\}; - \\ - \\export fn entry() void { - \\ var x = Small.One; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:6:5: error: enumeration value 4 too large for type 'u2'", - }); - - ctx.objErrStage1("specify non-integer enum tag type", - \\const Small = enum (f32) { - \\ One, - \\ Two, - \\ Three, - \\}; - \\ - \\export fn entry() void { - \\ var x = Small.One; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:1:21: error: expected integer, found 'f32'", - }); - - ctx.objErrStage1("implicitly casting enum to tag type", - \\const Small = enum(u2) { - \\ One, - \\ Two, - \\ Three, - \\ Four, - \\}; - \\ - \\export fn entry() void { - \\ var x: u2 = Small.Two; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:9:22: error: expected type 'u2', found 'Small'", - }); - - ctx.objErrStage1("explicitly casting non tag type to enum", - \\const Small = enum(u2) { - \\ One, - \\ Two, - \\ Three, - \\ Four, - \\}; - \\ - \\export fn entry() void { - \\ var y = @as(f32, 3); - \\ var x = @intToEnum(Small, y); - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:10:31: error: expected integer type, found 'f32'", - }); - - ctx.objErrStage1("union fields with value assignments", - \\const MultipleChoice = union { - \\ A: i32 = 20, - \\}; - \\export fn entry() void { - \\ var x: MultipleChoice = undefined; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:1:24: error: explicitly valued tagged union missing integer tag type", - "tmp.zig:2:14: note: tag value specified here", - }); - - ctx.objErrStage1("enum with 0 fields", - \\const Foo = enum {}; - , &[_][]const u8{ - "tmp.zig:1:13: error: enum declarations must have at least one tag", - }); - - ctx.objErrStage1("union with 0 fields", - \\const Foo = union {}; - , &[_][]const u8{ - "tmp.zig:1:13: error: union declarations must have at least one tag", - }); - - ctx.objErrStage1("enum value already taken", - \\const MultipleChoice = enum(u32) { - \\ A = 20, - \\ B = 40, - \\ C = 60, - \\ D = 1000, - \\ E = 60, - \\}; - \\export fn entry() void { - \\ var x = MultipleChoice.C; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:6:5: error: enum tag value 60 already taken", - "tmp.zig:4:5: note: other occurrence here", - }); - - ctx.objErrStage1("union with specified enum omits field", - \\const Letter = enum { - \\ A, - \\ B, - \\ C, - \\}; - \\const Payload = union(Letter) { - \\ A: i32, - \\ B: f64, - \\}; - \\export fn entry() usize { - \\ return @sizeOf(Payload); - \\} - , &[_][]const u8{ - "tmp.zig:6:17: error: enum field missing: 'C'", - "tmp.zig:4:5: note: declared here", - }); - - ctx.objErrStage1("non-integer tag type to automatic union enum", - \\const Foo = union(enum(f32)) { - \\ A: i32, - \\}; - \\export fn entry() void { - \\ const x = @typeInfo(Foo).Union.tag_type.?; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:1:24: error: expected integer tag type, found 'f32'", - }); - - ctx.objErrStage1("non-enum tag type passed to union", - \\const Foo = union(u32) { - \\ A: i32, - \\}; - \\export fn entry() void { - \\ const x = @typeInfo(Foo).Union.tag_type.?; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:1:19: error: expected enum tag type, found 'u32'", - }); - - ctx.objErrStage1("union auto-enum value already taken", - \\const MultipleChoice = union(enum(u32)) { - \\ A = 20, - \\ B = 40, - \\ C = 60, - \\ D = 1000, - \\ E = 60, - \\}; - \\export fn entry() void { - \\ var x = MultipleChoice { .C = {} }; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:6:9: error: enum tag value 60 already taken", - "tmp.zig:4:9: note: other occurrence here", - }); - - ctx.objErrStage1("union enum field does not match enum", - \\const Letter = enum { - \\ A, - \\ B, - \\ C, - \\}; - \\const Payload = union(Letter) { - \\ A: i32, - \\ B: f64, - \\ C: bool, - \\ D: bool, - \\}; - \\export fn entry() void { - \\ var a = Payload {.A = 1234}; - \\ _ = a; - \\} - , &[_][]const u8{ - "tmp.zig:10:5: error: enum field not found: 'D'", - "tmp.zig:1:16: note: enum declared here", - }); - - ctx.objErrStage1("field type supplied in an enum", - \\const Letter = enum { - \\ A: void, - \\ B, - \\ C, - \\}; - , &[_][]const u8{ - "tmp.zig:2:8: error: enum fields do not have types", - "tmp.zig:1:16: note: consider 'union(enum)' here to make it a tagged union", - }); - - ctx.objErrStage1("struct field missing type", - \\const Letter = struct { - \\ A, - \\}; - \\export fn entry() void { - \\ var a = Letter { .A = {} }; - \\ _ = a; - \\} - , &[_][]const u8{ - "tmp.zig:2:5: error: struct field missing type", - }); - - ctx.objErrStage1("extern union field missing type", - \\const Letter = extern union { - \\ A, - \\}; - \\export fn entry() void { - \\ var a = Letter { .A = {} }; - \\ _ = a; - \\} - , &[_][]const u8{ - "tmp.zig:2:5: error: union field missing type", - }); - - ctx.objErrStage1("extern union given enum tag type", - \\const Letter = enum { - \\ A, - \\ B, - \\ C, - \\}; - \\const Payload = extern union(Letter) { - \\ A: i32, - \\ B: f64, - \\ C: bool, - \\}; - \\export fn entry() void { - \\ var a = Payload { .A = 1234 }; - \\ _ = a; - \\} - , &[_][]const u8{ - "tmp.zig:6:30: error: extern union does not support enum tag type", - }); - - ctx.objErrStage1("packed union given enum tag type", - \\const Letter = enum { - \\ A, - \\ B, - \\ C, - \\}; - \\const Payload = packed union(Letter) { - \\ A: i32, - \\ B: f64, - \\ C: bool, - \\}; - \\export fn entry() void { - \\ var a = Payload { .A = 1234 }; - \\ _ = a; - \\} - , &[_][]const u8{ - "tmp.zig:6:30: error: packed union does not support enum tag type", - }); - - ctx.objErrStage1("packed union with automatic layout field", - \\const Foo = struct { - \\ a: u32, - \\ b: f32, - \\}; - \\const Payload = packed union { - \\ A: Foo, - \\ B: bool, - \\}; - \\export fn entry() void { - \\ var a = Payload { .B = true }; - \\ _ = a; - \\} - , &[_][]const u8{ - "tmp.zig:6:5: error: non-packed, non-extern struct 'Foo' not allowed in packed union; no guaranteed in-memory representation", - }); - - ctx.objErrStage1("switch on union with no attached enum", - \\const Payload = union { - \\ A: i32, - \\ B: f64, - \\ C: bool, - \\}; - \\export fn entry() void { - \\ const a = Payload { .A = 1234 }; - \\ foo(a); - \\} - \\fn foo(a: *const Payload) void { - \\ switch (a.*) { - \\ Payload.A => {}, - \\ else => unreachable, - \\ } - \\} - , &[_][]const u8{ - "tmp.zig:11:14: error: switch on union which has no attached enum", - "tmp.zig:1:17: note: consider 'union(enum)' here", - }); - - ctx.objErrStage1("enum in field count range but not matching tag", - \\const Foo = enum(u32) { - \\ A = 10, - \\ B = 11, - \\}; - \\export fn entry() void { - \\ var x = @intToEnum(Foo, 0); - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:6:13: error: enum 'Foo' has no tag matching integer value 0", - "tmp.zig:1:13: note: 'Foo' declared here", - }); - - ctx.objErrStage1("comptime cast enum to union but field has payload", - \\const Letter = enum { A, B, C }; - \\const Value = union(Letter) { - \\ A: i32, - \\ B, - \\ C, - \\}; - \\export fn entry() void { - \\ var x: Value = Letter.A; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:8:26: error: cast to union 'Value' must initialize 'i32' field 'A'", - "tmp.zig:3:5: note: field 'A' declared here", - }); - - ctx.objErrStage1("runtime cast to union which has non-void fields", - \\const Letter = enum { A, B, C }; - \\const Value = union(Letter) { - \\ A: i32, - \\ B, - \\ C, - \\}; - \\export fn entry() void { - \\ foo(Letter.A); - \\} - \\fn foo(l: Letter) void { - \\ var x: Value = l; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:11:20: error: runtime cast to union 'Value' which has non-void fields", - "tmp.zig:3:5: note: field 'A' has type 'i32'", - }); - - ctx.objErrStage1("taking byte offset of void field in struct", - \\const Empty = struct { - \\ val: void, - \\}; - \\export fn foo() void { - \\ const fieldOffset = @offsetOf(Empty, "val",); - \\ _ = fieldOffset; - \\} - , &[_][]const u8{ - "tmp.zig:5:42: error: zero-bit field 'val' in struct 'Empty' has no offset", - }); - - ctx.objErrStage1("taking bit offset of void field in struct", - \\const Empty = struct { - \\ val: void, - \\}; - \\export fn foo() void { - \\ const fieldOffset = @bitOffsetOf(Empty, "val",); - \\ _ = fieldOffset; - \\} - , &[_][]const u8{ - "tmp.zig:5:45: error: zero-bit field 'val' in struct 'Empty' has no offset", - }); - - ctx.objErrStage1("invalid union field access in comptime", - \\const Foo = union { - \\ Bar: u8, - \\ Baz: void, - \\}; - \\comptime { - \\ var foo = Foo {.Baz = {}}; - \\ const bar_val = foo.Bar; - \\ _ = bar_val; - \\} - , &[_][]const u8{ - "tmp.zig:7:24: error: accessing union field 'Bar' while field 'Baz' is set", - }); - - ctx.objErrStage1("unsupported modifier at start of asm output constraint", - \\export fn foo() void { - \\ var bar: u32 = 3; - \\ asm volatile ("" : [baz]"+r"(bar) : : ""); - \\} - , &[_][]const u8{ - "tmp.zig:3:5: error: invalid modifier starting output constraint for 'baz': '+', only '=' is supported. Compiler TODO: see https://github.com/ziglang/zig/issues/215", - }); - - ctx.objErrStage1("comptime_int in asm input", - \\export fn foo() void { - \\ asm volatile ("" : : [bar]"r"(3) : ""); - \\} - , &[_][]const u8{ - "tmp.zig:2:35: error: expected sized integer or sized float, found comptime_int", - }); - - ctx.objErrStage1("comptime_float in asm input", - \\export fn foo() void { - \\ asm volatile ("" : : [bar]"r"(3.17) : ""); - \\} - , &[_][]const u8{ - "tmp.zig:2:35: error: expected sized integer or sized float, found comptime_float", - }); - - ctx.objErrStage1("runtime assignment to comptime struct type", - \\const Foo = struct { - \\ Bar: u8, - \\ Baz: type, - \\}; - \\export fn f() void { - \\ var x: u8 = 0; - \\ const foo = Foo { .Bar = x, .Baz = u8 }; - \\ _ = foo; - \\} - , &[_][]const u8{ - "tmp.zig:7:23: error: unable to evaluate constant expression", - }); - - ctx.objErrStage1("runtime assignment to comptime union type", - \\const Foo = union { - \\ Bar: u8, - \\ Baz: type, - \\}; - \\export fn f() void { - \\ var x: u8 = 0; - \\ const foo = Foo { .Bar = x }; - \\ _ = foo; - \\} - , &[_][]const u8{ - "tmp.zig:7:23: error: unable to evaluate constant expression", - }); - - ctx.testErrStage1("@shuffle with selected index past first vector length", - \\export fn entry() void { - \\ const v: @import("std").meta.Vector(4, u32) = [4]u32{ 10, 11, 12, 13 }; - \\ const x: @import("std").meta.Vector(4, u32) = [4]u32{ 14, 15, 16, 17 }; - \\ var z = @shuffle(u32, v, x, [8]i32{ 0, 1, 2, 3, 7, 6, 5, 4 }); - \\ _ = z; - \\} - , &[_][]const u8{ - "tmp.zig:4:39: error: mask index '4' has out-of-bounds selection", - "tmp.zig:4:27: note: selected index '7' out of bounds of @Vector(4, u32)", - "tmp.zig:4:30: note: selections from the second vector are specified with negative numbers", - }); - - ctx.testErrStage1("nested vectors", - \\export fn entry() void { - \\ const V1 = @import("std").meta.Vector(4, u8); - \\ const V2 = @Type(.{ .Vector = .{ .len = 4, .child = V1 } }); - \\ var v: V2 = undefined; - \\ _ = v; - \\} - , &[_][]const u8{ - "tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; '@Vector(4, u8)' is invalid", - }); - - ctx.testErrStage1("bad @splat type", - \\export fn entry() void { - \\ const c = 4; - \\ var v = @splat(4, c); - \\ _ = v; - \\} - , &[_][]const u8{ - "tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; 'comptime_int' is invalid", - }); - - ctx.objErrStage1("compileLog of tagged enum doesn't crash the compiler", - \\const Bar = union(enum(u32)) { - \\ X: i32 = 1 - \\}; - \\ - \\fn testCompileLog(x: Bar) void { - \\ @compileLog(x); - \\} - \\ - \\pub fn main () void { - \\ comptime testCompileLog(Bar{.X = 123}); - \\} - , &[_][]const u8{ - "tmp.zig:6:5: error: found compile log statement", - }); - - ctx.objErrStage1("attempted implicit cast from *const T to *[1]T", - \\export fn entry(byte: u8) void { - \\ const w: i32 = 1234; - \\ var x: *const i32 = &w; - \\ var y: *[1]i32 = x; - \\ y[0] += 1; - \\ _ = byte; - \\} - , &[_][]const u8{ - "tmp.zig:4:22: error: expected type '*[1]i32', found '*const i32'", - "tmp.zig:4:22: note: cast discards const qualifier", - }); - - ctx.objErrStage1("attempted implicit cast from *const T to []T", - \\export fn entry() void { - \\ const u: u32 = 42; - \\ const x: []u32 = &u; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:3:23: error: expected type '[]u32', found '*const u32'", - }); - - ctx.objErrStage1("for loop body expression ignored", - \\fn returns() usize { - \\ return 2; - \\} - \\export fn f1() void { - \\ for ("hello") |_| returns(); - \\} - \\export fn f2() void { - \\ var x: anyerror!i32 = error.Bad; - \\ for ("hello") |_| returns() else unreachable; - \\ _ = x; - \\} - , &[_][]const u8{ - "tmp.zig:5:30: error: expression value is ignored", - "tmp.zig:9:30: error: expression value is ignored", - }); - - ctx.objErrStage1("aligned variable of zero-bit type", - \\export fn f() void { - \\ var s: struct {} align(4) = undefined; - \\ _ = s; - \\} - , &[_][]const u8{ - "tmp.zig:2:5: error: variable 's' of zero-bit type 'struct:2:12' has no in-memory representation, it cannot be aligned", - }); - - ctx.objErrStage1("function returning opaque type", - \\const FooType = opaque {}; - \\export fn bar() !FooType { - \\ return error.InvalidValue; - \\} - \\export fn bav() !@TypeOf(null) { - \\ return error.InvalidValue; - \\} - \\export fn baz() !@TypeOf(undefined) { - \\ return error.InvalidValue; - \\} - , &[_][]const u8{ - "tmp.zig:2:18: error: Opaque return type 'FooType' not allowed", - "tmp.zig:1:1: note: type declared here", - "tmp.zig:5:18: error: Null return type '@Type(.Null)' not allowed", - "tmp.zig:8:18: error: Undefined return type '@Type(.Undefined)' not allowed", - }); - - ctx.objErrStage1("generic function returning opaque type", - \\const FooType = opaque {}; - \\fn generic(comptime T: type) !T { - \\ return undefined; - \\} - \\export fn bar() void { - \\ _ = generic(FooType); - \\} - \\export fn bav() void { - \\ _ = generic(@TypeOf(null)); - \\} - \\export fn baz() void { - \\ _ = generic(@TypeOf(undefined)); - \\} - , &[_][]const u8{ - "tmp.zig:6:16: error: call to generic function with Opaque return type 'FooType' not allowed", - "tmp.zig:2:1: note: function declared here", - "tmp.zig:1:1: note: type declared here", - "tmp.zig:9:16: error: call to generic function with Null return type '@Type(.Null)' not allowed", - "tmp.zig:2:1: note: function declared here", - "tmp.zig:12:16: error: call to generic function with Undefined return type '@Type(.Undefined)' not allowed", - "tmp.zig:2:1: note: function declared here", - }); - - ctx.objErrStage1("function parameter is opaque", - \\const FooType = opaque {}; - \\export fn entry1() void { - \\ const someFuncPtr: fn (FooType) void = undefined; - \\ _ = someFuncPtr; - \\} - \\ - \\export fn entry2() void { - \\ const someFuncPtr: fn (@TypeOf(null)) void = undefined; - \\ _ = someFuncPtr; - \\} - \\ - \\fn foo(p: FooType) void {_ = p;} - \\export fn entry3() void { - \\ _ = foo; - \\} - \\ - \\fn bar(p: @TypeOf(null)) void {_ = p;} - \\export fn entry4() void { - \\ _ = bar; - \\} - , &[_][]const u8{ - "tmp.zig:3:28: error: parameter of opaque type 'FooType' not allowed", - "tmp.zig:8:28: error: parameter of type '@Type(.Null)' not allowed", - "tmp.zig:12:11: error: parameter of opaque type 'FooType' not allowed", - "tmp.zig:17:11: error: parameter of type '@Type(.Null)' not allowed", - }); - - ctx.objErrStage1( // fixed bug #2032 - "compile diagnostic string for top level decl type", - \\export fn entry() void { - \\ var foo: u32 = @This(){}; - \\ _ = foo; - \\} - , &[_][]const u8{ - "tmp.zig:2:27: error: type 'u32' does not support array initialization", - }); - - ctx.objErrStage1("issue #2687: coerce from undefined array pointer to slice", - \\export fn foo1() void { - \\ const a: *[1]u8 = undefined; - \\ var b: []u8 = a; - \\ _ = b; - \\} - \\export fn foo2() void { - \\ comptime { - \\ var a: *[1]u8 = undefined; - \\ var b: []u8 = a; - \\ _ = b; - \\ } - \\} - \\export fn foo3() void { - \\ comptime { - \\ const a: *[1]u8 = undefined; - \\ var b: []u8 = a; - \\ _ = b; - \\ } - \\} - , &[_][]const u8{ - "tmp.zig:3:19: error: use of undefined value here causes undefined behavior", - "tmp.zig:9:23: error: use of undefined value here causes undefined behavior", - "tmp.zig:16:23: error: use of undefined value here causes undefined behavior", - }); - - ctx.objErrStage1("issue #3818: bitcast from parray/slice to u16", - \\export fn foo1() void { - \\ var bytes = [_]u8{1, 2}; - \\ const word: u16 = @bitCast(u16, bytes[0..]); - \\ _ = word; - \\} - \\export fn foo2() void { - \\ var bytes: []const u8 = &[_]u8{1, 2}; - \\ const word: u16 = @bitCast(u16, bytes); - \\ _ = word; - \\} - , &[_][]const u8{ - "tmp.zig:3:42: error: unable to @bitCast from pointer type '*[2]u8'", - "tmp.zig:8:32: error: destination type 'u16' has size 2 but source type '[]const u8' has size 16", - }); - - // issue #7810 - ctx.objErrStage1("comptime slice-len increment beyond bounds", - \\export fn foo_slice_len_increment_beyond_bounds() void { - \\ comptime { - \\ var buf_storage: [8]u8 = undefined; - \\ var buf: []const u8 = buf_storage[0..]; - \\ buf.len += 1; - \\ buf[8] = 42; - \\ } - \\} - , &[_][]const u8{ - ":6:12: error: out of bounds slice", - }); - - ctx.objErrStage1("comptime slice-sentinel is out of bounds (unterminated)", - \\export fn foo_array() void { - \\ comptime { - \\ var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ const slice = target[0..14 :0]; - \\ _ = slice; - \\ } - \\} - \\export fn foo_ptr_array() void { - \\ comptime { - \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ var target = &buf; - \\ const slice = target[0..14 :0]; - \\ _ = slice; - \\ } - \\} - \\export fn foo_vector_ConstPtrSpecialBaseArray() void { - \\ comptime { - \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ var target: [*]u8 = &buf; - \\ const slice = target[0..14 :0]; - \\ _ = slice; - \\ } - \\} - \\export fn foo_vector_ConstPtrSpecialRef() void { - \\ comptime { - \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ var target: [*]u8 = @ptrCast([*]u8, &buf); - \\ const slice = target[0..14 :0]; - \\ _ = slice; - \\ } - \\} - \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { - \\ comptime { - \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ var target: [*c]u8 = &buf; - \\ const slice = target[0..14 :0]; - \\ _ = slice; - \\ } - \\} - \\export fn foo_cvector_ConstPtrSpecialRef() void { - \\ comptime { - \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); - \\ const slice = target[0..14 :0]; - \\ _ = slice; - \\ } - \\} - \\export fn foo_slice() void { - \\ comptime { - \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ var target: []u8 = &buf; - \\ const slice = target[0..14 :0]; - \\ _ = slice; - \\ } - \\} - , &[_][]const u8{ - ":4:29: error: slice-sentinel is out of bounds", - ":12:29: error: slice-sentinel is out of bounds", - ":20:29: error: slice-sentinel is out of bounds", - ":28:29: error: slice-sentinel is out of bounds", - ":36:29: error: slice-sentinel is out of bounds", - ":44:29: error: slice-sentinel is out of bounds", - ":52:29: error: slice-sentinel is out of bounds", - }); - - ctx.objErrStage1("comptime slice-sentinel is out of bounds (terminated)", - \\export fn foo_array() void { - \\ comptime { - \\ var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ const slice = target[0..15 :1]; - \\ _ = slice; - \\ } - \\} - \\export fn foo_ptr_array() void { - \\ comptime { - \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ var target = &buf; - \\ const slice = target[0..15 :0]; - \\ _ = slice; - \\ } - \\} - \\export fn foo_vector_ConstPtrSpecialBaseArray() void { - \\ comptime { - \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ var target: [*]u8 = &buf; - \\ const slice = target[0..15 :0]; - \\ _ = slice; - \\ } - \\} - \\export fn foo_vector_ConstPtrSpecialRef() void { - \\ comptime { - \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ var target: [*]u8 = @ptrCast([*]u8, &buf); - \\ const slice = target[0..15 :0]; - \\ _ = slice; - \\ } - \\} - \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { - \\ comptime { - \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ var target: [*c]u8 = &buf; - \\ const slice = target[0..15 :0]; - \\ _ = slice; - \\ } - \\} - \\export fn foo_cvector_ConstPtrSpecialRef() void { - \\ comptime { - \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); - \\ const slice = target[0..15 :0]; - \\ _ = slice; - \\ } - \\} - \\export fn foo_slice() void { - \\ comptime { - \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ var target: []u8 = &buf; - \\ const slice = target[0..15 :0]; - \\ _ = slice; - \\ } - \\} - , &[_][]const u8{ - ":4:29: error: out of bounds slice", - ":12:29: error: out of bounds slice", - ":20:29: error: out of bounds slice", - ":28:29: error: out of bounds slice", - ":36:29: error: out of bounds slice", - ":44:29: error: out of bounds slice", - ":52:29: error: out of bounds slice", - }); - - ctx.objErrStage1("comptime slice-sentinel does not match memory at target index (unterminated)", - \\export fn foo_array() void { - \\ comptime { - \\ var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ const slice = target[0..3 :0]; - \\ _ = slice; - \\ } - \\} - \\export fn foo_ptr_array() void { - \\ comptime { - \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ var target = &buf; - \\ const slice = target[0..3 :0]; - \\ _ = slice; - \\ } - \\} - \\export fn foo_vector_ConstPtrSpecialBaseArray() void { - \\ comptime { - \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ var target: [*]u8 = &buf; - \\ const slice = target[0..3 :0]; - \\ _ = slice; - \\ } - \\} - \\export fn foo_vector_ConstPtrSpecialRef() void { - \\ comptime { - \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ var target: [*]u8 = @ptrCast([*]u8, &buf); - \\ const slice = target[0..3 :0]; - \\ _ = slice; - \\ } - \\} - \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { - \\ comptime { - \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ var target: [*c]u8 = &buf; - \\ const slice = target[0..3 :0]; - \\ _ = slice; - \\ } - \\} - \\export fn foo_cvector_ConstPtrSpecialRef() void { - \\ comptime { - \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); - \\ const slice = target[0..3 :0]; - \\ _ = slice; - \\ } - \\} - \\export fn foo_slice() void { - \\ comptime { - \\ var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ var target: []u8 = &buf; - \\ const slice = target[0..3 :0]; - \\ _ = slice; - \\ } - \\} - , &[_][]const u8{ - ":4:29: error: slice-sentinel does not match memory at target index", - ":12:29: error: slice-sentinel does not match memory at target index", - ":20:29: error: slice-sentinel does not match memory at target index", - ":28:29: error: slice-sentinel does not match memory at target index", - ":36:29: error: slice-sentinel does not match memory at target index", - ":44:29: error: slice-sentinel does not match memory at target index", - ":52:29: error: slice-sentinel does not match memory at target index", - }); - - ctx.objErrStage1("comptime slice-sentinel does not match memory at target index (terminated)", - \\export fn foo_array() void { - \\ comptime { - \\ var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ const slice = target[0..3 :0]; - \\ _ = slice; - \\ } - \\} - \\export fn foo_ptr_array() void { - \\ comptime { - \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ var target = &buf; - \\ const slice = target[0..3 :0]; - \\ _ = slice; - \\ } - \\} - \\export fn foo_vector_ConstPtrSpecialBaseArray() void { - \\ comptime { - \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ var target: [*]u8 = &buf; - \\ const slice = target[0..3 :0]; - \\ _ = slice; - \\ } - \\} - \\export fn foo_vector_ConstPtrSpecialRef() void { - \\ comptime { - \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ var target: [*]u8 = @ptrCast([*]u8, &buf); - \\ const slice = target[0..3 :0]; - \\ _ = slice; - \\ } - \\} - \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { - \\ comptime { - \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ var target: [*c]u8 = &buf; - \\ const slice = target[0..3 :0]; - \\ _ = slice; - \\ } - \\} - \\export fn foo_cvector_ConstPtrSpecialRef() void { - \\ comptime { - \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); - \\ const slice = target[0..3 :0]; - \\ _ = slice; - \\ } - \\} - \\export fn foo_slice() void { - \\ comptime { - \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ var target: []u8 = &buf; - \\ const slice = target[0..3 :0]; - \\ _ = slice; - \\ } - \\} - , &[_][]const u8{ - ":4:29: error: slice-sentinel does not match memory at target index", - ":12:29: error: slice-sentinel does not match memory at target index", - ":20:29: error: slice-sentinel does not match memory at target index", - ":28:29: error: slice-sentinel does not match memory at target index", - ":36:29: error: slice-sentinel does not match memory at target index", - ":44:29: error: slice-sentinel does not match memory at target index", - ":52:29: error: slice-sentinel does not match memory at target index", - }); - - ctx.objErrStage1("comptime slice-sentinel does not match target-sentinel", - \\export fn foo_array() void { - \\ comptime { - \\ var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ const slice = target[0..14 :255]; - \\ _ = slice; - \\ } - \\} - \\export fn foo_ptr_array() void { - \\ comptime { - \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ var target = &buf; - \\ const slice = target[0..14 :255]; - \\ _ = slice; - \\ } - \\} - \\export fn foo_vector_ConstPtrSpecialBaseArray() void { - \\ comptime { - \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ var target: [*]u8 = &buf; - \\ const slice = target[0..14 :255]; - \\ _ = slice; - \\ } - \\} - \\export fn foo_vector_ConstPtrSpecialRef() void { - \\ comptime { - \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ var target: [*]u8 = @ptrCast([*]u8, &buf); - \\ const slice = target[0..14 :255]; - \\ _ = slice; - \\ } - \\} - \\export fn foo_cvector_ConstPtrSpecialBaseArray() void { - \\ comptime { - \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ var target: [*c]u8 = &buf; - \\ const slice = target[0..14 :255]; - \\ _ = slice; - \\ } - \\} - \\export fn foo_cvector_ConstPtrSpecialRef() void { - \\ comptime { - \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ var target: [*c]u8 = @ptrCast([*c]u8, &buf); - \\ const slice = target[0..14 :255]; - \\ _ = slice; - \\ } - \\} - \\export fn foo_slice() void { - \\ comptime { - \\ var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; - \\ var target: []u8 = &buf; - \\ const slice = target[0..14 :255]; - \\ _ = slice; - \\ } - \\} - , &[_][]const u8{ - ":4:29: error: slice-sentinel does not match target-sentinel", - ":12:29: error: slice-sentinel does not match target-sentinel", - ":20:29: error: slice-sentinel does not match target-sentinel", - ":28:29: error: slice-sentinel does not match target-sentinel", - ":36:29: error: slice-sentinel does not match target-sentinel", - ":44:29: error: slice-sentinel does not match target-sentinel", - ":52:29: error: slice-sentinel does not match target-sentinel", - }); - - ctx.objErrStage1("issue #4207: coerce from non-terminated-slice to terminated-pointer", - \\export fn foo() [*:0]const u8 { - \\ var buffer: [64]u8 = undefined; - \\ return buffer[0..]; - \\} - , &[_][]const u8{ - ":3:18: error: expected type '[*:0]const u8', found '*[64]u8'", - ":3:18: note: destination pointer requires a terminating '0' sentinel", - }); - - ctx.objErrStage1("issue #5221: invalid struct init type referenced by @typeInfo and passed into function", - \\fn ignore(comptime param: anytype) void {_ = param;} - \\ - \\export fn foo() void { - \\ const MyStruct = struct { - \\ wrong_type: []u8 = "foo", - \\ }; - \\ - \\ comptime ignore(@typeInfo(MyStruct).Struct.fields[0]); - \\} - , &[_][]const u8{ - ":5:28: error: cannot cast pointer to array literal to slice type '[]u8'", - ":5:28: note: cast discards const qualifier", - }); - - ctx.objErrStage1("integer underflow error", - \\export fn entry() void { - \\ _ = @intToPtr(*anyopaque, ~@as(usize, @import("std").math.maxInt(usize)) - 1); - \\} - , &[_][]const u8{ - ":2:78: error: operation caused overflow", - }); - { const case = ctx.obj("align(N) expr function pointers is a compile error", .{ .cpu_arch = .wasm32, @@ -8812,165 +420,4 @@ pub fn addCases(ctx: *TestContext) !void { "tmp.zig:1:23: error: align(N) expr is not allowed on function prototypes in wasm32/wasm64", }); } - - ctx.objErrStage1("compare optional to non-optional with invalid types", - \\export fn inconsistentChildType() void { - \\ var x: ?i32 = undefined; - \\ const y: comptime_int = 10; - \\ _ = (x == y); - \\} - \\ - \\export fn optionalToOptional() void { - \\ var x: ?i32 = undefined; - \\ var y: ?i32 = undefined; - \\ _ = (x == y); - \\} - \\ - \\export fn optionalVector() void { - \\ var x: ?@Vector(10, i32) = undefined; - \\ var y: @Vector(10, i32) = undefined; - \\ _ = (x == y); - \\} - \\ - \\export fn invalidChildType() void { - \\ var x: ?[3]i32 = undefined; - \\ var y: [3]i32 = undefined; - \\ _ = (x == y); - \\} - , &[_][]const u8{ - ":4:12: error: cannot compare types '?i32' and 'comptime_int'", - ":4:12: note: optional child type 'i32' must be the same as non-optional type 'comptime_int'", - ":10:12: error: cannot compare types '?i32' and '?i32'", - ":10:12: note: optional to optional comparison is only supported for optional pointer types", - ":16:12: error: TODO add comparison of optional vector", - ":22:12: error: cannot compare types '?[3]i32' and '[3]i32'", - ":22:12: note: operator not supported for type '[3]i32'", - }); - - ctx.objErrStage1("slice cannot have its bytes reinterpreted", - \\export fn foo() void { - \\ const bytes = [1]u8{ 0xfa } ** 16; - \\ var value = @ptrCast(*const []const u8, &bytes).*; - \\ _ = value; - \\} - , &[_][]const u8{ - ":3:52: error: slice '[]const u8' cannot have its bytes reinterpreted", - }); - - ctx.objErrStage1("wasmMemorySize is a compile error in non-Wasm targets", - \\export fn foo() void { - \\ _ = @wasmMemorySize(0); - \\ return; - \\} - , &[_][]const u8{ - "tmp.zig:2:9: error: @wasmMemorySize is a wasm32 feature only", - }); - - ctx.objErrStage1("wasmMemoryGrow is a compile error in non-Wasm targets", - \\export fn foo() void { - \\ _ = @wasmMemoryGrow(0, 1); - \\ return; - \\} - , &[_][]const u8{ - "tmp.zig:2:9: error: @wasmMemoryGrow is a wasm32 feature only", - }); - ctx.objErrStage1("Issue #5586: Make unary minus for unsigned types a compile error", - \\export fn f1(x: u32) u32 { - \\ const y = -%x; - \\ return -y; - \\} - \\const V = @import("std").meta.Vector; - \\export fn f2(x: V(4, u32)) V(4, u32) { - \\ const y = -%x; - \\ return -y; - \\} - , &[_][]const u8{ - "tmp.zig:3:12: error: negation of type 'u32'", - "tmp.zig:8:12: error: negation of type 'u32'", - }); - - ctx.objErrStage1("Issue #5618: coercion of ?*anyopaque to *anyopaque must fail.", - \\export fn foo() void { - \\ var u: ?*anyopaque = null; - \\ var v: *anyopaque = undefined; - \\ v = u; - \\} - , &[_][]const u8{ - "tmp.zig:4:9: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type '*anyopaque', found '?*anyopaque'", - }); - - ctx.objErrStage1("Issue #6823: don't allow .* to be followed by **", - \\fn foo() void { - \\ var sequence = "repeat".*** 10; - \\ _ = sequence; - \\} - , &[_][]const u8{ - // Ideally this would be column 30 but it's not very important. - "tmp.zig:2:28: error: '.*' cannot be followed by '*'. Are you missing a space?", - }); - - ctx.objErrStage1("Issue #9165: windows tcp server compilation error", - \\const std = @import("std"); - \\const builtin = @import("builtin"); - \\pub const io_mode = .evented; - \\pub fn main() !void { - \\ if (builtin.os.tag == .windows) { - \\ _ = try (std.net.StreamServer.init(.{})).accept(); - \\ } else { - \\ @compileError("Unsupported OS"); - \\ } - \\} - , &[_][]const u8{ - "error: Unsupported OS", - }); - - ctx.objErrStage1("attempt to close over comptime variable from outer scope", - \\fn SimpleList(comptime L: usize) type { - \\ var T = u8; - \\ return struct { - \\ array: [L]T, - \\ }; - \\} - , &[_][]const u8{ - "tmp.zig:4:19: error: mutable 'T' not accessible from here", - "tmp.zig:2:9: note: declared mutable here", - "tmp.zig:3:12: note: crosses namespace boundary here", - }); - - ctx.objErrStage1("saturating arithmetic does not allow floats", - \\export fn a() void { - \\ _ = @as(f32, 1.0) +| @as(f32, 1.0); - \\} - , &[_][]const u8{ - "error: invalid operands to binary expression: 'f32' and 'f32'", - }); - - ctx.objErrStage1("saturating shl does not allow negative rhs at comptime", - \\export fn a() void { - \\ _ = @as(i32, 1) <<| @as(i32, -2); - \\} - , &[_][]const u8{ - "error: shift by negative value -2", - }); - - ctx.objErrStage1("saturating shl assign does not allow negative rhs at comptime", - \\export fn a() void { - \\ comptime { - \\ var x = @as(i32, 1); - \\ x <<|= @as(i32, -2); - \\ } - \\} - , &[_][]const u8{ - "error: shift by negative value -2", - }); - - ctx.objErrStage1("undeclared identifier in unanalyzed branch", - \\export fn a() void { - \\ if (false) { - \\ lol_this_doesnt_exist = nonsense; - \\ } - \\} - , &[_][]const u8{ - "tmp.zig:3:9: error: use of undeclared identifier 'lol_this_doesnt_exist'", - }); } diff --git a/test/compile_errors/stage1/exe/main_missing_name.zig b/test/compile_errors/stage1/exe/main_missing_name.zig new file mode 100644 index 0000000000..c029665367 --- /dev/null +++ b/test/compile_errors/stage1/exe/main_missing_name.zig @@ -0,0 +1,5 @@ +pub fn (main) void {} + +// main missing name +// +// tmp.zig:1:5: error: missing function name diff --git a/test/compile_errors/stage1/exe/missing_main_fn_in_executable.zig b/test/compile_errors/stage1/exe/missing_main_fn_in_executable.zig new file mode 100644 index 0000000000..eb9ab469fd --- /dev/null +++ b/test/compile_errors/stage1/exe/missing_main_fn_in_executable.zig @@ -0,0 +1,5 @@ + + +// missing main fn in executable +// +// error: root source file has no member called 'main' diff --git a/test/compile_errors/stage1/exe/private_main_fn.zig b/test/compile_errors/stage1/exe/private_main_fn.zig new file mode 100644 index 0000000000..da617899a5 --- /dev/null +++ b/test/compile_errors/stage1/exe/private_main_fn.zig @@ -0,0 +1,6 @@ +fn main() void {} + +// private main fn +// +// error: 'main' is private +// tmp.zig:1:1: note: declared here diff --git a/test/compile_errors/stage1/exe/std.fmt_error_for_unused_arguments.zig b/test/compile_errors/stage1/exe/std.fmt_error_for_unused_arguments.zig new file mode 100644 index 0000000000..7da78d5b03 --- /dev/null +++ b/test/compile_errors/stage1/exe/std.fmt_error_for_unused_arguments.zig @@ -0,0 +1,7 @@ +pub fn main() !void { + @import("std").debug.print("{d} {d} {d} {d} {d}", .{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}); +} + +// std.fmt error for unused arguments +// +// ?:?:?: error: 10 unused arguments in '{d} {d} {d} {d} {d}' diff --git a/test/compile_errors/stage1/obj/C_pointer_pointing_to_non_C_ABI_compatible_type_or_has_align_attr.zig b/test/compile_errors/stage1/obj/C_pointer_pointing_to_non_C_ABI_compatible_type_or_has_align_attr.zig new file mode 100644 index 0000000000..24fd0d1b9f --- /dev/null +++ b/test/compile_errors/stage1/obj/C_pointer_pointing_to_non_C_ABI_compatible_type_or_has_align_attr.zig @@ -0,0 +1,10 @@ +const Foo = struct {}; +export fn a() void { + const T = [*c]Foo; + var t: T = undefined; + _ = t; +} + +// C pointer pointing to non C ABI compatible type or has align attr +// +// tmp.zig:3:19: error: C pointers cannot point to non-C-ABI-compatible type 'Foo' diff --git a/test/compile_errors/stage1/obj/C_pointer_to_anyopaque.zig b/test/compile_errors/stage1/obj/C_pointer_to_anyopaque.zig new file mode 100644 index 0000000000..3012996145 --- /dev/null +++ b/test/compile_errors/stage1/obj/C_pointer_to_anyopaque.zig @@ -0,0 +1,9 @@ +export fn a() void { + var x: *anyopaque = undefined; + var y: [*c]anyopaque = x; + _ = y; +} + +// C pointer to anyopaque +// +// tmp.zig:3:16: error: C pointers cannot point to opaque types diff --git a/test/compile_errors/stage1/obj/Frame_of_generic_function.zig b/test/compile_errors/stage1/obj/Frame_of_generic_function.zig new file mode 100644 index 0000000000..b9b2280dd7 --- /dev/null +++ b/test/compile_errors/stage1/obj/Frame_of_generic_function.zig @@ -0,0 +1,12 @@ +export fn entry() void { + var frame: @Frame(func) = undefined; + _ = frame; +} +fn func(comptime T: type) void { + var x: T = undefined; + _ = x; +} + +// @Frame() of generic function +// +// tmp.zig:2:16: error: @Frame() of generic function diff --git a/test/compile_errors/stage1/obj/Issue_5586_Make_unary_minus_for_unsigned_types_a_compile_error.zig b/test/compile_errors/stage1/obj/Issue_5586_Make_unary_minus_for_unsigned_types_a_compile_error.zig new file mode 100644 index 0000000000..d01e68e4eb --- /dev/null +++ b/test/compile_errors/stage1/obj/Issue_5586_Make_unary_minus_for_unsigned_types_a_compile_error.zig @@ -0,0 +1,14 @@ +export fn f1(x: u32) u32 { + const y = -%x; + return -y; +} +const V = @import("std").meta.Vector; +export fn f2(x: V(4, u32)) V(4, u32) { + const y = -%x; + return -y; +} + +// Issue #5586: Make unary minus for unsigned types a compile error +// +// tmp.zig:3:12: error: negation of type 'u32' +// tmp.zig:8:12: error: negation of type 'u32' diff --git a/test/compile_errors/stage1/obj/Issue_6823_dont_allow_._to_be_followed_by_.zig b/test/compile_errors/stage1/obj/Issue_6823_dont_allow_._to_be_followed_by_.zig new file mode 100644 index 0000000000..c21df43362 --- /dev/null +++ b/test/compile_errors/stage1/obj/Issue_6823_dont_allow_._to_be_followed_by_.zig @@ -0,0 +1,8 @@ +fn foo() void { + var sequence = "repeat".*** 10; + _ = sequence; +} + +// Issue #6823: don't allow .* to be followed by ** +// +// tmp.zig:2:28: error: '.*' cannot be followed by '*'. Are you missing a space? diff --git a/test/compile_errors/stage1/obj/Issue_9165_windows_tcp_server_compilation_error.zig b/test/compile_errors/stage1/obj/Issue_9165_windows_tcp_server_compilation_error.zig new file mode 100644 index 0000000000..e3b9d4b009 --- /dev/null +++ b/test/compile_errors/stage1/obj/Issue_9165_windows_tcp_server_compilation_error.zig @@ -0,0 +1,14 @@ +const std = @import("std"); +const builtin = @import("builtin"); +pub const io_mode = .evented; +pub fn main() !void { + if (builtin.os.tag == .windows) { + _ = try (std.net.StreamServer.init(.{})).accept(); + } else { + @compileError("Unsupported OS"); + } +} + +// Issue #9165: windows tcp server compilation error +// +// error: Unsupported OS diff --git a/test/compile_errors/stage1/obj/access_non-existent_member_of_error_set.zig b/test/compile_errors/stage1/obj/access_non-existent_member_of_error_set.zig new file mode 100644 index 0000000000..42a54b08cd --- /dev/null +++ b/test/compile_errors/stage1/obj/access_non-existent_member_of_error_set.zig @@ -0,0 +1,9 @@ +const Foo = error{A}; +comptime { + const z = Foo.Bar; + _ = z; +} + +// access non-existent member of error set +// +// tmp.zig:3:18: error: no error named 'Bar' in 'Foo' diff --git a/test/compile_errors/stage1/obj/accessing_runtime_parameter_from_outer_function.zig b/test/compile_errors/stage1/obj/accessing_runtime_parameter_from_outer_function.zig new file mode 100644 index 0000000000..68b23c6a43 --- /dev/null +++ b/test/compile_errors/stage1/obj/accessing_runtime_parameter_from_outer_function.zig @@ -0,0 +1,19 @@ +fn outer(y: u32) fn (u32) u32 { + const st = struct { + fn get(z: u32) u32 { + return z + y; + } + }; + return st.get; +} +export fn entry() void { + var func = outer(10); + var x = func(3); + _ = x; +} + +// accessing runtime parameter from outer function +// +// tmp.zig:4:24: error: 'y' not accessible from inner function +// tmp.zig:3:28: note: crossed function definition here +// tmp.zig:1:10: note: declared here diff --git a/test/compile_errors/stage1/obj/add_assign_on_undefined_value.zig b/test/compile_errors/stage1/obj/add_assign_on_undefined_value.zig new file mode 100644 index 0000000000..0076cf1bab --- /dev/null +++ b/test/compile_errors/stage1/obj/add_assign_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: i64 = undefined; + a += a; +} + +// add assign on undefined value +// +// tmp.zig:3:5: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/add_on_undefined_value.zig b/test/compile_errors/stage1/obj/add_on_undefined_value.zig new file mode 100644 index 0000000000..5f64c6999b --- /dev/null +++ b/test/compile_errors/stage1/obj/add_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: i64 = undefined; + _ = a + a; +} + +// add on undefined value +// +// tmp.zig:3:9: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/add_overflow_in_function_evaluation.zig b/test/compile_errors/stage1/obj/add_overflow_in_function_evaluation.zig new file mode 100644 index 0000000000..b01e005a04 --- /dev/null +++ b/test/compile_errors/stage1/obj/add_overflow_in_function_evaluation.zig @@ -0,0 +1,10 @@ +const y = add(65530, 10); +fn add(a: u16, b: u16) u16 { + return a + b; +} + +export fn entry() usize { return @sizeOf(@TypeOf(y)); } + +// add overflow in function evaluation +// +// tmp.zig:3:14: error: operation caused overflow diff --git a/test/compile_errors/stage1/obj/add_wrap_assign_on_undefined_value.zig b/test/compile_errors/stage1/obj/add_wrap_assign_on_undefined_value.zig new file mode 100644 index 0000000000..37dbf9106f --- /dev/null +++ b/test/compile_errors/stage1/obj/add_wrap_assign_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: i64 = undefined; + a +%= a; +} + +// add wrap assign on undefined value +// +// tmp.zig:3:5: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/add_wrap_on_undefined_value.zig b/test/compile_errors/stage1/obj/add_wrap_on_undefined_value.zig new file mode 100644 index 0000000000..3ba9bd11c6 --- /dev/null +++ b/test/compile_errors/stage1/obj/add_wrap_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: i64 = undefined; + _ = a +% a; +} + +// add wrap on undefined value +// +// tmp.zig:3:9: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/addition_with_non_numbers.zig b/test/compile_errors/stage1/obj/addition_with_non_numbers.zig new file mode 100644 index 0000000000..296b9f4103 --- /dev/null +++ b/test/compile_errors/stage1/obj/addition_with_non_numbers.zig @@ -0,0 +1,10 @@ +const Foo = struct { + field: i32, +}; +const x = Foo {.field = 1} + Foo {.field = 2}; + +export fn entry() usize { return @sizeOf(@TypeOf(x)); } + +// addition with non numbers +// +// tmp.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo' diff --git a/test/compile_errors/stage1/obj/address_of_number_literal.zig b/test/compile_errors/stage1/obj/address_of_number_literal.zig new file mode 100644 index 0000000000..ee61f2180f --- /dev/null +++ b/test/compile_errors/stage1/obj/address_of_number_literal.zig @@ -0,0 +1,8 @@ +const x = 3; +const y = &x; +fn foo() *const i32 { return y; } +export fn entry() usize { return @sizeOf(@TypeOf(foo)); } + +// address of number literal +// +// tmp.zig:3:30: error: expected type '*const i32', found '*const comptime_int' diff --git a/test/compile_errors/stage1/obj/alignCast_expects_pointer_or_slice.zig b/test/compile_errors/stage1/obj/alignCast_expects_pointer_or_slice.zig new file mode 100644 index 0000000000..91b269cef4 --- /dev/null +++ b/test/compile_errors/stage1/obj/alignCast_expects_pointer_or_slice.zig @@ -0,0 +1,7 @@ +export fn entry() void { + @alignCast(4, @as(u32, 3)); +} + +// @alignCast expects pointer or slice +// +// tmp.zig:2:19: error: expected pointer or slice, found 'u32' diff --git a/test/compile_errors/stage1/obj/aligned_variable_of_zero-bit_type.zig b/test/compile_errors/stage1/obj/aligned_variable_of_zero-bit_type.zig new file mode 100644 index 0000000000..90e690056d --- /dev/null +++ b/test/compile_errors/stage1/obj/aligned_variable_of_zero-bit_type.zig @@ -0,0 +1,8 @@ +export fn f() void { + var s: struct {} align(4) = undefined; + _ = s; +} + +// aligned variable of zero-bit type +// +// tmp.zig:2:5: error: variable 's' of zero-bit type 'struct:2:12' has no in-memory representation, it cannot be aligned diff --git a/test/compile_errors/stage1/obj/alignment_of_enum_field_specified.zig b/test/compile_errors/stage1/obj/alignment_of_enum_field_specified.zig new file mode 100644 index 0000000000..cf5cdfd213 --- /dev/null +++ b/test/compile_errors/stage1/obj/alignment_of_enum_field_specified.zig @@ -0,0 +1,12 @@ +const Number = enum { + a, + b align(i32), +}; +export fn entry1() void { + var x: Number = undefined; + _ = x; +} + +// alignment of enum field specified +// +// tmp.zig:3:7: error: expected ',' after field diff --git a/test/compile_errors/stage1/obj/ambiguous_decl_reference.zig b/test/compile_errors/stage1/obj/ambiguous_decl_reference.zig new file mode 100644 index 0000000000..421c41d2c2 --- /dev/null +++ b/test/compile_errors/stage1/obj/ambiguous_decl_reference.zig @@ -0,0 +1,19 @@ +fn foo() void {} +fn bar() void { + const S = struct { + fn baz() void { + foo(); + } + fn foo() void {} + }; + S.baz(); +} +export fn entry() void { + bar(); +} + +// ambiguous decl reference +// +// tmp.zig:5:13: error: ambiguous reference +// tmp.zig:7:9: note: declared here +// tmp.zig:1:1: note: also declared here diff --git a/test/compile_errors/stage1/obj/and_on_undefined_value.zig b/test/compile_errors/stage1/obj/and_on_undefined_value.zig new file mode 100644 index 0000000000..82363848f3 --- /dev/null +++ b/test/compile_errors/stage1/obj/and_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: bool = undefined; + _ = a and a; +} + +// and on undefined value +// +// tmp.zig:3:9: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/array_access_of_non_array.zig b/test/compile_errors/stage1/obj/array_access_of_non_array.zig new file mode 100644 index 0000000000..e4420debcd --- /dev/null +++ b/test/compile_errors/stage1/obj/array_access_of_non_array.zig @@ -0,0 +1,13 @@ +export fn f() void { + var bad : bool = undefined; + bad[0] = bad[0]; +} +export fn g() void { + var bad : bool = undefined; + _ = bad[0]; +} + +// array access of non array +// +// tmp.zig:3:8: error: array access of non-array type 'bool' +// tmp.zig:7:12: error: array access of non-array type 'bool' diff --git a/test/compile_errors/stage1/obj/array_access_of_type.zig b/test/compile_errors/stage1/obj/array_access_of_type.zig new file mode 100644 index 0000000000..82708eed6c --- /dev/null +++ b/test/compile_errors/stage1/obj/array_access_of_type.zig @@ -0,0 +1,8 @@ +export fn foo() void { + var b: u8[40] = undefined; + _ = b; +} + +// array access of type +// +// tmp.zig:2:14: error: array access of non-array type 'type' diff --git a/test/compile_errors/stage1/obj/array_access_of_undeclared_identifier.zig b/test/compile_errors/stage1/obj/array_access_of_undeclared_identifier.zig new file mode 100644 index 0000000000..193a7bf5de --- /dev/null +++ b/test/compile_errors/stage1/obj/array_access_of_undeclared_identifier.zig @@ -0,0 +1,7 @@ +export fn f() void { + i[i] = i[i]; +} + +// array access of undeclared identifier +// +// tmp.zig:2:5: error: use of undeclared identifier 'i' diff --git a/test/compile_errors/stage1/obj/array_access_with_non_integer_index.zig b/test/compile_errors/stage1/obj/array_access_with_non_integer_index.zig new file mode 100644 index 0000000000..1a3e17d896 --- /dev/null +++ b/test/compile_errors/stage1/obj/array_access_with_non_integer_index.zig @@ -0,0 +1,15 @@ +export fn f() void { + var array = "aoeu"; + var bad = false; + array[bad] = array[bad]; +} +export fn g() void { + var array = "aoeu"; + var bad = false; + _ = array[bad]; +} + +// array access with non integer index +// +// tmp.zig:4:11: error: expected type 'usize', found 'bool' +// tmp.zig:9:15: error: expected type 'usize', found 'bool' diff --git a/test/compile_errors/stage1/obj/array_concatenation_with_wrong_type.zig b/test/compile_errors/stage1/obj/array_concatenation_with_wrong_type.zig new file mode 100644 index 0000000000..91036e5f25 --- /dev/null +++ b/test/compile_errors/stage1/obj/array_concatenation_with_wrong_type.zig @@ -0,0 +1,9 @@ +const src = "aoeu"; +const derp: usize = 1234; +const a = derp ++ "foo"; + +export fn entry() usize { return @sizeOf(@TypeOf(a)); } + +// array concatenation with wrong type +// +// tmp.zig:3:11: error: expected array, found 'usize' diff --git a/test/compile_errors/stage1/obj/array_in_c_exported_function.zig b/test/compile_errors/stage1/obj/array_in_c_exported_function.zig new file mode 100644 index 0000000000..fe03d220b1 --- /dev/null +++ b/test/compile_errors/stage1/obj/array_in_c_exported_function.zig @@ -0,0 +1,12 @@ +export fn zig_array(x: [10]u8) void { + try std.testing.expect(std.mem.eql(u8, &x, "1234567890")); +} +const std = @import("std"); +export fn zig_return_array() [10]u8 { + return "1234567890".*; +} + +// array in c exported function +// +// tmp.zig:1:24: error: parameter of type '[10]u8' not allowed in function with calling convention 'C' +// tmp.zig:5:30: error: return type '[10]u8' not allowed in function with calling convention 'C' diff --git a/test/compile_errors/stage1/obj/asm_at_compile_time.zig b/test/compile_errors/stage1/obj/asm_at_compile_time.zig new file mode 100644 index 0000000000..e08b500c6e --- /dev/null +++ b/test/compile_errors/stage1/obj/asm_at_compile_time.zig @@ -0,0 +1,15 @@ +comptime { + doSomeAsm(); +} + +fn doSomeAsm() void { + asm volatile ( + \\.globl aoeu; + \\.type aoeu, @function; + \\.set aoeu, derp; + ); +} + +// asm at compile time +// +// tmp.zig:6:5: error: unable to evaluate constant expression diff --git a/test/compile_errors/stage1/obj/assign_inline_fn_to_non-comptime_var.zig b/test/compile_errors/stage1/obj/assign_inline_fn_to_non-comptime_var.zig new file mode 100644 index 0000000000..aa7bb91d1b --- /dev/null +++ b/test/compile_errors/stage1/obj/assign_inline_fn_to_non-comptime_var.zig @@ -0,0 +1,10 @@ +export fn entry() void { + var a = b; + _ = a; +} +fn b() callconv(.Inline) void { } + +// assign inline fn to non-comptime var +// +// tmp.zig:2:5: error: functions marked inline must be stored in const or comptime var +// tmp.zig:5:1: note: declared here diff --git a/test/compile_errors/stage1/obj/assign_null_to_non-optional_pointer.zig b/test/compile_errors/stage1/obj/assign_null_to_non-optional_pointer.zig new file mode 100644 index 0000000000..9c1aaf5031 --- /dev/null +++ b/test/compile_errors/stage1/obj/assign_null_to_non-optional_pointer.zig @@ -0,0 +1,7 @@ +const a: *u8 = null; + +export fn entry() usize { return @sizeOf(@TypeOf(a)); } + +// assign null to non-optional pointer +// +// tmp.zig:1:16: error: expected type '*u8', found '@Type(.Null)' diff --git a/test/compile_errors/stage1/obj/assign_through_constant_pointer.zig b/test/compile_errors/stage1/obj/assign_through_constant_pointer.zig new file mode 100644 index 0000000000..452e3ea617 --- /dev/null +++ b/test/compile_errors/stage1/obj/assign_through_constant_pointer.zig @@ -0,0 +1,8 @@ +export fn f() void { + var cstr = "Hat"; + cstr[0] = 'W'; +} + +// assign through constant pointer +// +// tmp.zig:3:13: error: cannot assign to constant diff --git a/test/compile_errors/stage1/obj/assign_through_constant_slice.zig b/test/compile_errors/stage1/obj/assign_through_constant_slice.zig new file mode 100644 index 0000000000..e36991897b --- /dev/null +++ b/test/compile_errors/stage1/obj/assign_through_constant_slice.zig @@ -0,0 +1,8 @@ +export fn f() void { + var cstr: []const u8 = "Hat"; + cstr[0] = 'W'; +} + +// assign through constant slice +// +// tmp.zig:3:13: error: cannot assign to constant diff --git a/test/compile_errors/stage1/obj/assign_to_constant_field.zig b/test/compile_errors/stage1/obj/assign_to_constant_field.zig new file mode 100644 index 0000000000..f371655fb5 --- /dev/null +++ b/test/compile_errors/stage1/obj/assign_to_constant_field.zig @@ -0,0 +1,11 @@ +const Foo = struct { + field: i32, +}; +export fn derp() void { + const f = Foo {.field = 1234,}; + f.field = 0; +} + +// assign to constant field +// +// tmp.zig:6:15: error: cannot assign to constant diff --git a/test/compile_errors/stage1/obj/assign_to_constant_variable.zig b/test/compile_errors/stage1/obj/assign_to_constant_variable.zig new file mode 100644 index 0000000000..1e8dd6c06f --- /dev/null +++ b/test/compile_errors/stage1/obj/assign_to_constant_variable.zig @@ -0,0 +1,8 @@ +export fn f() void { + const a = 3; + a = 4; +} + +// assign to constant variable +// +// tmp.zig:3:9: error: cannot assign to constant diff --git a/test/compile_errors/stage1/obj/assign_to_invalid_dereference.zig b/test/compile_errors/stage1/obj/assign_to_invalid_dereference.zig new file mode 100644 index 0000000000..6466f7afc8 --- /dev/null +++ b/test/compile_errors/stage1/obj/assign_to_invalid_dereference.zig @@ -0,0 +1,7 @@ +export fn entry() void { + 'a'.* = 1; +} + +// assign to invalid dereference +// +// tmp.zig:2:8: error: attempt to dereference non-pointer type 'comptime_int' diff --git a/test/compile_errors/stage1/obj/assign_too_big_number_to_u16.zig b/test/compile_errors/stage1/obj/assign_too_big_number_to_u16.zig new file mode 100644 index 0000000000..13b5280588 --- /dev/null +++ b/test/compile_errors/stage1/obj/assign_too_big_number_to_u16.zig @@ -0,0 +1,8 @@ +export fn foo() void { + var vga_mem: u16 = 0xB8000; + _ = vga_mem; +} + +// assign too big number to u16 +// +// tmp.zig:2:24: error: integer value 753664 cannot be coerced to type 'u16' diff --git a/test/compile_errors/stage1/obj/assign_unreachable.zig b/test/compile_errors/stage1/obj/assign_unreachable.zig new file mode 100644 index 0000000000..78e2305abc --- /dev/null +++ b/test/compile_errors/stage1/obj/assign_unreachable.zig @@ -0,0 +1,8 @@ +export fn f() void { + const a = return; +} + +// assign unreachable +// +// tmp.zig:2:5: error: unreachable code +// tmp.zig:2:15: note: control flow is diverted here diff --git a/test/compile_errors/stage1/obj/assigning_to_struct_or_union_fields_that_are_not_optionals_with_a_function_that_returns_an_optional.zig b/test/compile_errors/stage1/obj/assigning_to_struct_or_union_fields_that_are_not_optionals_with_a_function_that_returns_an_optional.zig new file mode 100644 index 0000000000..f93650821b --- /dev/null +++ b/test/compile_errors/stage1/obj/assigning_to_struct_or_union_fields_that_are_not_optionals_with_a_function_that_returns_an_optional.zig @@ -0,0 +1,19 @@ +fn maybe(is: bool) ?u8 { + if (is) return @as(u8, 10) else return null; +} +const U = union { + Ye: u8, +}; +const S = struct { + num: u8, +}; +export fn entry() void { + var u = U{ .Ye = maybe(false) }; + var s = S{ .num = maybe(false) }; + _ = u; + _ = s; +} + +// assigning to struct or union fields that are not optionals with a function that returns an optional +// +// tmp.zig:11:27: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'u8', found '?u8' diff --git a/test/compile_errors/stage1/obj/async_function_depends_on_its_own_frame.zig b/test/compile_errors/stage1/obj/async_function_depends_on_its_own_frame.zig new file mode 100644 index 0000000000..0d1cd7f77e --- /dev/null +++ b/test/compile_errors/stage1/obj/async_function_depends_on_its_own_frame.zig @@ -0,0 +1,11 @@ +export fn entry() void { + _ = async amain(); +} +fn amain() callconv(.Async) void { + var x: [@sizeOf(@Frame(amain))]u8 = undefined; + _ = x; +} + +// async function depends on its own frame +// +// tmp.zig:4:1: error: cannot resolve '@Frame(amain)': function not fully analyzed yet diff --git a/test/compile_errors/stage1/obj/async_function_indirectly_depends_on_its_own_frame.zig b/test/compile_errors/stage1/obj/async_function_indirectly_depends_on_its_own_frame.zig new file mode 100644 index 0000000000..809409f524 --- /dev/null +++ b/test/compile_errors/stage1/obj/async_function_indirectly_depends_on_its_own_frame.zig @@ -0,0 +1,15 @@ +export fn entry() void { + _ = async amain(); +} +fn amain() callconv(.Async) void { + other(); +} +fn other() void { + var x: [@sizeOf(@Frame(amain))]u8 = undefined; + _ = x; +} + +// async function indirectly depends on its own frame +// +// tmp.zig:4:1: error: unable to determine async function frame of 'amain' +// tmp.zig:5:10: note: analysis of function 'other' depends on the frame diff --git a/test/compile_errors/stage1/obj/atomic_orderings_of_atomicStore_Acquire_or_AcqRel.zig b/test/compile_errors/stage1/obj/atomic_orderings_of_atomicStore_Acquire_or_AcqRel.zig new file mode 100644 index 0000000000..7d97c2813e --- /dev/null +++ b/test/compile_errors/stage1/obj/atomic_orderings_of_atomicStore_Acquire_or_AcqRel.zig @@ -0,0 +1,8 @@ +export fn entry() void { + var x: u32 = 0; + @atomicStore(u32, &x, 1, .Acquire); +} + +// atomic orderings of atomicStore Acquire or AcqRel +// +// tmp.zig:3:30: error: @atomicStore atomic ordering must not be Acquire or AcqRel diff --git a/test/compile_errors/stage1/obj/atomic_orderings_of_cmpxchg-failure_stricter_than_success.zig b/test/compile_errors/stage1/obj/atomic_orderings_of_cmpxchg-failure_stricter_than_success.zig new file mode 100644 index 0000000000..d6d9ab478b --- /dev/null +++ b/test/compile_errors/stage1/obj/atomic_orderings_of_cmpxchg-failure_stricter_than_success.zig @@ -0,0 +1,9 @@ +const AtomicOrder = @import("std").builtin.AtomicOrder; +export fn f() void { + var x: i32 = 1234; + while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {} +} + +// atomic orderings of cmpxchg - failure stricter than success +// +// tmp.zig:4:81: error: failure atomic ordering must be no stricter than success diff --git a/test/compile_errors/stage1/obj/atomic_orderings_of_cmpxchg-success_Monotonic_or_stricter.zig b/test/compile_errors/stage1/obj/atomic_orderings_of_cmpxchg-success_Monotonic_or_stricter.zig new file mode 100644 index 0000000000..770c08f3fe --- /dev/null +++ b/test/compile_errors/stage1/obj/atomic_orderings_of_cmpxchg-success_Monotonic_or_stricter.zig @@ -0,0 +1,9 @@ +const AtomicOrder = @import("std").builtin.AtomicOrder; +export fn f() void { + var x: i32 = 1234; + while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {} +} + +// atomic orderings of cmpxchg - success Monotonic or stricter +// +// tmp.zig:4:58: error: success atomic ordering must be Monotonic or stricter diff --git a/test/compile_errors/stage1/obj/atomic_orderings_of_fence_Acquire_or_stricter.zig b/test/compile_errors/stage1/obj/atomic_orderings_of_fence_Acquire_or_stricter.zig new file mode 100644 index 0000000000..34ee200eeb --- /dev/null +++ b/test/compile_errors/stage1/obj/atomic_orderings_of_fence_Acquire_or_stricter.zig @@ -0,0 +1,7 @@ +export fn entry() void { + @fence(.Monotonic); +} + +// atomic orderings of fence Acquire or stricter +// +// tmp.zig:2:12: error: atomic ordering must be Acquire or stricter diff --git a/test/compile_errors/stage1/obj/atomicrmw_with_bool_op_not_.Xchg.zig b/test/compile_errors/stage1/obj/atomicrmw_with_bool_op_not_.Xchg.zig new file mode 100644 index 0000000000..03309737cf --- /dev/null +++ b/test/compile_errors/stage1/obj/atomicrmw_with_bool_op_not_.Xchg.zig @@ -0,0 +1,8 @@ +export fn entry() void { + var x = false; + _ = @atomicRmw(bool, &x, .Add, true, .SeqCst); +} + +// atomicrmw with bool op not .Xchg +// +// tmp.zig:3:30: error: @atomicRmw with bool only allowed with .Xchg diff --git a/test/compile_errors/stage1/obj/atomicrmw_with_enum_op_not_.Xchg.zig b/test/compile_errors/stage1/obj/atomicrmw_with_enum_op_not_.Xchg.zig new file mode 100644 index 0000000000..95e6a7d95d --- /dev/null +++ b/test/compile_errors/stage1/obj/atomicrmw_with_enum_op_not_.Xchg.zig @@ -0,0 +1,14 @@ +export fn entry() void { + const E = enum(u8) { + a, + b, + c, + d, + }; + var x: E = .a; + _ = @atomicRmw(E, &x, .Add, .b, .SeqCst); +} + +// atomicrmw with enum op not .Xchg +// +// tmp.zig:9:27: error: @atomicRmw with enum only allowed with .Xchg diff --git a/test/compile_errors/stage1/obj/atomicrmw_with_float_op_not_.Xchg_.Add_or_.Sub.zig b/test/compile_errors/stage1/obj/atomicrmw_with_float_op_not_.Xchg_.Add_or_.Sub.zig new file mode 100644 index 0000000000..a7359dbf32 --- /dev/null +++ b/test/compile_errors/stage1/obj/atomicrmw_with_float_op_not_.Xchg_.Add_or_.Sub.zig @@ -0,0 +1,8 @@ +export fn entry() void { + var x: f32 = 0; + _ = @atomicRmw(f32, &x, .And, 2, .SeqCst); +} + +// atomicrmw with float op not .Xchg, .Add or .Sub +// +// tmp.zig:3:29: error: @atomicRmw with float only allowed with .Xchg, .Add and .Sub diff --git a/test/compile_errors/stage1/obj/attempt_to_cast_enum_literal_to_error.zig b/test/compile_errors/stage1/obj/attempt_to_cast_enum_literal_to_error.zig new file mode 100644 index 0000000000..fd120af3eb --- /dev/null +++ b/test/compile_errors/stage1/obj/attempt_to_cast_enum_literal_to_error.zig @@ -0,0 +1,9 @@ +export fn entry() void { + switch (error.Hi) { + .Hi => {}, + } +} + +// attempt to cast enum literal to error +// +// tmp.zig:3:9: error: expected type 'error{Hi}', found '@Type(.EnumLiteral)' diff --git a/test/compile_errors/stage1/obj/attempt_to_close_over_comptime_variable_from_outer_scope.zig b/test/compile_errors/stage1/obj/attempt_to_close_over_comptime_variable_from_outer_scope.zig new file mode 100644 index 0000000000..5eb5db3dc8 --- /dev/null +++ b/test/compile_errors/stage1/obj/attempt_to_close_over_comptime_variable_from_outer_scope.zig @@ -0,0 +1,12 @@ +fn SimpleList(comptime L: usize) type { + var T = u8; + return struct { + array: [L]T, + }; +} + +// attempt to close over comptime variable from outer scope +// +// tmp.zig:4:19: error: mutable 'T' not accessible from here +// tmp.zig:2:9: note: declared mutable here +// tmp.zig:3:12: note: crosses namespace boundary here diff --git a/test/compile_errors/stage1/obj/attempt_to_create_17_bit_float_type.zig b/test/compile_errors/stage1/obj/attempt_to_create_17_bit_float_type.zig new file mode 100644 index 0000000000..bdea578696 --- /dev/null +++ b/test/compile_errors/stage1/obj/attempt_to_create_17_bit_float_type.zig @@ -0,0 +1,8 @@ +const builtin = @import("std").builtin; +comptime { + _ = @Type(.{ .Float = .{ .bits = 17 } }); +} + +// attempt to create 17 bit float type +// +// tmp.zig:3:16: error: 17-bit float unsupported diff --git a/test/compile_errors/stage1/obj/attempt_to_negate_a_non-integer_non-float_or_non-vector_type.zig b/test/compile_errors/stage1/obj/attempt_to_negate_a_non-integer_non-float_or_non-vector_type.zig new file mode 100644 index 0000000000..00ee26033d --- /dev/null +++ b/test/compile_errors/stage1/obj/attempt_to_negate_a_non-integer_non-float_or_non-vector_type.zig @@ -0,0 +1,12 @@ +fn foo() anyerror!u32 { + return 1; +} + +export fn entry() void { + const x = -foo(); + _ = x; +} + +// attempt to negate a non-integer, non-float or non-vector type +// +// tmp.zig:6:15: error: negation of type 'anyerror!u32' diff --git a/test/compile_errors/stage1/obj/attempt_to_use_0_bit_type_in_extern_fn.zig b/test/compile_errors/stage1/obj/attempt_to_use_0_bit_type_in_extern_fn.zig new file mode 100644 index 0000000000..d7767e25e9 --- /dev/null +++ b/test/compile_errors/stage1/obj/attempt_to_use_0_bit_type_in_extern_fn.zig @@ -0,0 +1,15 @@ +extern fn foo(ptr: fn(*void) callconv(.C) void) void; + +export fn entry() void { + foo(bar); +} + +fn bar(x: *void) callconv(.C) void { _ = x; } +export fn entry2() void { + bar(&{}); +} + +// attempt to use 0 bit type in extern fn +// +// tmp.zig:1:23: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'C' +// tmp.zig:7:11: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'C' diff --git a/test/compile_errors/stage1/obj/attempted_double_ampersand.zig b/test/compile_errors/stage1/obj/attempted_double_ampersand.zig new file mode 100644 index 0000000000..cc92bc2fae --- /dev/null +++ b/test/compile_errors/stage1/obj/attempted_double_ampersand.zig @@ -0,0 +1,10 @@ +export fn entry(a: bool, b: bool) i32 { + if (a && b) { + return 1234; + } + return 5678; +} + +// attempted `&&` +// +// tmp.zig:2:11: error: ambiguous use of '&&'; use 'and' for logical AND, or change whitespace to ' & &' for bitwise AND diff --git a/test/compile_errors/stage1/obj/attempted_double_pipe_on_boolean_values.zig b/test/compile_errors/stage1/obj/attempted_double_pipe_on_boolean_values.zig new file mode 100644 index 0000000000..8e67b4950d --- /dev/null +++ b/test/compile_errors/stage1/obj/attempted_double_pipe_on_boolean_values.zig @@ -0,0 +1,11 @@ +export fn entry(a: bool, b: bool) i32 { + if (a || b) { + return 1234; + } + return 5678; +} + +// attempted `||` on boolean values +// +// tmp.zig:2:9: error: expected error set type, found 'bool' +// tmp.zig:2:11: note: `||` merges error sets; `or` performs boolean OR diff --git a/test/compile_errors/stage1/obj/attempted_implicit_cast_from_T_to_slice_const_T.zig b/test/compile_errors/stage1/obj/attempted_implicit_cast_from_T_to_slice_const_T.zig new file mode 100644 index 0000000000..4776104928 --- /dev/null +++ b/test/compile_errors/stage1/obj/attempted_implicit_cast_from_T_to_slice_const_T.zig @@ -0,0 +1,8 @@ +export fn entry() void { + const x: [*]const bool = true; + _ = x; +} + +// attempted implicit cast from T to [*]const T +// +// tmp.zig:2:30: error: expected type '[*]const bool', found 'bool' diff --git a/test/compile_errors/stage1/obj/attempted_implicit_cast_from_const_T_to_array_len_1_T.zig b/test/compile_errors/stage1/obj/attempted_implicit_cast_from_const_T_to_array_len_1_T.zig new file mode 100644 index 0000000000..d389c572ca --- /dev/null +++ b/test/compile_errors/stage1/obj/attempted_implicit_cast_from_const_T_to_array_len_1_T.zig @@ -0,0 +1,12 @@ +export fn entry(byte: u8) void { + const w: i32 = 1234; + var x: *const i32 = &w; + var y: *[1]i32 = x; + y[0] += 1; + _ = byte; +} + +// attempted implicit cast from *const T to *[1]T +// +// tmp.zig:4:22: error: expected type '*[1]i32', found '*const i32' +// tmp.zig:4:22: note: cast discards const qualifier diff --git a/test/compile_errors/stage1/obj/attempted_implicit_cast_from_const_T_to_sliceT.zig b/test/compile_errors/stage1/obj/attempted_implicit_cast_from_const_T_to_sliceT.zig new file mode 100644 index 0000000000..70d1cbece2 --- /dev/null +++ b/test/compile_errors/stage1/obj/attempted_implicit_cast_from_const_T_to_sliceT.zig @@ -0,0 +1,9 @@ +export fn entry() void { + const u: u32 = 42; + const x: []u32 = &u; + _ = x; +} + +// attempted implicit cast from *const T to []T +// +// tmp.zig:3:23: error: expected type '[]u32', found '*const u32' diff --git a/test/compile_errors/stage1/obj/bad_alignCast_at_comptime.zig b/test/compile_errors/stage1/obj/bad_alignCast_at_comptime.zig new file mode 100644 index 0000000000..7396dfc4dd --- /dev/null +++ b/test/compile_errors/stage1/obj/bad_alignCast_at_comptime.zig @@ -0,0 +1,9 @@ +comptime { + const ptr = @intToPtr(*align(1) i32, 0x1); + const aligned = @alignCast(4, ptr); + _ = aligned; +} + +// bad @alignCast at comptime +// +// tmp.zig:3:35: error: pointer address 0x1 is not aligned to 4 bytes diff --git a/test/compile_errors/stage1/obj/bad_alignment_in_implicit_cast_from_array_pointer_to_slice.zig b/test/compile_errors/stage1/obj/bad_alignment_in_implicit_cast_from_array_pointer_to_slice.zig new file mode 100644 index 0000000000..ecfc5523d0 --- /dev/null +++ b/test/compile_errors/stage1/obj/bad_alignment_in_implicit_cast_from_array_pointer_to_slice.zig @@ -0,0 +1,9 @@ +export fn a() void { + var x: [10]u8 = undefined; + var y: []align(16) u8 = &x; + _ = y; +} + +// bad alignment in implicit cast from array pointer to slice +// +// tmp.zig:3:30: error: expected type '[]align(16) u8', found '*[10]u8' diff --git a/test/compile_errors/stage1/obj/bad_alignment_type.zig b/test/compile_errors/stage1/obj/bad_alignment_type.zig new file mode 100644 index 0000000000..902ffc79d6 --- /dev/null +++ b/test/compile_errors/stage1/obj/bad_alignment_type.zig @@ -0,0 +1,13 @@ +export fn entry1() void { + var x: []align(true) i32 = undefined; + _ = x; +} +export fn entry2() void { + var x: *align(@as(f64, 12.34)) i32 = undefined; + _ = x; +} + +// bad alignment type +// +// tmp.zig:2:20: error: expected type 'u29', found 'bool' +// tmp.zig:6:19: error: fractional component prevents float value 12.340000 from being casted to type 'u29' diff --git a/test/compile_errors/stage1/obj/bad_identifier_in_function_with_struct_defined_inside_function_which_references_local_const.zig b/test/compile_errors/stage1/obj/bad_identifier_in_function_with_struct_defined_inside_function_which_references_local_const.zig new file mode 100644 index 0000000000..f32301f9ff --- /dev/null +++ b/test/compile_errors/stage1/obj/bad_identifier_in_function_with_struct_defined_inside_function_which_references_local_const.zig @@ -0,0 +1,15 @@ +export fn entry() void { + const BlockKind = u32; + + const Block = struct { + kind: BlockKind, + }; + + bogus; + + _ = Block; +} + +// bad identifier in function with struct defined inside function which references local const +// +// tmp.zig:8:5: error: use of undeclared identifier 'bogus' diff --git a/test/compile_errors/stage1/obj/bad_import.zig b/test/compile_errors/stage1/obj/bad_import.zig new file mode 100644 index 0000000000..f6e93559b2 --- /dev/null +++ b/test/compile_errors/stage1/obj/bad_import.zig @@ -0,0 +1,5 @@ +const bogus = @import("bogus-does-not-exist.zig",); + +// bad import +// +// tmp.zig:1:23: error: unable to load '${DIR}bogus-does-not-exist.zig': FileNotFound diff --git a/test/compile_errors/stage1/obj/bad_usage_of_call.zig b/test/compile_errors/stage1/obj/bad_usage_of_call.zig new file mode 100644 index 0000000000..928c39b5a8 --- /dev/null +++ b/test/compile_errors/stage1/obj/bad_usage_of_call.zig @@ -0,0 +1,28 @@ +export fn entry1() void { + @call(.{}, foo, {}); +} +export fn entry2() void { + comptime @call(.{ .modifier = .never_inline }, foo, .{}); +} +export fn entry3() void { + comptime @call(.{ .modifier = .never_tail }, foo, .{}); +} +export fn entry4() void { + @call(.{ .modifier = .never_inline }, bar, .{}); +} +export fn entry5(c: bool) void { + var baz = if (c) baz1 else baz2; + @call(.{ .modifier = .compile_time }, baz, .{}); +} +fn foo() void {} +fn bar() callconv(.Inline) void {} +fn baz1() void {} +fn baz2() void {} + +// bad usage of @call +// +// tmp.zig:2:21: error: expected tuple or struct, found 'void' +// tmp.zig:5:14: error: unable to perform 'never_inline' call at compile-time +// tmp.zig:8:14: error: unable to perform 'never_tail' call at compile-time +// tmp.zig:11:5: error: no-inline call of inline function +// tmp.zig:15:5: error: the specified modifier requires a comptime-known function diff --git a/test/compile_errors/stage1/obj/bin_and_assign_on_undefined_value.zig b/test/compile_errors/stage1/obj/bin_and_assign_on_undefined_value.zig new file mode 100644 index 0000000000..d9dbdea741 --- /dev/null +++ b/test/compile_errors/stage1/obj/bin_and_assign_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: i64 = undefined; + a &= a; +} + +// bin and assign on undefined value +// +// tmp.zig:3:5: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/bin_and_on_undefined_value.zig b/test/compile_errors/stage1/obj/bin_and_on_undefined_value.zig new file mode 100644 index 0000000000..6775cd56ea --- /dev/null +++ b/test/compile_errors/stage1/obj/bin_and_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: i64 = undefined; + _ = a & a; +} + +// bin and on undefined value +// +// tmp.zig:3:9: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/bin_not_on_undefined_value.zig b/test/compile_errors/stage1/obj/bin_not_on_undefined_value.zig new file mode 100644 index 0000000000..0e543c4f00 --- /dev/null +++ b/test/compile_errors/stage1/obj/bin_not_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: i64 = undefined; + _ = ~a; +} + +// bin not on undefined value +// +// tmp.zig:3:10: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/bin_or_assign_on_undefined_value.zig b/test/compile_errors/stage1/obj/bin_or_assign_on_undefined_value.zig new file mode 100644 index 0000000000..bfbeb7ce3e --- /dev/null +++ b/test/compile_errors/stage1/obj/bin_or_assign_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: i64 = undefined; + a |= a; +} + +// bin or assign on undefined value +// +// tmp.zig:3:5: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/bin_or_on_undefined_value.zig b/test/compile_errors/stage1/obj/bin_or_on_undefined_value.zig new file mode 100644 index 0000000000..7a62ace9dd --- /dev/null +++ b/test/compile_errors/stage1/obj/bin_or_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: i64 = undefined; + _ = a | a; +} + +// bin or on undefined value +// +// tmp.zig:3:9: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/bin_xor_assign_on_undefined_value.zig b/test/compile_errors/stage1/obj/bin_xor_assign_on_undefined_value.zig new file mode 100644 index 0000000000..bea5e1e089 --- /dev/null +++ b/test/compile_errors/stage1/obj/bin_xor_assign_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: i64 = undefined; + a ^= a; +} + +// bin xor assign on undefined value +// +// tmp.zig:3:5: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/bin_xor_on_undefined_value.zig b/test/compile_errors/stage1/obj/bin_xor_on_undefined_value.zig new file mode 100644 index 0000000000..f6ddb24521 --- /dev/null +++ b/test/compile_errors/stage1/obj/bin_xor_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: i64 = undefined; + _ = a ^ a; +} + +// bin xor on undefined value +// +// tmp.zig:3:9: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/binary_not_on_number_literal.zig b/test/compile_errors/stage1/obj/binary_not_on_number_literal.zig new file mode 100644 index 0000000000..12f5953f16 --- /dev/null +++ b/test/compile_errors/stage1/obj/binary_not_on_number_literal.zig @@ -0,0 +1,9 @@ +const TINY_QUANTUM_SHIFT = 4; +const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT; +var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1); + +export fn entry() usize { return @sizeOf(@TypeOf(block_aligned_stuff)); } + +// binary not on number literal +// +// tmp.zig:3:60: error: unable to perform binary not operation on type 'comptime_int' diff --git a/test/compile_errors/stage1/obj/bitCast_same_size_but_bit_count_mismatch.zig b/test/compile_errors/stage1/obj/bitCast_same_size_but_bit_count_mismatch.zig new file mode 100644 index 0000000000..e4945a1194 --- /dev/null +++ b/test/compile_errors/stage1/obj/bitCast_same_size_but_bit_count_mismatch.zig @@ -0,0 +1,8 @@ +export fn entry(byte: u8) void { + var oops = @bitCast(u7, byte); + _ = oops; +} + +// @bitCast same size but bit count mismatch +// +// tmp.zig:2:25: error: destination type 'u7' has 7 bits but source type 'u8' has 8 bits diff --git a/test/compile_errors/stage1/obj/bitCast_to_enum_type.zig b/test/compile_errors/stage1/obj/bitCast_to_enum_type.zig new file mode 100644 index 0000000000..dbb73eba18 --- /dev/null +++ b/test/compile_errors/stage1/obj/bitCast_to_enum_type.zig @@ -0,0 +1,8 @@ +export fn entry() void { + const y = @bitCast(enum(u32) { a, b }, @as(u32, 3)); + _ = y; +} + +// bitCast to enum type +// +// tmp.zig:2:24: error: cannot cast a value of type 'y' diff --git a/test/compile_errors/stage1/obj/bitCast_with_different_sizes_inside_an_expression.zig b/test/compile_errors/stage1/obj/bitCast_with_different_sizes_inside_an_expression.zig new file mode 100644 index 0000000000..bb5c0c5936 --- /dev/null +++ b/test/compile_errors/stage1/obj/bitCast_with_different_sizes_inside_an_expression.zig @@ -0,0 +1,8 @@ +export fn entry() void { + var foo = (@bitCast(u8, @as(f32, 1.0)) == 0xf); + _ = foo; +} + +// @bitCast with different sizes inside an expression +// +// tmp.zig:2:25: error: destination type 'u8' has size 1 but source type 'f32' has size 4 diff --git a/test/compile_errors/stage1/obj/bit_shifting_only_works_on_integer_types.zig b/test/compile_errors/stage1/obj/bit_shifting_only_works_on_integer_types.zig new file mode 100644 index 0000000000..98fa3128aa --- /dev/null +++ b/test/compile_errors/stage1/obj/bit_shifting_only_works_on_integer_types.zig @@ -0,0 +1,8 @@ +export fn entry() void { + const x = &@as(u8, 1) << 10; + _ = x; +} + +// bit shifting only works on integer types +// +// tmp.zig:2:16: error: bit shifting operation expected integer type, found '*const u8' diff --git a/test/compile_errors/stage1/obj/bogus_compile_var.zig b/test/compile_errors/stage1/obj/bogus_compile_var.zig new file mode 100644 index 0000000000..05777b9ecd --- /dev/null +++ b/test/compile_errors/stage1/obj/bogus_compile_var.zig @@ -0,0 +1,6 @@ +const x = @import("builtin").bogus; +export fn entry() usize { return @sizeOf(@TypeOf(x)); } + +// bogus compile var +// +// tmp.zig:1:29: error: container 'builtin' has no member called 'bogus' diff --git a/test/compile_errors/stage1/obj/bogus_method_call_on_slice.zig b/test/compile_errors/stage1/obj/bogus_method_call_on_slice.zig new file mode 100644 index 0000000000..8d34a09817 --- /dev/null +++ b/test/compile_errors/stage1/obj/bogus_method_call_on_slice.zig @@ -0,0 +1,9 @@ +var self = "aoeu"; +fn f(m: []const u8) void { + m.copy(u8, self[0..], m); +} +export fn entry() usize { return @sizeOf(@TypeOf(f)); } + +// bogus method call on slice +// +// tmp.zig:3:6: error: no member named 'copy' in '[]const u8' diff --git a/test/compile_errors/stage1/obj/bool_not_on_undefined_value.zig b/test/compile_errors/stage1/obj/bool_not_on_undefined_value.zig new file mode 100644 index 0000000000..71ea7d5e96 --- /dev/null +++ b/test/compile_errors/stage1/obj/bool_not_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: bool = undefined; + _ = !a; +} + +// bool not on undefined value +// +// tmp.zig:3:10: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/branch_on_undefined_value.zig b/test/compile_errors/stage1/obj/branch_on_undefined_value.zig new file mode 100644 index 0000000000..d02ac22a2a --- /dev/null +++ b/test/compile_errors/stage1/obj/branch_on_undefined_value.zig @@ -0,0 +1,7 @@ +const x = if (undefined) true else false; + +export fn entry() usize { return @sizeOf(@TypeOf(x)); } + +// branch on undefined value +// +// tmp.zig:1:15: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/cImport_with_bogus_include.zig b/test/compile_errors/stage1/obj/cImport_with_bogus_include.zig new file mode 100644 index 0000000000..89627b354f --- /dev/null +++ b/test/compile_errors/stage1/obj/cImport_with_bogus_include.zig @@ -0,0 +1,7 @@ +const c = @cImport(@cInclude("bogus.h")); +export fn entry() usize { return @sizeOf(@TypeOf(c.bogo)); } + +// @cImport with bogus include +// +// tmp.zig:1:11: error: C import failed +// .h:1:10: note: 'bogus.h' file not found diff --git a/test/compile_errors/stage1/obj/call_assigned_to_constant.zig b/test/compile_errors/stage1/obj/call_assigned_to_constant.zig new file mode 100644 index 0000000000..fb2febadb2 --- /dev/null +++ b/test/compile_errors/stage1/obj/call_assigned_to_constant.zig @@ -0,0 +1,22 @@ +const Foo = struct { + x: i32, +}; +fn foo() Foo { + return .{ .x = 42 }; +} +fn bar(val: anytype) Foo { + return .{ .x = val }; +} +export fn entry() void { + const baz: Foo = undefined; + baz = foo(); +} +export fn entry1() void { + const baz: Foo = undefined; + baz = bar(42); +} + +// call assigned to constant +// +// tmp.zig:12:14: error: cannot assign to constant +// tmp.zig:16:14: error: cannot assign to constant diff --git a/test/compile_errors/stage1/obj/calling_a_generic_function_only_known_at_runtime.zig b/test/compile_errors/stage1/obj/calling_a_generic_function_only_known_at_runtime.zig new file mode 100644 index 0000000000..c31b18bb6f --- /dev/null +++ b/test/compile_errors/stage1/obj/calling_a_generic_function_only_known_at_runtime.zig @@ -0,0 +1,12 @@ +var foos = [_]fn(anytype) void { foo1, foo2 }; + +fn foo1(arg: anytype) void {_ = arg;} +fn foo2(arg: anytype) void {_ = arg;} + +pub fn main() !void { + foos[0](true); +} + +// calling a generic function only known at runtime +// +// tmp.zig:7:9: error: calling a generic function requires compile-time known function value diff --git a/test/compile_errors/stage1/obj/calling_function_with_naked_calling_convention.zig b/test/compile_errors/stage1/obj/calling_function_with_naked_calling_convention.zig new file mode 100644 index 0000000000..c99e5b7831 --- /dev/null +++ b/test/compile_errors/stage1/obj/calling_function_with_naked_calling_convention.zig @@ -0,0 +1,9 @@ +export fn entry() void { + foo(); +} +fn foo() callconv(.Naked) void { } + +// calling function with naked calling convention +// +// tmp.zig:2:5: error: unable to call function with naked calling convention +// tmp.zig:4:1: note: declared here diff --git a/test/compile_errors/stage1/obj/calling_var_args_extern_function_passing_array_instead_of_pointer.zig b/test/compile_errors/stage1/obj/calling_var_args_extern_function_passing_array_instead_of_pointer.zig new file mode 100644 index 0000000000..e3cc4425db --- /dev/null +++ b/test/compile_errors/stage1/obj/calling_var_args_extern_function_passing_array_instead_of_pointer.zig @@ -0,0 +1,8 @@ +export fn entry() void { + foo("hello".*,); +} +pub extern fn foo(format: *const u8, ...) void; + +// calling var args extern function, passing array instead of pointer +// +// tmp.zig:2:16: error: expected type '*const u8', found '[5:0]u8' diff --git a/test/compile_errors/stage1/obj/cannot_break_out_of_defer_expression.zig b/test/compile_errors/stage1/obj/cannot_break_out_of_defer_expression.zig new file mode 100644 index 0000000000..002a7717d3 --- /dev/null +++ b/test/compile_errors/stage1/obj/cannot_break_out_of_defer_expression.zig @@ -0,0 +1,11 @@ +export fn foo() void { + while (true) { + defer { + break; + } + } +} + +// cannot break out of defer expression +// +// tmp.zig:4:13: error: cannot break out of defer expression diff --git a/test/compile_errors/stage1/obj/cannot_continue_out_of_defer_expression.zig b/test/compile_errors/stage1/obj/cannot_continue_out_of_defer_expression.zig new file mode 100644 index 0000000000..8adb7eafd6 --- /dev/null +++ b/test/compile_errors/stage1/obj/cannot_continue_out_of_defer_expression.zig @@ -0,0 +1,11 @@ +export fn foo() void { + while (true) { + defer { + continue; + } + } +} + +// cannot continue out of defer expression +// +// tmp.zig:4:13: error: cannot continue out of defer expression diff --git a/test/compile_errors/stage1/obj/capture_group_on_switch_prong_with_incompatible_payload_types.zig b/test/compile_errors/stage1/obj/capture_group_on_switch_prong_with_incompatible_payload_types.zig new file mode 100644 index 0000000000..8a4c94f503 --- /dev/null +++ b/test/compile_errors/stage1/obj/capture_group_on_switch_prong_with_incompatible_payload_types.zig @@ -0,0 +1,19 @@ +const Union = union(enum) { + A: usize, + B: isize, +}; +comptime { + var u = Union{ .A = 8 }; + switch (u) { + .A, .B => |e| { + _ = e; + unreachable; + }, + } +} + +// capture group on switch prong with incompatible payload types +// +// tmp.zig:8:20: error: capture group with incompatible types +// tmp.zig:8:9: note: type 'usize' here +// tmp.zig:8:13: note: type 'isize' here diff --git a/test/compile_errors/stage1/obj/cast_enum_literal_to_enum_but_it_doesnt_match.zig b/test/compile_errors/stage1/obj/cast_enum_literal_to_enum_but_it_doesnt_match.zig new file mode 100644 index 0000000000..10717ff392 --- /dev/null +++ b/test/compile_errors/stage1/obj/cast_enum_literal_to_enum_but_it_doesnt_match.zig @@ -0,0 +1,13 @@ +const Foo = enum { + a, + b, +}; +export fn entry() void { + const x: Foo = .c; + _ = x; +} + +// cast enum literal to enum but it doesn't match +// +// tmp.zig:6:20: error: enum 'Foo' has no field named 'c' +// tmp.zig:1:13: note: 'Foo' declared here diff --git a/test/compile_errors/stage1/obj/cast_error_union_of_global_error_set_to_error_union_of_smaller_error_set.zig b/test/compile_errors/stage1/obj/cast_error_union_of_global_error_set_to_error_union_of_smaller_error_set.zig new file mode 100644 index 0000000000..fbb68c30c8 --- /dev/null +++ b/test/compile_errors/stage1/obj/cast_error_union_of_global_error_set_to_error_union_of_smaller_error_set.zig @@ -0,0 +1,14 @@ +const SmallErrorSet = error{A}; +export fn entry() void { + var x: SmallErrorSet!i32 = foo(); + _ = x; +} +fn foo() anyerror!i32 { + return error.B; +} + +// cast error union of global error set to error union of smaller error set +// +// tmp.zig:3:35: error: expected type 'SmallErrorSet!i32', found 'anyerror!i32' +// tmp.zig:3:35: note: error set 'anyerror' cannot cast into error set 'SmallErrorSet' +// tmp.zig:3:35: note: cannot cast global error set into smaller set diff --git a/test/compile_errors/stage1/obj/cast_global_error_set_to_error_set.zig b/test/compile_errors/stage1/obj/cast_global_error_set_to_error_set.zig new file mode 100644 index 0000000000..f37ffce229 --- /dev/null +++ b/test/compile_errors/stage1/obj/cast_global_error_set_to_error_set.zig @@ -0,0 +1,13 @@ +const SmallErrorSet = error{A}; +export fn entry() void { + var x: SmallErrorSet = foo(); + _ = x; +} +fn foo() anyerror { + return error.B; +} + +// cast global error set to error set +// +// tmp.zig:3:31: error: expected type 'SmallErrorSet', found 'anyerror' +// tmp.zig:3:31: note: cannot cast global error set into smaller set diff --git a/test/compile_errors/stage1/obj/cast_negative_integer_literal_to_usize.zig b/test/compile_errors/stage1/obj/cast_negative_integer_literal_to_usize.zig new file mode 100644 index 0000000000..37e42c062c --- /dev/null +++ b/test/compile_errors/stage1/obj/cast_negative_integer_literal_to_usize.zig @@ -0,0 +1,8 @@ +export fn entry() void { + const x = @as(usize, -10); + _ = x; +} + +// cast negative integer literal to usize +// +// tmp.zig:2:26: error: cannot cast negative value -10 to unsigned integer type 'usize' diff --git a/test/compile_errors/stage1/obj/cast_negative_value_to_unsigned_integer.zig b/test/compile_errors/stage1/obj/cast_negative_value_to_unsigned_integer.zig new file mode 100644 index 0000000000..e740d406f6 --- /dev/null +++ b/test/compile_errors/stage1/obj/cast_negative_value_to_unsigned_integer.zig @@ -0,0 +1,15 @@ +comptime { + const value: i32 = -1; + const unsigned = @intCast(u32, value); + _ = unsigned; +} +export fn entry1() void { + const value: i32 = -1; + const unsigned: u32 = value; + _ = unsigned; +} + +// cast negative value to unsigned integer +// +// tmp.zig:3:22: error: attempt to cast negative value to unsigned integer +// tmp.zig:8:27: error: cannot cast negative value -1 to unsigned integer type 'u32' diff --git a/test/compile_errors/stage1/obj/cast_unreachable.zig b/test/compile_errors/stage1/obj/cast_unreachable.zig new file mode 100644 index 0000000000..94fa121770 --- /dev/null +++ b/test/compile_errors/stage1/obj/cast_unreachable.zig @@ -0,0 +1,9 @@ +fn f() i32 { + return @as(i32, return 1); +} +export fn entry() void { _ = f(); } + +// cast unreachable +// +// tmp.zig:2:12: error: unreachable code +// tmp.zig:2:21: note: control flow is diverted here diff --git a/test/compile_errors/stage1/obj/casting_bit_offset_pointer_to_regular_pointer.zig b/test/compile_errors/stage1/obj/casting_bit_offset_pointer_to_regular_pointer.zig new file mode 100644 index 0000000000..9b6c5ea0e6 --- /dev/null +++ b/test/compile_errors/stage1/obj/casting_bit_offset_pointer_to_regular_pointer.zig @@ -0,0 +1,19 @@ +const BitField = packed struct { + a: u3, + b: u3, + c: u2, +}; + +fn foo(bit_field: *const BitField) u3 { + return bar(&bit_field.b); +} + +fn bar(x: *const u3) u3 { + return x.*; +} + +export fn entry() usize { return @sizeOf(@TypeOf(foo)); } + +// casting bit offset pointer to regular pointer +// +// tmp.zig:8:26: error: expected type '*const u3', found '*align(:3:1) const u3' diff --git a/test/compile_errors/stage1/obj/catch_on_undefined_value.zig b/test/compile_errors/stage1/obj/catch_on_undefined_value.zig new file mode 100644 index 0000000000..9d22d07219 --- /dev/null +++ b/test/compile_errors/stage1/obj/catch_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: anyerror!bool = undefined; + _ = a catch false; +} + +// catch on undefined value +// +// tmp.zig:3:11: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/chained_comparison_operators.zig b/test/compile_errors/stage1/obj/chained_comparison_operators.zig new file mode 100644 index 0000000000..89e1ea1e75 --- /dev/null +++ b/test/compile_errors/stage1/obj/chained_comparison_operators.zig @@ -0,0 +1,7 @@ +export fn a(value: u32) bool { + return 1 < value < 1000; +} + +// chained comparison operators +// +// tmp.zig:2:22: error: comparison operators cannot be chained diff --git a/test/compile_errors/stage1/obj/cmpxchg_with_float.zig b/test/compile_errors/stage1/obj/cmpxchg_with_float.zig new file mode 100644 index 0000000000..8926ffc36b --- /dev/null +++ b/test/compile_errors/stage1/obj/cmpxchg_with_float.zig @@ -0,0 +1,8 @@ +export fn entry() void { + var x: f32 = 0; + _ = @cmpxchgWeak(f32, &x, 1, 2, .SeqCst, .SeqCst); +} + +// cmpxchg with float +// +// tmp.zig:3:22: error: expected bool, integer, enum or pointer type, found 'f32' diff --git a/test/compile_errors/stage1/obj/colliding_invalid_top_level_functions.zig b/test/compile_errors/stage1/obj/colliding_invalid_top_level_functions.zig new file mode 100644 index 0000000000..f4e5d24c46 --- /dev/null +++ b/test/compile_errors/stage1/obj/colliding_invalid_top_level_functions.zig @@ -0,0 +1,8 @@ +fn func() bogus {} +fn func() bogus {} +export fn entry() usize { return @sizeOf(@TypeOf(func)); } + +// colliding invalid top level functions +// +// tmp.zig:2:1: error: redeclaration of 'func' +// tmp.zig:1:1: note: other declaration here diff --git a/test/compile_errors/stage1/obj/compare_optional_to_non-optional_with_invalid_types.zig b/test/compile_errors/stage1/obj/compare_optional_to_non-optional_with_invalid_types.zig new file mode 100644 index 0000000000..8713cf4501 --- /dev/null +++ b/test/compile_errors/stage1/obj/compare_optional_to_non-optional_with_invalid_types.zig @@ -0,0 +1,33 @@ +export fn inconsistentChildType() void { + var x: ?i32 = undefined; + const y: comptime_int = 10; + _ = (x == y); +} + +export fn optionalToOptional() void { + var x: ?i32 = undefined; + var y: ?i32 = undefined; + _ = (x == y); +} + +export fn optionalVector() void { + var x: ?@Vector(10, i32) = undefined; + var y: @Vector(10, i32) = undefined; + _ = (x == y); +} + +export fn invalidChildType() void { + var x: ?[3]i32 = undefined; + var y: [3]i32 = undefined; + _ = (x == y); +} + +// compare optional to non-optional with invalid types +// +// :4:12: error: cannot compare types '?i32' and 'comptime_int' +// :4:12: note: optional child type 'i32' must be the same as non-optional type 'comptime_int' +// :10:12: error: cannot compare types '?i32' and '?i32' +// :10:12: note: optional to optional comparison is only supported for optional pointer types +// :16:12: error: TODO add comparison of optional vector +// :22:12: error: cannot compare types '?[3]i32' and '[3]i32' +// :22:12: note: operator not supported for type '[3]i32' diff --git a/test/compile_errors/stage1/obj/comparing_a_non-optional_pointer_against_null.zig b/test/compile_errors/stage1/obj/comparing_a_non-optional_pointer_against_null.zig new file mode 100644 index 0000000000..69a5120135 --- /dev/null +++ b/test/compile_errors/stage1/obj/comparing_a_non-optional_pointer_against_null.zig @@ -0,0 +1,8 @@ +export fn entry() void { + var x: i32 = 1; + _ = &x == null; +} + +// comparing a non-optional pointer against null +// +// tmp.zig:3:12: error: comparison of '*i32' with null diff --git a/test/compile_errors/stage1/obj/comparing_against_undefined_produces_undefined_value.zig b/test/compile_errors/stage1/obj/comparing_against_undefined_produces_undefined_value.zig new file mode 100644 index 0000000000..c329f51ef7 --- /dev/null +++ b/test/compile_errors/stage1/obj/comparing_against_undefined_produces_undefined_value.zig @@ -0,0 +1,7 @@ +export fn entry() void { + if (2 == undefined) {} +} + +// comparing against undefined produces undefined value +// +// tmp.zig:2:11: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/comparison_operators_with_undefined_value.zig b/test/compile_errors/stage1/obj/comparison_operators_with_undefined_value.zig new file mode 100644 index 0000000000..6021382fd4 --- /dev/null +++ b/test/compile_errors/stage1/obj/comparison_operators_with_undefined_value.zig @@ -0,0 +1,45 @@ +// operator == +comptime { + var a: i64 = undefined; + var x: i32 = 0; + if (a == a) x += 1; +} +// operator != +comptime { + var a: i64 = undefined; + var x: i32 = 0; + if (a != a) x += 1; +} +// operator > +comptime { + var a: i64 = undefined; + var x: i32 = 0; + if (a > a) x += 1; +} +// operator < +comptime { + var a: i64 = undefined; + var x: i32 = 0; + if (a < a) x += 1; +} +// operator >= +comptime { + var a: i64 = undefined; + var x: i32 = 0; + if (a >= a) x += 1; +} +// operator <= +comptime { + var a: i64 = undefined; + var x: i32 = 0; + if (a <= a) x += 1; +} + +// comparison operators with undefined value +// +// tmp.zig:5:11: error: use of undefined value here causes undefined behavior +// tmp.zig:11:11: error: use of undefined value here causes undefined behavior +// tmp.zig:17:11: error: use of undefined value here causes undefined behavior +// tmp.zig:23:11: error: use of undefined value here causes undefined behavior +// tmp.zig:29:11: error: use of undefined value here causes undefined behavior +// tmp.zig:35:11: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/comparison_with_error_union_and_error_value.zig b/test/compile_errors/stage1/obj/comparison_with_error_union_and_error_value.zig new file mode 100644 index 0000000000..260ccc6f01 --- /dev/null +++ b/test/compile_errors/stage1/obj/comparison_with_error_union_and_error_value.zig @@ -0,0 +1,8 @@ +export fn entry() void { + var number_or_error: anyerror!i32 = error.SomethingAwful; + _ = number_or_error == error.SomethingAwful; +} + +// comparison with error union and error value +// +// tmp.zig:3:25: error: operator not allowed for type 'anyerror!i32' diff --git a/test/compile_errors/stage1/obj/compile-time_division_by_zero.zig b/test/compile_errors/stage1/obj/compile-time_division_by_zero.zig new file mode 100644 index 0000000000..578dbc7b4a --- /dev/null +++ b/test/compile_errors/stage1/obj/compile-time_division_by_zero.zig @@ -0,0 +1,10 @@ +comptime { + const a: i32 = 1; + const b: i32 = 0; + const c = a / b; + _ = c; +} + +// compile-time division by zero +// +// tmp.zig:4:17: error: division by zero diff --git a/test/compile_errors/stage1/obj/compile-time_remainder_division_by_zero.zig b/test/compile_errors/stage1/obj/compile-time_remainder_division_by_zero.zig new file mode 100644 index 0000000000..015d229110 --- /dev/null +++ b/test/compile_errors/stage1/obj/compile-time_remainder_division_by_zero.zig @@ -0,0 +1,10 @@ +comptime { + const a: i32 = 1; + const b: i32 = 0; + const c = a % b; + _ = c; +} + +// compile-time remainder division by zero +// +// tmp.zig:4:17: error: division by zero diff --git a/test/compile_errors/stage1/obj/compileError_shows_traceback_of_references_that_caused_it.zig b/test/compile_errors/stage1/obj/compileError_shows_traceback_of_references_that_caused_it.zig new file mode 100644 index 0000000000..4273741ad2 --- /dev/null +++ b/test/compile_errors/stage1/obj/compileError_shows_traceback_of_references_that_caused_it.zig @@ -0,0 +1,12 @@ +const foo = @compileError("aoeu",); + +const bar = baz + foo; +const baz = 1; + +export fn entry() i32 { + return bar; +} + +// @compileError shows traceback of references that caused it +// +// tmp.zig:1:13: error: aoeu diff --git a/test/compile_errors/stage1/obj/compileLog_of_tagged_enum_doesnt_crash_the_compiler.zig b/test/compile_errors/stage1/obj/compileLog_of_tagged_enum_doesnt_crash_the_compiler.zig new file mode 100644 index 0000000000..0770b3b6a4 --- /dev/null +++ b/test/compile_errors/stage1/obj/compileLog_of_tagged_enum_doesnt_crash_the_compiler.zig @@ -0,0 +1,15 @@ +const Bar = union(enum(u32)) { + X: i32 = 1 +}; + +fn testCompileLog(x: Bar) void { + @compileLog(x); +} + +pub fn main () void { + comptime testCompileLog(Bar{.X = 123}); +} + +// compileLog of tagged enum doesn't crash the compiler +// +// tmp.zig:6:5: error: found compile log statement diff --git a/test/compile_errors/stage1/obj/compile_error_in_struct_init_expression.zig b/test/compile_errors/stage1/obj/compile_error_in_struct_init_expression.zig new file mode 100644 index 0000000000..6215c9ad76 --- /dev/null +++ b/test/compile_errors/stage1/obj/compile_error_in_struct_init_expression.zig @@ -0,0 +1,14 @@ +const Foo = struct { + a: i32 = crap, + b: i32, +}; +export fn entry() void { + var x = Foo{ + .b = 5, + }; + _ = x; +} + +// compile error in struct init expression +// +// tmp.zig:2:14: error: use of undeclared identifier 'crap' diff --git a/test/compile_errors/stage1/obj/compile_error_when_evaluating_return_type_of_inferred_error_set.zig b/test/compile_errors/stage1/obj/compile_error_when_evaluating_return_type_of_inferred_error_set.zig new file mode 100644 index 0000000000..44d5b6a389 --- /dev/null +++ b/test/compile_errors/stage1/obj/compile_error_when_evaluating_return_type_of_inferred_error_set.zig @@ -0,0 +1,12 @@ +const Car = struct { + foo: *SymbolThatDoesNotExist, + pub fn init() !Car {} +}; +export fn entry() void { + const car = Car.init(); + _ = car; +} + +// compile error when evaluating return type of inferred error set +// +// tmp.zig:2:11: error: use of undeclared identifier 'SymbolThatDoesNotExist' diff --git a/test/compile_errors/stage1/obj/compile_log.zig b/test/compile_errors/stage1/obj/compile_log.zig new file mode 100644 index 0000000000..ef1cba4502 --- /dev/null +++ b/test/compile_errors/stage1/obj/compile_log.zig @@ -0,0 +1,14 @@ +export fn foo() void { + comptime bar(12, "hi",); +} +fn bar(a: i32, b: []const u8) void { + @compileLog("begin",); + @compileLog("a", a, "b", b); + @compileLog("end",); +} + +// compile log +// +// tmp.zig:5:5: error: found compile log statement +// tmp.zig:6:5: error: found compile log statement +// tmp.zig:7:5: error: found compile log statement diff --git a/test/compile_errors/stage1/obj/compile_log_a_pointer_to_an_opaque_value.zig b/test/compile_errors/stage1/obj/compile_log_a_pointer_to_an_opaque_value.zig new file mode 100644 index 0000000000..15b7825a91 --- /dev/null +++ b/test/compile_errors/stage1/obj/compile_log_a_pointer_to_an_opaque_value.zig @@ -0,0 +1,7 @@ +export fn entry() void { + @compileLog(@ptrCast(*const anyopaque, &entry)); +} + +// compile log a pointer to an opaque value +// +// tmp.zig:2:5: error: found compile log statement diff --git a/test/compile_errors/stage1/obj/compile_log_statement_inside_function_which_must_be_comptime_evaluated.zig b/test/compile_errors/stage1/obj/compile_log_statement_inside_function_which_must_be_comptime_evaluated.zig new file mode 100644 index 0000000000..f848ed7c7c --- /dev/null +++ b/test/compile_errors/stage1/obj/compile_log_statement_inside_function_which_must_be_comptime_evaluated.zig @@ -0,0 +1,12 @@ +fn Foo(comptime T: type) type { + @compileLog(@typeName(T)); + return T; +} +export fn entry() void { + _ = Foo(i32); + _ = @typeName(Foo(i32)); +} + +// compile log statement inside function which must be comptime evaluated +// +// tmp.zig:2:5: error: found compile log statement diff --git a/test/compile_errors/stage1/obj/compile_log_statement_warning_deduplication_in_generic_fn.zig b/test/compile_errors/stage1/obj/compile_log_statement_warning_deduplication_in_generic_fn.zig new file mode 100644 index 0000000000..05ac76724c --- /dev/null +++ b/test/compile_errors/stage1/obj/compile_log_statement_warning_deduplication_in_generic_fn.zig @@ -0,0 +1,12 @@ +export fn entry() void { + inner(1); + inner(2); +} +fn inner(comptime n: usize) void { + comptime var i = 0; + inline while (i < n) : (i += 1) { @compileLog("!@#$"); } +} + +// compile log statement warning deduplication in generic fn +// +// tmp.zig:7:39: error: found compile log statement diff --git a/test/compile_errors/stage1/obj/compile_time_division_by_zero.zig b/test/compile_errors/stage1/obj/compile_time_division_by_zero.zig new file mode 100644 index 0000000000..17187c47bf --- /dev/null +++ b/test/compile_errors/stage1/obj/compile_time_division_by_zero.zig @@ -0,0 +1,10 @@ +const y = foo(0); +fn foo(x: u32) u32 { + return 1 / x; +} + +export fn entry() usize { return @sizeOf(@TypeOf(y)); } + +// compile time division by zero +// +// tmp.zig:3:14: error: division by zero diff --git a/test/compile_errors/stage1/obj/comptime_cast_enum_to_union_but_field_has_payload.zig b/test/compile_errors/stage1/obj/comptime_cast_enum_to_union_but_field_has_payload.zig new file mode 100644 index 0000000000..36a2079a01 --- /dev/null +++ b/test/compile_errors/stage1/obj/comptime_cast_enum_to_union_but_field_has_payload.zig @@ -0,0 +1,15 @@ +const Letter = enum { A, B, C }; +const Value = union(Letter) { + A: i32, + B, + C, +}; +export fn entry() void { + var x: Value = Letter.A; + _ = x; +} + +// comptime cast enum to union but field has payload +// +// tmp.zig:8:26: error: cast to union 'Value' must initialize 'i32' field 'A' +// tmp.zig:3:5: note: field 'A' declared here diff --git a/test/compile_errors/stage1/obj/comptime_continue_inside_runtime_catch.zig b/test/compile_errors/stage1/obj/comptime_continue_inside_runtime_catch.zig new file mode 100644 index 0000000000..18c78c858c --- /dev/null +++ b/test/compile_errors/stage1/obj/comptime_continue_inside_runtime_catch.zig @@ -0,0 +1,14 @@ +export fn entry() void { + const ints = [_]u8{ 1, 2 }; + inline for (ints) |_| { + bad() catch continue; + } +} +fn bad() !void { + return error.Bad; +} + +// comptime continue inside runtime catch +// +// tmp.zig:4:21: error: comptime control flow inside runtime block +// tmp.zig:4:15: note: runtime block created here diff --git a/test/compile_errors/stage1/obj/comptime_continue_inside_runtime_if_bool.zig b/test/compile_errors/stage1/obj/comptime_continue_inside_runtime_if_bool.zig new file mode 100644 index 0000000000..f6ec1b98b1 --- /dev/null +++ b/test/compile_errors/stage1/obj/comptime_continue_inside_runtime_if_bool.zig @@ -0,0 +1,13 @@ +export fn entry() void { + var p: usize = undefined; + comptime var q = true; + inline while (q) { + if (p == 11) continue; + q = false; + } +} + +// comptime continue inside runtime if bool +// +// tmp.zig:5:22: error: comptime control flow inside runtime block +// tmp.zig:5:9: note: runtime block created here diff --git a/test/compile_errors/stage1/obj/comptime_continue_inside_runtime_if_error.zig b/test/compile_errors/stage1/obj/comptime_continue_inside_runtime_if_error.zig new file mode 100644 index 0000000000..556a8769a5 --- /dev/null +++ b/test/compile_errors/stage1/obj/comptime_continue_inside_runtime_if_error.zig @@ -0,0 +1,13 @@ +export fn entry() void { + var p: anyerror!i32 = undefined; + comptime var q = true; + inline while (q) { + if (p) |_| continue else |_| {} + q = false; + } +} + +// comptime continue inside runtime if error +// +// tmp.zig:5:20: error: comptime control flow inside runtime block +// tmp.zig:5:9: note: runtime block created here diff --git a/test/compile_errors/stage1/obj/comptime_continue_inside_runtime_if_optional.zig b/test/compile_errors/stage1/obj/comptime_continue_inside_runtime_if_optional.zig new file mode 100644 index 0000000000..4f35398a2b --- /dev/null +++ b/test/compile_errors/stage1/obj/comptime_continue_inside_runtime_if_optional.zig @@ -0,0 +1,13 @@ +export fn entry() void { + var p: ?i32 = undefined; + comptime var q = true; + inline while (q) { + if (p) |_| continue; + q = false; + } +} + +// comptime continue inside runtime if optional +// +// tmp.zig:5:20: error: comptime control flow inside runtime block +// tmp.zig:5:9: note: runtime block created here diff --git a/test/compile_errors/stage1/obj/comptime_continue_inside_runtime_switch.zig b/test/compile_errors/stage1/obj/comptime_continue_inside_runtime_switch.zig new file mode 100644 index 0000000000..259cbd602e --- /dev/null +++ b/test/compile_errors/stage1/obj/comptime_continue_inside_runtime_switch.zig @@ -0,0 +1,16 @@ +export fn entry() void { + var p: i32 = undefined; + comptime var q = true; + inline while (q) { + switch (p) { + 11 => continue, + else => {}, + } + q = false; + } +} + +// comptime continue inside runtime switch +// +// tmp.zig:6:19: error: comptime control flow inside runtime block +// tmp.zig:5:9: note: runtime block created here diff --git a/test/compile_errors/stage1/obj/comptime_continue_inside_runtime_while_bool.zig b/test/compile_errors/stage1/obj/comptime_continue_inside_runtime_while_bool.zig new file mode 100644 index 0000000000..5d86394815 --- /dev/null +++ b/test/compile_errors/stage1/obj/comptime_continue_inside_runtime_while_bool.zig @@ -0,0 +1,13 @@ +export fn entry() void { + var p: usize = undefined; + comptime var q = true; + outer: inline while (q) { + while (p == 11) continue :outer; + q = false; + } +} + +// comptime continue inside runtime while bool +// +// tmp.zig:5:25: error: comptime control flow inside runtime block +// tmp.zig:5:9: note: runtime block created here diff --git a/test/compile_errors/stage1/obj/comptime_continue_inside_runtime_while_error.zig b/test/compile_errors/stage1/obj/comptime_continue_inside_runtime_while_error.zig new file mode 100644 index 0000000000..0ba49cb3ca --- /dev/null +++ b/test/compile_errors/stage1/obj/comptime_continue_inside_runtime_while_error.zig @@ -0,0 +1,15 @@ +export fn entry() void { + var p: anyerror!usize = undefined; + comptime var q = true; + outer: inline while (q) { + while (p) |_| { + continue :outer; + } else |_| {} + q = false; + } +} + +// comptime continue inside runtime while error +// +// tmp.zig:6:13: error: comptime control flow inside runtime block +// tmp.zig:5:9: note: runtime block created here diff --git a/test/compile_errors/stage1/obj/comptime_continue_inside_runtime_while_optional.zig b/test/compile_errors/stage1/obj/comptime_continue_inside_runtime_while_optional.zig new file mode 100644 index 0000000000..b2cfd2f69d --- /dev/null +++ b/test/compile_errors/stage1/obj/comptime_continue_inside_runtime_while_optional.zig @@ -0,0 +1,13 @@ +export fn entry() void { + var p: ?usize = undefined; + comptime var q = true; + outer: inline while (q) { + while (p) |_| continue :outer; + q = false; + } +} + +// comptime continue inside runtime while optional +// +// tmp.zig:5:23: error: comptime control flow inside runtime block +// tmp.zig:5:9: note: runtime block created here diff --git a/test/compile_errors/stage1/obj/comptime_float_in_asm_input.zig b/test/compile_errors/stage1/obj/comptime_float_in_asm_input.zig new file mode 100644 index 0000000000..c2333586b4 --- /dev/null +++ b/test/compile_errors/stage1/obj/comptime_float_in_asm_input.zig @@ -0,0 +1,7 @@ +export fn foo() void { + asm volatile ("" : : [bar]"r"(3.17) : ""); +} + +// comptime_float in asm input +// +// tmp.zig:2:35: error: expected sized integer or sized float, found comptime_float diff --git a/test/compile_errors/stage1/obj/comptime_implicit_cast_f64_to_f32.zig b/test/compile_errors/stage1/obj/comptime_implicit_cast_f64_to_f32.zig new file mode 100644 index 0000000000..f98c45a348 --- /dev/null +++ b/test/compile_errors/stage1/obj/comptime_implicit_cast_f64_to_f32.zig @@ -0,0 +1,9 @@ +export fn entry() void { + const x: f64 = 16777217; + const y: f32 = x; + _ = y; +} + +// comptime implicit cast f64 to f32 +// +// tmp.zig:3:20: error: cast of value 16777217.000000 to type 'f32' loses information diff --git a/test/compile_errors/stage1/obj/comptime_int_in_asm_input.zig b/test/compile_errors/stage1/obj/comptime_int_in_asm_input.zig new file mode 100644 index 0000000000..5a587e5a77 --- /dev/null +++ b/test/compile_errors/stage1/obj/comptime_int_in_asm_input.zig @@ -0,0 +1,7 @@ +export fn foo() void { + asm volatile ("" : : [bar]"r"(3) : ""); +} + +// comptime_int in asm input +// +// tmp.zig:2:35: error: expected sized integer or sized float, found comptime_int diff --git a/test/compile_errors/stage1/obj/comptime_ptrcast_of_zero-sized_type.zig b/test/compile_errors/stage1/obj/comptime_ptrcast_of_zero-sized_type.zig new file mode 100644 index 0000000000..1d3f91fe91 --- /dev/null +++ b/test/compile_errors/stage1/obj/comptime_ptrcast_of_zero-sized_type.zig @@ -0,0 +1,10 @@ +fn foo() void { + const node: struct {} = undefined; + const vla_ptr = @ptrCast([*]const u8, &node); + _ = vla_ptr; +} +comptime { foo(); } + +// comptime ptrcast of zero-sized type +// +// tmp.zig:3:21: error: '*const struct:2:17' and '[*]const u8' do not have the same in-memory representation diff --git a/test/compile_errors/stage1/obj/comptime_slice-sentinel_does_not_match_memory_at_target_index_terminated.zig b/test/compile_errors/stage1/obj/comptime_slice-sentinel_does_not_match_memory_at_target_index_terminated.zig new file mode 100644 index 0000000000..622e0cf76b --- /dev/null +++ b/test/compile_errors/stage1/obj/comptime_slice-sentinel_does_not_match_memory_at_target_index_terminated.zig @@ -0,0 +1,65 @@ +export fn foo_array() void { + comptime { + var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + const slice = target[0..3 :0]; + _ = slice; + } +} +export fn foo_ptr_array() void { + comptime { + var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + var target = &buf; + const slice = target[0..3 :0]; + _ = slice; + } +} +export fn foo_vector_ConstPtrSpecialBaseArray() void { + comptime { + var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + var target: [*]u8 = &buf; + const slice = target[0..3 :0]; + _ = slice; + } +} +export fn foo_vector_ConstPtrSpecialRef() void { + comptime { + var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + var target: [*]u8 = @ptrCast([*]u8, &buf); + const slice = target[0..3 :0]; + _ = slice; + } +} +export fn foo_cvector_ConstPtrSpecialBaseArray() void { + comptime { + var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + var target: [*c]u8 = &buf; + const slice = target[0..3 :0]; + _ = slice; + } +} +export fn foo_cvector_ConstPtrSpecialRef() void { + comptime { + var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + var target: [*c]u8 = @ptrCast([*c]u8, &buf); + const slice = target[0..3 :0]; + _ = slice; + } +} +export fn foo_slice() void { + comptime { + var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + var target: []u8 = &buf; + const slice = target[0..3 :0]; + _ = slice; + } +} + +// comptime slice-sentinel does not match memory at target index (terminated) +// +// :4:29: error: slice-sentinel does not match memory at target index +// :12:29: error: slice-sentinel does not match memory at target index +// :20:29: error: slice-sentinel does not match memory at target index +// :28:29: error: slice-sentinel does not match memory at target index +// :36:29: error: slice-sentinel does not match memory at target index +// :44:29: error: slice-sentinel does not match memory at target index +// :52:29: error: slice-sentinel does not match memory at target index diff --git a/test/compile_errors/stage1/obj/comptime_slice-sentinel_does_not_match_memory_at_target_index_unterminated.zig b/test/compile_errors/stage1/obj/comptime_slice-sentinel_does_not_match_memory_at_target_index_unterminated.zig new file mode 100644 index 0000000000..e9451cf9aa --- /dev/null +++ b/test/compile_errors/stage1/obj/comptime_slice-sentinel_does_not_match_memory_at_target_index_unterminated.zig @@ -0,0 +1,65 @@ +export fn foo_array() void { + comptime { + var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + const slice = target[0..3 :0]; + _ = slice; + } +} +export fn foo_ptr_array() void { + comptime { + var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + var target = &buf; + const slice = target[0..3 :0]; + _ = slice; + } +} +export fn foo_vector_ConstPtrSpecialBaseArray() void { + comptime { + var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + var target: [*]u8 = &buf; + const slice = target[0..3 :0]; + _ = slice; + } +} +export fn foo_vector_ConstPtrSpecialRef() void { + comptime { + var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + var target: [*]u8 = @ptrCast([*]u8, &buf); + const slice = target[0..3 :0]; + _ = slice; + } +} +export fn foo_cvector_ConstPtrSpecialBaseArray() void { + comptime { + var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + var target: [*c]u8 = &buf; + const slice = target[0..3 :0]; + _ = slice; + } +} +export fn foo_cvector_ConstPtrSpecialRef() void { + comptime { + var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + var target: [*c]u8 = @ptrCast([*c]u8, &buf); + const slice = target[0..3 :0]; + _ = slice; + } +} +export fn foo_slice() void { + comptime { + var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + var target: []u8 = &buf; + const slice = target[0..3 :0]; + _ = slice; + } +} + +// comptime slice-sentinel does not match memory at target index (unterminated) +// +// :4:29: error: slice-sentinel does not match memory at target index +// :12:29: error: slice-sentinel does not match memory at target index +// :20:29: error: slice-sentinel does not match memory at target index +// :28:29: error: slice-sentinel does not match memory at target index +// :36:29: error: slice-sentinel does not match memory at target index +// :44:29: error: slice-sentinel does not match memory at target index +// :52:29: error: slice-sentinel does not match memory at target index diff --git a/test/compile_errors/stage1/obj/comptime_slice-sentinel_does_not_match_target-sentinel.zig b/test/compile_errors/stage1/obj/comptime_slice-sentinel_does_not_match_target-sentinel.zig new file mode 100644 index 0000000000..597a493705 --- /dev/null +++ b/test/compile_errors/stage1/obj/comptime_slice-sentinel_does_not_match_target-sentinel.zig @@ -0,0 +1,65 @@ +export fn foo_array() void { + comptime { + var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + const slice = target[0..14 :255]; + _ = slice; + } +} +export fn foo_ptr_array() void { + comptime { + var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + var target = &buf; + const slice = target[0..14 :255]; + _ = slice; + } +} +export fn foo_vector_ConstPtrSpecialBaseArray() void { + comptime { + var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + var target: [*]u8 = &buf; + const slice = target[0..14 :255]; + _ = slice; + } +} +export fn foo_vector_ConstPtrSpecialRef() void { + comptime { + var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + var target: [*]u8 = @ptrCast([*]u8, &buf); + const slice = target[0..14 :255]; + _ = slice; + } +} +export fn foo_cvector_ConstPtrSpecialBaseArray() void { + comptime { + var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + var target: [*c]u8 = &buf; + const slice = target[0..14 :255]; + _ = slice; + } +} +export fn foo_cvector_ConstPtrSpecialRef() void { + comptime { + var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + var target: [*c]u8 = @ptrCast([*c]u8, &buf); + const slice = target[0..14 :255]; + _ = slice; + } +} +export fn foo_slice() void { + comptime { + var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + var target: []u8 = &buf; + const slice = target[0..14 :255]; + _ = slice; + } +} + +// comptime slice-sentinel does not match target-sentinel +// +// :4:29: error: slice-sentinel does not match target-sentinel +// :12:29: error: slice-sentinel does not match target-sentinel +// :20:29: error: slice-sentinel does not match target-sentinel +// :28:29: error: slice-sentinel does not match target-sentinel +// :36:29: error: slice-sentinel does not match target-sentinel +// :44:29: error: slice-sentinel does not match target-sentinel +// :52:29: error: slice-sentinel does not match target-sentinel diff --git a/test/compile_errors/stage1/obj/comptime_slice-sentinel_is_out_of_bounds_terminated.zig b/test/compile_errors/stage1/obj/comptime_slice-sentinel_is_out_of_bounds_terminated.zig new file mode 100644 index 0000000000..d5fc64ea84 --- /dev/null +++ b/test/compile_errors/stage1/obj/comptime_slice-sentinel_is_out_of_bounds_terminated.zig @@ -0,0 +1,65 @@ +export fn foo_array() void { + comptime { + var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + const slice = target[0..15 :1]; + _ = slice; + } +} +export fn foo_ptr_array() void { + comptime { + var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + var target = &buf; + const slice = target[0..15 :0]; + _ = slice; + } +} +export fn foo_vector_ConstPtrSpecialBaseArray() void { + comptime { + var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + var target: [*]u8 = &buf; + const slice = target[0..15 :0]; + _ = slice; + } +} +export fn foo_vector_ConstPtrSpecialRef() void { + comptime { + var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + var target: [*]u8 = @ptrCast([*]u8, &buf); + const slice = target[0..15 :0]; + _ = slice; + } +} +export fn foo_cvector_ConstPtrSpecialBaseArray() void { + comptime { + var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + var target: [*c]u8 = &buf; + const slice = target[0..15 :0]; + _ = slice; + } +} +export fn foo_cvector_ConstPtrSpecialRef() void { + comptime { + var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + var target: [*c]u8 = @ptrCast([*c]u8, &buf); + const slice = target[0..15 :0]; + _ = slice; + } +} +export fn foo_slice() void { + comptime { + var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + var target: []u8 = &buf; + const slice = target[0..15 :0]; + _ = slice; + } +} + +// comptime slice-sentinel is out of bounds (terminated) +// +// :4:29: error: out of bounds slice +// :12:29: error: out of bounds slice +// :20:29: error: out of bounds slice +// :28:29: error: out of bounds slice +// :36:29: error: out of bounds slice +// :44:29: error: out of bounds slice +// :52:29: error: out of bounds slice diff --git a/test/compile_errors/stage1/obj/comptime_slice-sentinel_is_out_of_bounds_unterminated.zig b/test/compile_errors/stage1/obj/comptime_slice-sentinel_is_out_of_bounds_unterminated.zig new file mode 100644 index 0000000000..05a499ca8a --- /dev/null +++ b/test/compile_errors/stage1/obj/comptime_slice-sentinel_is_out_of_bounds_unterminated.zig @@ -0,0 +1,65 @@ +export fn foo_array() void { + comptime { + var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + const slice = target[0..14 :0]; + _ = slice; + } +} +export fn foo_ptr_array() void { + comptime { + var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + var target = &buf; + const slice = target[0..14 :0]; + _ = slice; + } +} +export fn foo_vector_ConstPtrSpecialBaseArray() void { + comptime { + var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + var target: [*]u8 = &buf; + const slice = target[0..14 :0]; + _ = slice; + } +} +export fn foo_vector_ConstPtrSpecialRef() void { + comptime { + var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + var target: [*]u8 = @ptrCast([*]u8, &buf); + const slice = target[0..14 :0]; + _ = slice; + } +} +export fn foo_cvector_ConstPtrSpecialBaseArray() void { + comptime { + var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + var target: [*c]u8 = &buf; + const slice = target[0..14 :0]; + _ = slice; + } +} +export fn foo_cvector_ConstPtrSpecialRef() void { + comptime { + var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + var target: [*c]u8 = @ptrCast([*c]u8, &buf); + const slice = target[0..14 :0]; + _ = slice; + } +} +export fn foo_slice() void { + comptime { + var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10; + var target: []u8 = &buf; + const slice = target[0..14 :0]; + _ = slice; + } +} + +// comptime slice-sentinel is out of bounds (unterminated) +// +// :4:29: error: slice-sentinel is out of bounds +// :12:29: error: slice-sentinel is out of bounds +// :20:29: error: slice-sentinel is out of bounds +// :28:29: error: slice-sentinel is out of bounds +// :36:29: error: slice-sentinel is out of bounds +// :44:29: error: slice-sentinel is out of bounds +// :52:29: error: slice-sentinel is out of bounds diff --git a/test/compile_errors/stage1/obj/comptime_slice_of_an_undefined_slice.zig b/test/compile_errors/stage1/obj/comptime_slice_of_an_undefined_slice.zig new file mode 100644 index 0000000000..b56feddc02 --- /dev/null +++ b/test/compile_errors/stage1/obj/comptime_slice_of_an_undefined_slice.zig @@ -0,0 +1,9 @@ +comptime { + var a: []u8 = undefined; + var b = a[0..10]; + _ = b; +} + +// comptime slice of an undefined slice +// +// tmp.zig:3:14: error: slice of undefined diff --git a/test/compile_errors/stage1/obj/comptime_slice_of_undefined_pointer_non-zero_len.zig b/test/compile_errors/stage1/obj/comptime_slice_of_undefined_pointer_non-zero_len.zig new file mode 100644 index 0000000000..bcddd1d866 --- /dev/null +++ b/test/compile_errors/stage1/obj/comptime_slice_of_undefined_pointer_non-zero_len.zig @@ -0,0 +1,8 @@ +export fn entry() void { + const slice = @as([*]i32, undefined)[0..1]; + _ = slice; +} + +// comptime slice of undefined pointer non-zero len +// +// tmp.zig:2:41: error: non-zero length slice of undefined pointer diff --git a/test/compile_errors/stage1/obj/comptime_struct_field_no_init_value.zig b/test/compile_errors/stage1/obj/comptime_struct_field_no_init_value.zig new file mode 100644 index 0000000000..c3de76a794 --- /dev/null +++ b/test/compile_errors/stage1/obj/comptime_struct_field_no_init_value.zig @@ -0,0 +1,11 @@ +const Foo = struct { + comptime b: i32, +}; +export fn entry() void { + var f: Foo = undefined; + _ = f; +} + +// comptime struct field, no init value +// +// tmp.zig:2:5: error: comptime field without default initialization value diff --git a/test/compile_errors/stage1/obj/const_frame_cast_to_anyframe.zig b/test/compile_errors/stage1/obj/const_frame_cast_to_anyframe.zig new file mode 100644 index 0000000000..1e6cdba507 --- /dev/null +++ b/test/compile_errors/stage1/obj/const_frame_cast_to_anyframe.zig @@ -0,0 +1,17 @@ +export fn a() void { + const f = async func(); + resume f; +} +export fn b() void { + const f = async func(); + var x: anyframe = &f; + _ = x; +} +fn func() void { + suspend {} +} + +// const frame cast to anyframe +// +// tmp.zig:3:12: error: expected type 'anyframe', found '*const @Frame(func)' +// tmp.zig:7:24: error: expected type 'anyframe', found '*const @Frame(func)' diff --git a/test/compile_errors/stage1/obj/const_is_a_statement_not_an_expression.zig b/test/compile_errors/stage1/obj/const_is_a_statement_not_an_expression.zig new file mode 100644 index 0000000000..4396407dd1 --- /dev/null +++ b/test/compile_errors/stage1/obj/const_is_a_statement_not_an_expression.zig @@ -0,0 +1,7 @@ +export fn f() void { + (const a = 0); +} + +// const is a statement, not an expression +// +// tmp.zig:2:6: error: expected expression, found 'const' diff --git a/test/compile_errors/stage1/obj/constant_inside_comptime_function_has_compile_error.zig b/test/compile_errors/stage1/obj/constant_inside_comptime_function_has_compile_error.zig new file mode 100644 index 0000000000..8eabcfdeaa --- /dev/null +++ b/test/compile_errors/stage1/obj/constant_inside_comptime_function_has_compile_error.zig @@ -0,0 +1,19 @@ +const ContextAllocator = MemoryPool(usize); + +pub fn MemoryPool(comptime T: type) type { + const free_list_t = @compileError("aoeu",); + + return struct { + free_list: free_list_t, + }; +} + +export fn entry() void { + var allocator: ContextAllocator = undefined; +} + +// constant inside comptime function has compile error +// +// tmp.zig:4:5: error: unreachable code +// tmp.zig:4:25: note: control flow is diverted here +// tmp.zig:12:9: error: unused local variable diff --git a/test/compile_errors/stage1/obj/container_init_with_non-type.zig b/test/compile_errors/stage1/obj/container_init_with_non-type.zig new file mode 100644 index 0000000000..6464555df5 --- /dev/null +++ b/test/compile_errors/stage1/obj/container_init_with_non-type.zig @@ -0,0 +1,8 @@ +const zero: i32 = 0; +const a = zero{1}; + +export fn entry() usize { return @sizeOf(@TypeOf(a)); } + +// container init with non-type +// +// tmp.zig:2:11: error: expected type 'type', found 'i32' diff --git a/test/compile_errors/stage1/obj/control_flow_uses_comptime_var_at_runtime.zig b/test/compile_errors/stage1/obj/control_flow_uses_comptime_var_at_runtime.zig new file mode 100644 index 0000000000..ee2c0234c3 --- /dev/null +++ b/test/compile_errors/stage1/obj/control_flow_uses_comptime_var_at_runtime.zig @@ -0,0 +1,13 @@ +export fn foo() void { + comptime var i = 0; + while (i < 5) : (i += 1) { + bar(); + } +} + +fn bar() void { } + +// control flow uses comptime var at runtime +// +// tmp.zig:3:5: error: control flow attempts to use compile-time variable at runtime +// tmp.zig:3:24: note: compile-time variable assigned here diff --git a/test/compile_errors/stage1/obj/control_reaches_end_of_non-void_function.zig b/test/compile_errors/stage1/obj/control_reaches_end_of_non-void_function.zig new file mode 100644 index 0000000000..13d2876823 --- /dev/null +++ b/test/compile_errors/stage1/obj/control_reaches_end_of_non-void_function.zig @@ -0,0 +1,6 @@ +fn a() i32 {} +export fn entry() void { _ = a(); } + +// control reaches end of non-void function +// +// tmp.zig:1:12: error: expected type 'i32', found 'void' diff --git a/test/compile_errors/stage1/obj/declaration_between_fields.zig b/test/compile_errors/stage1/obj/declaration_between_fields.zig new file mode 100644 index 0000000000..6e6b60f2e4 --- /dev/null +++ b/test/compile_errors/stage1/obj/declaration_between_fields.zig @@ -0,0 +1,22 @@ +const S = struct { + const foo = 2; + const bar = 2; + const baz = 2; + a: struct { + a: u32, + b: u32, + }, + const foo1 = 2; + const bar1 = 2; + const baz1 = 2; + b: usize, +}; +comptime { + _ = S; +} + +// declaration between fields +// +// tmp.zig:9:5: error: declarations are not allowed between container fields +// tmp.zig:5:5: note: field before declarations here +// tmp.zig:12:5: note: field after declarations here diff --git a/test/compile_errors/stage1/obj/declaration_with_same_name_as_primitive_must_use_special_syntax.zig b/test/compile_errors/stage1/obj/declaration_with_same_name_as_primitive_must_use_special_syntax.zig new file mode 100644 index 0000000000..c10f397da4 --- /dev/null +++ b/test/compile_errors/stage1/obj/declaration_with_same_name_as_primitive_must_use_special_syntax.zig @@ -0,0 +1,10 @@ +const u8 = u16; +export fn entry() void { + const a: u8 = 300; + _ = a; +} + +// declaration with same name as primitive must use special syntax +// +// tmp.zig:1:7: error: name shadows primitive 'u8' +// tmp.zig:1:7: note: consider using @"u8" to disambiguate diff --git a/test/compile_errors/stage1/obj/deduplicate_undeclared_identifier.zig b/test/compile_errors/stage1/obj/deduplicate_undeclared_identifier.zig new file mode 100644 index 0000000000..1c9d6c3d31 --- /dev/null +++ b/test/compile_errors/stage1/obj/deduplicate_undeclared_identifier.zig @@ -0,0 +1,10 @@ +export fn a() void { + x += 1; +} +export fn b() void { + x += 1; +} + +// deduplicate undeclared identifier +// +// tmp.zig:2:5: error: use of undeclared identifier 'x' diff --git a/test/compile_errors/stage1/obj/deref_on_undefined_value.zig b/test/compile_errors/stage1/obj/deref_on_undefined_value.zig new file mode 100644 index 0000000000..607f6ea5e0 --- /dev/null +++ b/test/compile_errors/stage1/obj/deref_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: *u8 = undefined; + _ = a.*; +} + +// deref on undefined value +// +// tmp.zig:3:9: error: attempt to dereference undefined value diff --git a/test/compile_errors/stage1/obj/deref_slice_and_get_len_field.zig b/test/compile_errors/stage1/obj/deref_slice_and_get_len_field.zig new file mode 100644 index 0000000000..2fa5ff6133 --- /dev/null +++ b/test/compile_errors/stage1/obj/deref_slice_and_get_len_field.zig @@ -0,0 +1,8 @@ +export fn entry() void { + var a: []u8 = undefined; + _ = a.*.len; +} + +// deref slice and get len field +// +// tmp.zig:3:10: error: attempt to dereference non-pointer type '[]u8' diff --git a/test/compile_errors/stage1/obj/dereference_an_array.zig b/test/compile_errors/stage1/obj/dereference_an_array.zig new file mode 100644 index 0000000000..713c655784 --- /dev/null +++ b/test/compile_errors/stage1/obj/dereference_an_array.zig @@ -0,0 +1,12 @@ +var s_buffer: [10]u8 = undefined; +pub fn pass(in: []u8) []u8 { + var out = &s_buffer; + out.*.* = in[0]; + return out.*[0..1]; +} + +export fn entry() usize { return @sizeOf(@TypeOf(pass)); } + +// dereference an array +// +// tmp.zig:4:10: error: attempt to dereference non-pointer type '[10]u8' diff --git a/test/compile_errors/stage1/obj/dereference_unknown_length_pointer.zig b/test/compile_errors/stage1/obj/dereference_unknown_length_pointer.zig new file mode 100644 index 0000000000..22ad181fb2 --- /dev/null +++ b/test/compile_errors/stage1/obj/dereference_unknown_length_pointer.zig @@ -0,0 +1,7 @@ +export fn entry(x: [*]i32) i32 { + return x.*; +} + +// dereference unknown length pointer +// +// tmp.zig:2:13: error: index syntax required for unknown-length pointer type '[*]i32' diff --git a/test/compile_errors/stage1/obj/direct_struct_loop.zig b/test/compile_errors/stage1/obj/direct_struct_loop.zig new file mode 100644 index 0000000000..25b3c724c3 --- /dev/null +++ b/test/compile_errors/stage1/obj/direct_struct_loop.zig @@ -0,0 +1,6 @@ +const A = struct { a : A, }; +export fn entry() usize { return @sizeOf(A); } + +// direct struct loop +// +// tmp.zig:1:11: error: struct 'A' depends on itself diff --git a/test/compile_errors/stage1/obj/directly_embedding_opaque_type_in_struct_and_union.zig b/test/compile_errors/stage1/obj/directly_embedding_opaque_type_in_struct_and_union.zig new file mode 100644 index 0000000000..811fc00f50 --- /dev/null +++ b/test/compile_errors/stage1/obj/directly_embedding_opaque_type_in_struct_and_union.zig @@ -0,0 +1,27 @@ +const O = opaque {}; +const Foo = struct { + o: O, +}; +const Bar = union { + One: i32, + Two: O, +}; +export fn a() void { + var foo: Foo = undefined; + _ = foo; +} +export fn b() void { + var bar: Bar = undefined; + _ = bar; +} +export fn c() void { + var baz: *opaque {} = undefined; + const qux = .{baz.*}; + _ = qux; +} + +// directly embedding opaque type in struct and union +// +// tmp.zig:3:5: error: opaque types have unknown size and therefore cannot be directly embedded in structs +// tmp.zig:7:5: error: opaque types have unknown size and therefore cannot be directly embedded in unions +// tmp.zig:19:22: error: opaque types have unknown size and therefore cannot be directly embedded in structs diff --git a/test/compile_errors/stage1/obj/disallow_coercion_from_non-null-terminated_pointer_to_null-terminated_pointer.zig b/test/compile_errors/stage1/obj/disallow_coercion_from_non-null-terminated_pointer_to_null-terminated_pointer.zig new file mode 100644 index 0000000000..a8467ddc87 --- /dev/null +++ b/test/compile_errors/stage1/obj/disallow_coercion_from_non-null-terminated_pointer_to_null-terminated_pointer.zig @@ -0,0 +1,10 @@ +extern fn puts(s: [*:0]const u8) c_int; +pub fn main() void { + const no_zero_array = [_]u8{'h', 'e', 'l', 'l', 'o'}; + const no_zero_ptr: [*]const u8 = &no_zero_array; + _ = puts(no_zero_ptr); +} + +// disallow coercion from non-null-terminated pointer to null-terminated pointer +// +// tmp.zig:5:14: error: expected type '[*:0]const u8', found '[*]const u8' diff --git a/test/compile_errors/stage1/obj/discarding_error_value.zig b/test/compile_errors/stage1/obj/discarding_error_value.zig new file mode 100644 index 0000000000..966a43a47c --- /dev/null +++ b/test/compile_errors/stage1/obj/discarding_error_value.zig @@ -0,0 +1,10 @@ +export fn entry() void { + _ = foo(); +} +fn foo() !void { + return error.OutOfMemory; +} + +// discarding error value +// +// tmp.zig:2:12: error: error is discarded. consider using `try`, `catch`, or `if` diff --git a/test/compile_errors/stage1/obj/div_assign_on_undefined_value.zig b/test/compile_errors/stage1/obj/div_assign_on_undefined_value.zig new file mode 100644 index 0000000000..40c31649fb --- /dev/null +++ b/test/compile_errors/stage1/obj/div_assign_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: i64 = undefined; + a /= a; +} + +// div assign on undefined value +// +// tmp.zig:3:5: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/div_on_undefined_value.zig b/test/compile_errors/stage1/obj/div_on_undefined_value.zig new file mode 100644 index 0000000000..17af3fa221 --- /dev/null +++ b/test/compile_errors/stage1/obj/div_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: i64 = undefined; + _ = a / a; +} + +// div on undefined value +// +// tmp.zig:3:9: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/division_by_zero.zig b/test/compile_errors/stage1/obj/division_by_zero.zig new file mode 100644 index 0000000000..178d1d935b --- /dev/null +++ b/test/compile_errors/stage1/obj/division_by_zero.zig @@ -0,0 +1,16 @@ +const lit_int_x = 1 / 0; +const lit_float_x = 1.0 / 0.0; +const int_x = @as(u32, 1) / @as(u32, 0); +const float_x = @as(f32, 1.0) / @as(f32, 0.0); + +export fn entry1() usize { return @sizeOf(@TypeOf(lit_int_x)); } +export fn entry2() usize { return @sizeOf(@TypeOf(lit_float_x)); } +export fn entry3() usize { return @sizeOf(@TypeOf(int_x)); } +export fn entry4() usize { return @sizeOf(@TypeOf(float_x)); } + +// division by zero +// +// tmp.zig:1:21: error: division by zero +// tmp.zig:2:25: error: division by zero +// tmp.zig:3:27: error: division by zero +// tmp.zig:4:31: error: division by zero diff --git a/test/compile_errors/stage1/obj/dont_implicit_cast_double_pointer_to_anyopaque.zig b/test/compile_errors/stage1/obj/dont_implicit_cast_double_pointer_to_anyopaque.zig new file mode 100644 index 0000000000..5894103f1c --- /dev/null +++ b/test/compile_errors/stage1/obj/dont_implicit_cast_double_pointer_to_anyopaque.zig @@ -0,0 +1,11 @@ +export fn entry() void { + var a: u32 = 1; + var ptr: *align(@alignOf(u32)) anyopaque = &a; + var b: *u32 = @ptrCast(*u32, ptr); + var ptr2: *anyopaque = &b; + _ = ptr2; +} + +// don't implicit cast double pointer to *anyopaque +// +// tmp.zig:5:29: error: expected type '*anyopaque', found '**u32' diff --git a/test/compile_errors/stage1/obj/double_optional_on_main_return_value.zig b/test/compile_errors/stage1/obj/double_optional_on_main_return_value.zig new file mode 100644 index 0000000000..c85706bc87 --- /dev/null +++ b/test/compile_errors/stage1/obj/double_optional_on_main_return_value.zig @@ -0,0 +1,6 @@ +pub fn main() ??void { +} + +// double ?? on main return value +// +// error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8' diff --git a/test/compile_errors/stage1/obj/duplicate_boolean_switch_value.zig b/test/compile_errors/stage1/obj/duplicate_boolean_switch_value.zig new file mode 100644 index 0000000000..8c496d5e19 --- /dev/null +++ b/test/compile_errors/stage1/obj/duplicate_boolean_switch_value.zig @@ -0,0 +1,21 @@ +comptime { + const x = switch (true) { + true => false, + false => true, + true => false, + }; + _ = x; +} +comptime { + const x = switch (true) { + false => true, + true => false, + false => true, + }; + _ = x; +} + +// duplicate boolean switch value +// +// tmp.zig:5:9: error: duplicate switch value +// tmp.zig:13:9: error: duplicate switch value diff --git a/test/compile_errors/stage1/obj/duplicate_enum_field.zig b/test/compile_errors/stage1/obj/duplicate_enum_field.zig new file mode 100644 index 0000000000..2aee3cc2dc --- /dev/null +++ b/test/compile_errors/stage1/obj/duplicate_enum_field.zig @@ -0,0 +1,14 @@ +const Foo = enum { + Bar, + Bar, +}; + +export fn entry() void { + const a: Foo = undefined; + _ = a; +} + +// duplicate enum field +// +// tmp.zig:3:5: error: duplicate enum field: 'Bar' +// tmp.zig:2:5: note: other field here diff --git a/test/compile_errors/stage1/obj/duplicate_error_in_switch.zig b/test/compile_errors/stage1/obj/duplicate_error_in_switch.zig new file mode 100644 index 0000000000..bca59056c3 --- /dev/null +++ b/test/compile_errors/stage1/obj/duplicate_error_in_switch.zig @@ -0,0 +1,20 @@ +export fn entry() void { + foo(452) catch |err| switch (err) { + error.Foo => {}, + error.Bar => {}, + error.Foo => {}, + else => {}, + }; +} +fn foo(x: i32) !void { + switch (x) { + 0 ... 10 => return error.Foo, + 11 ... 20 => return error.Bar, + else => {}, + } +} + +// duplicate error in switch +// +// tmp.zig:5:14: error: duplicate switch value: '@typeInfo(@typeInfo(@TypeOf(foo)).Fn.return_type.?).ErrorUnion.error_set.Foo' +// tmp.zig:3:14: note: other value here diff --git a/test/compile_errors/stage1/obj/duplicate_error_value_in_error_set.zig b/test/compile_errors/stage1/obj/duplicate_error_value_in_error_set.zig new file mode 100644 index 0000000000..90457562b2 --- /dev/null +++ b/test/compile_errors/stage1/obj/duplicate_error_value_in_error_set.zig @@ -0,0 +1,13 @@ +const Foo = error { + Bar, + Bar, +}; +export fn entry() void { + const a: Foo = undefined; + _ = a; +} + +// duplicate error value in error set +// +// tmp.zig:3:5: error: duplicate error set field 'Bar' +// tmp.zig:2:5: note: previous declaration here diff --git a/test/compile_errors/stage1/obj/duplicate_field_in_struct_value_expression.zig b/test/compile_errors/stage1/obj/duplicate_field_in_struct_value_expression.zig new file mode 100644 index 0000000000..6df71430d9 --- /dev/null +++ b/test/compile_errors/stage1/obj/duplicate_field_in_struct_value_expression.zig @@ -0,0 +1,18 @@ +const A = struct { + x : i32, + y : i32, + z : i32, +}; +export fn f() void { + const a = A { + .z = 1, + .y = 2, + .x = 3, + .z = 4, + }; + _ = a; +} + +// duplicate field in struct value expression +// +// tmp.zig:11:9: error: duplicate field diff --git a/test/compile_errors/stage1/obj/duplicate_struct_field.zig b/test/compile_errors/stage1/obj/duplicate_struct_field.zig new file mode 100644 index 0000000000..d1fd05aacc --- /dev/null +++ b/test/compile_errors/stage1/obj/duplicate_struct_field.zig @@ -0,0 +1,13 @@ +const Foo = struct { + Bar: i32, + Bar: usize, +}; +export fn entry() void { + const a: Foo = undefined; + _ = a; +} + +// duplicate struct field +// +// tmp.zig:3:5: error: duplicate struct field: 'Bar' +// tmp.zig:2:5: note: other field here diff --git a/test/compile_errors/stage1/obj/duplicate_union_field.zig b/test/compile_errors/stage1/obj/duplicate_union_field.zig new file mode 100644 index 0000000000..a8bff106c6 --- /dev/null +++ b/test/compile_errors/stage1/obj/duplicate_union_field.zig @@ -0,0 +1,13 @@ +const Foo = union { + Bar: i32, + Bar: usize, +}; +export fn entry() void { + const a: Foo = undefined; + _ = a; +} + +// duplicate union field +// +// tmp.zig:3:5: error: duplicate union field: 'Bar' +// tmp.zig:2:5: note: other field here diff --git a/test/compile_errors/stage1/obj/embedFile_with_bogus_file.zig b/test/compile_errors/stage1/obj/embedFile_with_bogus_file.zig new file mode 100644 index 0000000000..e50e091909 --- /dev/null +++ b/test/compile_errors/stage1/obj/embedFile_with_bogus_file.zig @@ -0,0 +1,7 @@ +const resource = @embedFile("bogus.txt",); + +export fn entry() usize { return @sizeOf(@TypeOf(resource)); } + +// @embedFile with bogus file +// +// tmp.zig:1:29: error: unable to find ' diff --git a/test/compile_errors/stage1/obj/empty_for_loop_body.zig b/test/compile_errors/stage1/obj/empty_for_loop_body.zig new file mode 100644 index 0000000000..6e042f71e4 --- /dev/null +++ b/test/compile_errors/stage1/obj/empty_for_loop_body.zig @@ -0,0 +1,7 @@ +export fn a() void { + for(undefined) |x|; +} + +// empty for loop body +// +// tmp.zig:2:23: error: expected block or assignment, found ';' diff --git a/test/compile_errors/stage1/obj/empty_if_body.zig b/test/compile_errors/stage1/obj/empty_if_body.zig new file mode 100644 index 0000000000..a81973396f --- /dev/null +++ b/test/compile_errors/stage1/obj/empty_if_body.zig @@ -0,0 +1,7 @@ +export fn a() void { + if(true); +} + +// empty if body +// +// tmp.zig:2:13: error: expected block or assignment, found ';' diff --git a/test/compile_errors/stage1/obj/empty_switch_on_an_integer.zig b/test/compile_errors/stage1/obj/empty_switch_on_an_integer.zig new file mode 100644 index 0000000000..eb0bdbab19 --- /dev/null +++ b/test/compile_errors/stage1/obj/empty_switch_on_an_integer.zig @@ -0,0 +1,8 @@ +export fn entry() void { + var x: u32 = 0; + switch(x) {} +} + +// empty switch on an integer +// +// tmp.zig:3:5: error: switch must handle all possibilities diff --git a/test/compile_errors/stage1/obj/empty_while_loop_body.zig b/test/compile_errors/stage1/obj/empty_while_loop_body.zig new file mode 100644 index 0000000000..3a186f1a2b --- /dev/null +++ b/test/compile_errors/stage1/obj/empty_while_loop_body.zig @@ -0,0 +1,7 @@ +export fn a() void { + while(true); +} + +// empty while loop body +// +// tmp.zig:2:16: error: expected block or assignment, found ';' diff --git a/test/compile_errors/stage1/obj/endless_loop_in_function_evaluation.zig b/test/compile_errors/stage1/obj/endless_loop_in_function_evaluation.zig new file mode 100644 index 0000000000..fa422ba588 --- /dev/null +++ b/test/compile_errors/stage1/obj/endless_loop_in_function_evaluation.zig @@ -0,0 +1,10 @@ +const seventh_fib_number = fibonacci(7); +fn fibonacci(x: i32) i32 { + return fibonacci(x - 1) + fibonacci(x - 2); +} + +export fn entry() usize { return @sizeOf(@TypeOf(seventh_fib_number)); } + +// endless loop in function evaluation +// +// tmp.zig:3:21: error: evaluation exceeded 1000 backwards branches diff --git a/test/compile_errors/stage1/obj/enum_field_value_references_enum.zig b/test/compile_errors/stage1/obj/enum_field_value_references_enum.zig new file mode 100644 index 0000000000..02dcfc1f9d --- /dev/null +++ b/test/compile_errors/stage1/obj/enum_field_value_references_enum.zig @@ -0,0 +1,13 @@ +pub const Foo = enum(c_int) { + A = Foo.B, + C = D, +}; +export fn entry() void { + var s: Foo = Foo.E; + _ = s; +} +const D = 1; + +// enum field value references enum +// +// tmp.zig:1:17: error: enum 'Foo' depends on itself diff --git a/test/compile_errors/stage1/obj/enum_in_field_count_range_but_not_matching_tag.zig b/test/compile_errors/stage1/obj/enum_in_field_count_range_but_not_matching_tag.zig new file mode 100644 index 0000000000..dc90c467df --- /dev/null +++ b/test/compile_errors/stage1/obj/enum_in_field_count_range_but_not_matching_tag.zig @@ -0,0 +1,13 @@ +const Foo = enum(u32) { + A = 10, + B = 11, +}; +export fn entry() void { + var x = @intToEnum(Foo, 0); + _ = x; +} + +// enum in field count range but not matching tag +// +// tmp.zig:6:13: error: enum 'Foo' has no tag matching integer value 0 +// tmp.zig:1:13: note: 'Foo' declared here diff --git a/test/compile_errors/stage1/obj/enum_value_already_taken.zig b/test/compile_errors/stage1/obj/enum_value_already_taken.zig new file mode 100644 index 0000000000..9939553c41 --- /dev/null +++ b/test/compile_errors/stage1/obj/enum_value_already_taken.zig @@ -0,0 +1,16 @@ +const MultipleChoice = enum(u32) { + A = 20, + B = 40, + C = 60, + D = 1000, + E = 60, +}; +export fn entry() void { + var x = MultipleChoice.C; + _ = x; +} + +// enum value already taken +// +// tmp.zig:6:5: error: enum tag value 60 already taken +// tmp.zig:4:5: note: other occurrence here diff --git a/test/compile_errors/stage1/obj/enum_with_0_fields.zig b/test/compile_errors/stage1/obj/enum_with_0_fields.zig new file mode 100644 index 0000000000..10559d15b3 --- /dev/null +++ b/test/compile_errors/stage1/obj/enum_with_0_fields.zig @@ -0,0 +1,5 @@ +const Foo = enum {}; + +// enum with 0 fields +// +// tmp.zig:1:13: error: enum declarations must have at least one tag diff --git a/test/compile_errors/stage1/obj/enum_with_declarations_unavailable_for_reify_type.zig b/test/compile_errors/stage1/obj/enum_with_declarations_unavailable_for_reify_type.zig new file mode 100644 index 0000000000..4a27caab3d --- /dev/null +++ b/test/compile_errors/stage1/obj/enum_with_declarations_unavailable_for_reify_type.zig @@ -0,0 +1,7 @@ +export fn entry() void { + _ = @Type(@typeInfo(enum { foo, const bar = 1; })); +} + +// enum with declarations unavailable for @Type +// +// tmp.zig:2:15: error: Type.Enum.decls must be empty for @Type diff --git a/test/compile_errors/stage1/obj/error_equality_but_sets_have_no_common_members.zig b/test/compile_errors/stage1/obj/error_equality_but_sets_have_no_common_members.zig new file mode 100644 index 0000000000..433f6d50e3 --- /dev/null +++ b/test/compile_errors/stage1/obj/error_equality_but_sets_have_no_common_members.zig @@ -0,0 +1,14 @@ +const Set1 = error{A, C}; +const Set2 = error{B, D}; +export fn entry() void { + foo(Set1.A); +} +fn foo(x: Set1) void { + if (x == Set2.B) { + + } +} + +// error equality but sets have no common members +// +// tmp.zig:7:11: error: error sets 'Set1' and 'Set2' have no common errors diff --git a/test/compile_errors/stage1/obj/error_not_handled_in_switch.zig b/test/compile_errors/stage1/obj/error_not_handled_in_switch.zig new file mode 100644 index 0000000000..a69c538eac --- /dev/null +++ b/test/compile_errors/stage1/obj/error_not_handled_in_switch.zig @@ -0,0 +1,18 @@ +export fn entry() void { + foo(452) catch |err| switch (err) { + error.Foo => {}, + }; +} +fn foo(x: i32) !void { + switch (x) { + 0 ... 10 => return error.Foo, + 11 ... 20 => return error.Bar, + 21 ... 30 => return error.Baz, + else => {}, + } +} + +// error not handled in switch +// +// tmp.zig:2:26: error: error.Baz not handled in switch +// tmp.zig:2:26: error: error.Bar not handled in switch diff --git a/test/compile_errors/stage1/obj/error_note_for_function_parameter_incompatibility.zig b/test/compile_errors/stage1/obj/error_note_for_function_parameter_incompatibility.zig new file mode 100644 index 0000000000..5014d01a3d --- /dev/null +++ b/test/compile_errors/stage1/obj/error_note_for_function_parameter_incompatibility.zig @@ -0,0 +1,10 @@ +fn do_the_thing(func: fn (arg: i32) void) void { _ = func; } +fn bar(arg: bool) void { _ = arg; } +export fn entry() void { + do_the_thing(bar); +} + +// error note for function parameter incompatibility +// +// tmp.zig:4:18: error: expected type 'fn(i32) void', found 'fn(bool) void +// tmp.zig:4:18: note: parameter 0: 'bool' cannot cast into 'i32' diff --git a/test/compile_errors/stage1/obj/error_union_operator_with_non_error_set_LHS.zig b/test/compile_errors/stage1/obj/error_union_operator_with_non_error_set_LHS.zig new file mode 100644 index 0000000000..40b5872fc8 --- /dev/null +++ b/test/compile_errors/stage1/obj/error_union_operator_with_non_error_set_LHS.zig @@ -0,0 +1,9 @@ +comptime { + const z = i32!i32; + var x: z = undefined; + _ = x; +} + +// error union operator with non error set LHS +// +// tmp.zig:2:15: error: expected error set type, found type 'i32' diff --git a/test/compile_errors/stage1/obj/error_when_evaluating_return_type.zig b/test/compile_errors/stage1/obj/error_when_evaluating_return_type.zig new file mode 100644 index 0000000000..60baa1c5b4 --- /dev/null +++ b/test/compile_errors/stage1/obj/error_when_evaluating_return_type.zig @@ -0,0 +1,15 @@ +const Foo = struct { + map: @as(i32, i32), + + fn init() Foo { + return undefined; + } +}; +export fn entry() void { + var rule_set = try Foo.init(); + _ = rule_set; +} + +// error when evaluating return type +// +// tmp.zig:2:19: error: expected type 'i32', found 'type' diff --git a/test/compile_errors/stage1/obj/exceeded_maximum_bit_width_of_integer.zig b/test/compile_errors/stage1/obj/exceeded_maximum_bit_width_of_integer.zig new file mode 100644 index 0000000000..e1784de63e --- /dev/null +++ b/test/compile_errors/stage1/obj/exceeded_maximum_bit_width_of_integer.zig @@ -0,0 +1,13 @@ +export fn entry1() void { + const T = u65536; + _ = T; +} +export fn entry2() void { + var x: i65536 = 1; + _ = x; +} + +// exceeded maximum bit width of integer +// +// tmp.zig:2:15: error: primitive integer type 'u65536' exceeds maximum bit width of 65535 +// tmp.zig:6:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535 diff --git a/test/compile_errors/stage1/obj/explicit_cast_float_literal_to_integer_when_there_is_a_fraction_component.zig b/test/compile_errors/stage1/obj/explicit_cast_float_literal_to_integer_when_there_is_a_fraction_component.zig new file mode 100644 index 0000000000..eaa2be84c7 --- /dev/null +++ b/test/compile_errors/stage1/obj/explicit_cast_float_literal_to_integer_when_there_is_a_fraction_component.zig @@ -0,0 +1,7 @@ +export fn entry() i32 { + return @as(i32, 12.34); +} + +// explicit cast float literal to integer when there is a fraction component +// +// tmp.zig:2:21: error: fractional component prevents float value 12.340000 from being casted to type 'i32' diff --git a/test/compile_errors/stage1/obj/explicit_error_set_cast_known_at_comptime_violates_error_sets.zig b/test/compile_errors/stage1/obj/explicit_error_set_cast_known_at_comptime_violates_error_sets.zig new file mode 100644 index 0000000000..68d78e0f92 --- /dev/null +++ b/test/compile_errors/stage1/obj/explicit_error_set_cast_known_at_comptime_violates_error_sets.zig @@ -0,0 +1,11 @@ +const Set1 = error {A, B}; +const Set2 = error {A, C}; +comptime { + var x = Set1.B; + var y = @errSetCast(Set2, x); + _ = y; +} + +// explicit error set cast known at comptime violates error sets +// +// tmp.zig:5:13: error: error.B not a member of error set 'Set2' diff --git a/test/compile_errors/stage1/obj/explicitly_casting_non_tag_type_to_enum.zig b/test/compile_errors/stage1/obj/explicitly_casting_non_tag_type_to_enum.zig new file mode 100644 index 0000000000..e7c4d5f5d9 --- /dev/null +++ b/test/compile_errors/stage1/obj/explicitly_casting_non_tag_type_to_enum.zig @@ -0,0 +1,16 @@ +const Small = enum(u2) { + One, + Two, + Three, + Four, +}; + +export fn entry() void { + var y = @as(f32, 3); + var x = @intToEnum(Small, y); + _ = x; +} + +// explicitly casting non tag type to enum +// +// tmp.zig:10:31: error: expected integer type, found 'f32' diff --git a/test/compile_errors/stage1/obj/export_function_with_comptime_parameter.zig b/test/compile_errors/stage1/obj/export_function_with_comptime_parameter.zig new file mode 100644 index 0000000000..0f300f324b --- /dev/null +++ b/test/compile_errors/stage1/obj/export_function_with_comptime_parameter.zig @@ -0,0 +1,7 @@ +export fn foo(comptime x: i32, y: i32) i32{ + return x + y; +} + +// export function with comptime parameter +// +// tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C' diff --git a/test/compile_errors/stage1/obj/export_generic_function.zig b/test/compile_errors/stage1/obj/export_generic_function.zig new file mode 100644 index 0000000000..3fb4375ed4 --- /dev/null +++ b/test/compile_errors/stage1/obj/export_generic_function.zig @@ -0,0 +1,8 @@ +export fn foo(num: anytype) i32 { + _ = num; + return 0; +} + +// export generic function +// +// tmp.zig:1:15: error: parameter of type 'anytype' not allowed in function with calling convention 'C' diff --git a/test/compile_errors/stage1/obj/exported_async_function.zig b/test/compile_errors/stage1/obj/exported_async_function.zig new file mode 100644 index 0000000000..296a5950e9 --- /dev/null +++ b/test/compile_errors/stage1/obj/exported_async_function.zig @@ -0,0 +1,5 @@ +export fn foo() callconv(.Async) void {} + +// exported async function +// +// tmp.zig:1:1: error: exported function cannot be async diff --git a/test/compile_errors/stage1/obj/exported_enum_without_explicit_integer_tag_type.zig b/test/compile_errors/stage1/obj/exported_enum_without_explicit_integer_tag_type.zig new file mode 100644 index 0000000000..3d6e63db43 --- /dev/null +++ b/test/compile_errors/stage1/obj/exported_enum_without_explicit_integer_tag_type.zig @@ -0,0 +1,13 @@ +const E = enum { one, two }; +comptime { + @export(E, .{ .name = "E" }); +} +const e: E = .two; +comptime { + @export(e, .{ .name = "e" }); +} + +// exported enum without explicit integer tag type +// +// tmp.zig:3:13: error: exported enum without explicit integer tag type +// tmp.zig:7:13: error: exported enum value without explicit integer tag type diff --git a/test/compile_errors/stage1/obj/extern_function_pointer_mismatch.zig b/test/compile_errors/stage1/obj/extern_function_pointer_mismatch.zig new file mode 100644 index 0000000000..f93a24db34 --- /dev/null +++ b/test/compile_errors/stage1/obj/extern_function_pointer_mismatch.zig @@ -0,0 +1,10 @@ +const fns = [_](fn(i32)i32) { a, b, c }; +pub fn a(x: i32) i32 {return x + 0;} +pub fn b(x: i32) i32 {return x + 1;} +export fn c(x: i32) i32 {return x + 2;} + +export fn entry() usize { return @sizeOf(@TypeOf(fns)); } + +// extern function pointer mismatch +// +// tmp.zig:1:37: error: expected type 'fn(i32) i32', found 'fn(i32) callconv(.C) i32' diff --git a/test/compile_errors/stage1/obj/extern_function_with_comptime_parameter.zig b/test/compile_errors/stage1/obj/extern_function_with_comptime_parameter.zig new file mode 100644 index 0000000000..3dfdfe663e --- /dev/null +++ b/test/compile_errors/stage1/obj/extern_function_with_comptime_parameter.zig @@ -0,0 +1,9 @@ +extern fn foo(comptime x: i32, y: i32) i32; +fn f() i32 { + return foo(1, 2); +} +export fn entry() usize { return @sizeOf(@TypeOf(f)); } + +// extern function with comptime parameter +// +// tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C' diff --git a/test/compile_errors/stage1/obj/extern_struct_with_extern-compatible_but_inferred_integer_tag_type.zig b/test/compile_errors/stage1/obj/extern_struct_with_extern-compatible_but_inferred_integer_tag_type.zig new file mode 100644 index 0000000000..e65c438da3 --- /dev/null +++ b/test/compile_errors/stage1/obj/extern_struct_with_extern-compatible_but_inferred_integer_tag_type.zig @@ -0,0 +1,41 @@ +pub const E = enum { +@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12", +@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23", +@"24",@"25",@"26",@"27",@"28",@"29",@"30",@"31",@"32",@"33",@"34", +@"35",@"36",@"37",@"38",@"39",@"40",@"41",@"42",@"43",@"44",@"45", +@"46",@"47",@"48",@"49",@"50",@"51",@"52",@"53",@"54",@"55",@"56", +@"57",@"58",@"59",@"60",@"61",@"62",@"63",@"64",@"65",@"66",@"67", +@"68",@"69",@"70",@"71",@"72",@"73",@"74",@"75",@"76",@"77",@"78", +@"79",@"80",@"81",@"82",@"83",@"84",@"85",@"86",@"87",@"88",@"89", +@"90",@"91",@"92",@"93",@"94",@"95",@"96",@"97",@"98",@"99",@"100", +@"101",@"102",@"103",@"104",@"105",@"106",@"107",@"108",@"109", +@"110",@"111",@"112",@"113",@"114",@"115",@"116",@"117",@"118", +@"119",@"120",@"121",@"122",@"123",@"124",@"125",@"126",@"127", +@"128",@"129",@"130",@"131",@"132",@"133",@"134",@"135",@"136", +@"137",@"138",@"139",@"140",@"141",@"142",@"143",@"144",@"145", +@"146",@"147",@"148",@"149",@"150",@"151",@"152",@"153",@"154", +@"155",@"156",@"157",@"158",@"159",@"160",@"161",@"162",@"163", +@"164",@"165",@"166",@"167",@"168",@"169",@"170",@"171",@"172", +@"173",@"174",@"175",@"176",@"177",@"178",@"179",@"180",@"181", +@"182",@"183",@"184",@"185",@"186",@"187",@"188",@"189",@"190", +@"191",@"192",@"193",@"194",@"195",@"196",@"197",@"198",@"199", +@"200",@"201",@"202",@"203",@"204",@"205",@"206",@"207",@"208", +@"209",@"210",@"211",@"212",@"213",@"214",@"215",@"216",@"217", +@"218",@"219",@"220",@"221",@"222",@"223",@"224",@"225",@"226", +@"227",@"228",@"229",@"230",@"231",@"232",@"233",@"234",@"235", +@"236",@"237",@"238",@"239",@"240",@"241",@"242",@"243",@"244", +@"245",@"246",@"247",@"248",@"249",@"250",@"251",@"252",@"253", +@"254",@"255" +}; +pub const S = extern struct { + e: E, +}; +export fn entry() void { + if (@typeInfo(E).Enum.tag_type != u8) @compileError("did not infer u8 tag type"); + const s: S = undefined; + _ = s; +} + +// extern struct with extern-compatible but inferred integer tag type +// +// tmp.zig:31:5: error: extern structs cannot contain fields of type 'E' diff --git a/test/compile_errors/stage1/obj/extern_struct_with_non-extern-compatible_integer_tag_type.zig b/test/compile_errors/stage1/obj/extern_struct_with_non-extern-compatible_integer_tag_type.zig new file mode 100644 index 0000000000..6d698ce8e3 --- /dev/null +++ b/test/compile_errors/stage1/obj/extern_struct_with_non-extern-compatible_integer_tag_type.zig @@ -0,0 +1,12 @@ +pub const E = enum(u31) { A, B, C }; +pub const S = extern struct { + e: E, +}; +export fn entry() void { + const s: S = undefined; + _ = s; +} + +// extern struct with non-extern-compatible integer tag type +// +// tmp.zig:3:5: error: extern structs cannot contain fields of type 'E' diff --git a/test/compile_errors/stage1/obj/extern_union_field_missing_type.zig b/test/compile_errors/stage1/obj/extern_union_field_missing_type.zig new file mode 100644 index 0000000000..1287ce0159 --- /dev/null +++ b/test/compile_errors/stage1/obj/extern_union_field_missing_type.zig @@ -0,0 +1,11 @@ +const Letter = extern union { + A, +}; +export fn entry() void { + var a = Letter { .A = {} }; + _ = a; +} + +// extern union field missing type +// +// tmp.zig:2:5: error: union field missing type diff --git a/test/compile_errors/stage1/obj/extern_union_given_enum_tag_type.zig b/test/compile_errors/stage1/obj/extern_union_given_enum_tag_type.zig new file mode 100644 index 0000000000..5b38d77eb6 --- /dev/null +++ b/test/compile_errors/stage1/obj/extern_union_given_enum_tag_type.zig @@ -0,0 +1,18 @@ +const Letter = enum { + A, + B, + C, +}; +const Payload = extern union(Letter) { + A: i32, + B: f64, + C: bool, +}; +export fn entry() void { + var a = Payload { .A = 1234 }; + _ = a; +} + +// extern union given enum tag type +// +// tmp.zig:6:30: error: extern union does not support enum tag type diff --git a/test/compile_errors/stage1/obj/extern_variable_has_no_type.zig b/test/compile_errors/stage1/obj/extern_variable_has_no_type.zig new file mode 100644 index 0000000000..f9d3952275 --- /dev/null +++ b/test/compile_errors/stage1/obj/extern_variable_has_no_type.zig @@ -0,0 +1,8 @@ +extern var foo; +pub export fn entry() void { + foo; +} + +// extern variable has no type +// +// tmp.zig:1:8: error: unable to infer variable type diff --git a/test/compile_errors/stage1/obj/fieldParentPtr-bad_field_name.zig b/test/compile_errors/stage1/obj/fieldParentPtr-bad_field_name.zig new file mode 100644 index 0000000000..8c40641113 --- /dev/null +++ b/test/compile_errors/stage1/obj/fieldParentPtr-bad_field_name.zig @@ -0,0 +1,10 @@ +const Foo = extern struct { + derp: i32, +}; +export fn foo(a: *i32) *Foo { + return @fieldParentPtr(Foo, "a", a); +} + +// @fieldParentPtr - bad field name +// +// tmp.zig:5:33: error: struct 'Foo' has no field 'a' diff --git a/test/compile_errors/stage1/obj/fieldParentPtr-comptime_field_ptr_not_based_on_struct.zig b/test/compile_errors/stage1/obj/fieldParentPtr-comptime_field_ptr_not_based_on_struct.zig new file mode 100644 index 0000000000..a8a5431352 --- /dev/null +++ b/test/compile_errors/stage1/obj/fieldParentPtr-comptime_field_ptr_not_based_on_struct.zig @@ -0,0 +1,15 @@ +const Foo = struct { + a: i32, + b: i32, +}; +const foo = Foo { .a = 1, .b = 2, }; + +comptime { + const field_ptr = @intToPtr(*i32, 0x1234); + const another_foo_ptr = @fieldParentPtr(Foo, "b", field_ptr); + _ = another_foo_ptr; +} + +// @fieldParentPtr - comptime field ptr not based on struct +// +// tmp.zig:9:55: error: pointer value not based on parent struct diff --git a/test/compile_errors/stage1/obj/fieldParentPtr-comptime_wrong_field_index.zig b/test/compile_errors/stage1/obj/fieldParentPtr-comptime_wrong_field_index.zig new file mode 100644 index 0000000000..11bb7282fc --- /dev/null +++ b/test/compile_errors/stage1/obj/fieldParentPtr-comptime_wrong_field_index.zig @@ -0,0 +1,14 @@ +const Foo = struct { + a: i32, + b: i32, +}; +const foo = Foo { .a = 1, .b = 2, }; + +comptime { + const another_foo_ptr = @fieldParentPtr(Foo, "b", &foo.a); + _ = another_foo_ptr; +} + +// @fieldParentPtr - comptime wrong field index +// +// tmp.zig:8:29: error: field 'b' has index 1 but pointer value is index 0 of struct 'Foo' diff --git a/test/compile_errors/stage1/obj/fieldParentPtr-field_pointer_is_not_pointer.zig b/test/compile_errors/stage1/obj/fieldParentPtr-field_pointer_is_not_pointer.zig new file mode 100644 index 0000000000..8db9075b7b --- /dev/null +++ b/test/compile_errors/stage1/obj/fieldParentPtr-field_pointer_is_not_pointer.zig @@ -0,0 +1,10 @@ +const Foo = extern struct { + a: i32, +}; +export fn foo(a: i32) *Foo { + return @fieldParentPtr(Foo, "a", a); +} + +// @fieldParentPtr - field pointer is not pointer +// +// tmp.zig:5:38: error: expected pointer, found 'i32' diff --git a/test/compile_errors/stage1/obj/fieldParentPtr-non_struct.zig b/test/compile_errors/stage1/obj/fieldParentPtr-non_struct.zig new file mode 100644 index 0000000000..325fbe5b3b --- /dev/null +++ b/test/compile_errors/stage1/obj/fieldParentPtr-non_struct.zig @@ -0,0 +1,8 @@ +const Foo = i32; +export fn foo(a: *i32) *Foo { + return @fieldParentPtr(Foo, "a", a); +} + +// @fieldParentPtr - non struct +// +// tmp.zig:3:28: error: expected struct type, found 'i32' diff --git a/test/compile_errors/stage1/obj/field_access_of_opaque_type.zig b/test/compile_errors/stage1/obj/field_access_of_opaque_type.zig new file mode 100644 index 0000000000..3354c0f471 --- /dev/null +++ b/test/compile_errors/stage1/obj/field_access_of_opaque_type.zig @@ -0,0 +1,14 @@ +const MyType = opaque {}; + +export fn entry() bool { + var x: i32 = 1; + return bar(@ptrCast(*MyType, &x)); +} + +fn bar(x: *MyType) bool { + return x.blah; +} + +// field access of opaque type +// +// tmp.zig:9:13: error: no member named 'blah' in opaque type 'MyType' diff --git a/test/compile_errors/stage1/obj/field_access_of_slices.zig b/test/compile_errors/stage1/obj/field_access_of_slices.zig new file mode 100644 index 0000000000..3e79e1f0e0 --- /dev/null +++ b/test/compile_errors/stage1/obj/field_access_of_slices.zig @@ -0,0 +1,9 @@ +export fn entry() void { + var slice: []i32 = undefined; + const info = @TypeOf(slice).unknown; + _ = info; +} + +// field access of slices +// +// tmp.zig:3:32: error: type 'type' does not support field access diff --git a/test/compile_errors/stage1/obj/field_access_of_unknown_length_pointer.zig b/test/compile_errors/stage1/obj/field_access_of_unknown_length_pointer.zig new file mode 100644 index 0000000000..7097c13605 --- /dev/null +++ b/test/compile_errors/stage1/obj/field_access_of_unknown_length_pointer.zig @@ -0,0 +1,11 @@ +const Foo = extern struct { + a: i32, +}; + +export fn entry(foo: [*]Foo) void { + foo.a += 1; +} + +// field access of unknown length pointer +// +// tmp.zig:6:8: error: type '[*]Foo' does not support field access diff --git a/test/compile_errors/stage1/obj/field_type_supplied_in_an_enum.zig b/test/compile_errors/stage1/obj/field_type_supplied_in_an_enum.zig new file mode 100644 index 0000000000..cb308307bb --- /dev/null +++ b/test/compile_errors/stage1/obj/field_type_supplied_in_an_enum.zig @@ -0,0 +1,10 @@ +const Letter = enum { + A: void, + B, + C, +}; + +// field type supplied in an enum +// +// tmp.zig:2:8: error: enum fields do not have types +// tmp.zig:1:16: note: consider 'union(enum)' here to make it a tagged union diff --git a/test/compile_errors/stage1/obj/floatToInt_comptime_safety.zig b/test/compile_errors/stage1/obj/floatToInt_comptime_safety.zig new file mode 100644 index 0000000000..e54047fb2f --- /dev/null +++ b/test/compile_errors/stage1/obj/floatToInt_comptime_safety.zig @@ -0,0 +1,15 @@ +comptime { + _ = @floatToInt(i8, @as(f32, -129.1)); +} +comptime { + _ = @floatToInt(u8, @as(f32, -1.1)); +} +comptime { + _ = @floatToInt(u8, @as(f32, 256.1)); +} + +// @floatToInt comptime safety +// +// tmp.zig:2:9: error: integer value '-129' cannot be stored in type 'i8' +// tmp.zig:5:9: error: integer value '-1' cannot be stored in type 'u8' +// tmp.zig:8:9: error: integer value '256' cannot be stored in type 'u8' diff --git a/test/compile_errors/stage1/obj/float_literal_too_large_error.zig b/test/compile_errors/stage1/obj/float_literal_too_large_error.zig new file mode 100644 index 0000000000..d7be9874ac --- /dev/null +++ b/test/compile_errors/stage1/obj/float_literal_too_large_error.zig @@ -0,0 +1,8 @@ +comptime { + const a = 0x1.0p18495; + _ = a; +} + +// float literal too large error +// +// tmp.zig:2:15: error: float literal out of range of any type diff --git a/test/compile_errors/stage1/obj/float_literal_too_small_error_denormal.zig b/test/compile_errors/stage1/obj/float_literal_too_small_error_denormal.zig new file mode 100644 index 0000000000..2657775be0 --- /dev/null +++ b/test/compile_errors/stage1/obj/float_literal_too_small_error_denormal.zig @@ -0,0 +1,8 @@ +comptime { + const a = 0x1.0p-19000; + _ = a; +} + +// float literal too small error (denormal) +// +// tmp.zig:2:15: error: float literal out of range of any type diff --git a/test/compile_errors/stage1/obj/for_loop_body_expression_ignored.zig b/test/compile_errors/stage1/obj/for_loop_body_expression_ignored.zig new file mode 100644 index 0000000000..fffbb13604 --- /dev/null +++ b/test/compile_errors/stage1/obj/for_loop_body_expression_ignored.zig @@ -0,0 +1,16 @@ +fn returns() usize { + return 2; +} +export fn f1() void { + for ("hello") |_| returns(); +} +export fn f2() void { + var x: anyerror!i32 = error.Bad; + for ("hello") |_| returns() else unreachable; + _ = x; +} + +// for loop body expression ignored +// +// tmp.zig:5:30: error: expression value is ignored +// tmp.zig:9:30: error: expression value is ignored diff --git a/test/compile_errors/stage1/obj/frame_called_outside_of_function_definition.zig b/test/compile_errors/stage1/obj/frame_called_outside_of_function_definition.zig new file mode 100644 index 0000000000..a76fff93a8 --- /dev/null +++ b/test/compile_errors/stage1/obj/frame_called_outside_of_function_definition.zig @@ -0,0 +1,9 @@ +var handle_undef: anyframe = undefined; +var handle_dummy: anyframe = @frame(); +export fn entry() bool { + return handle_undef == handle_dummy; +} + +// @frame() called outside of function definition +// +// tmp.zig:2:30: error: @frame() called outside of function definition diff --git a/test/compile_errors/stage1/obj/frame_causes_function_to_be_async.zig b/test/compile_errors/stage1/obj/frame_causes_function_to_be_async.zig new file mode 100644 index 0000000000..b45ff6965e --- /dev/null +++ b/test/compile_errors/stage1/obj/frame_causes_function_to_be_async.zig @@ -0,0 +1,11 @@ +export fn entry() void { + func(); +} +fn func() void { + _ = @frame(); +} + +// @frame() causes function to be async +// +// tmp.zig:1:1: error: function with calling convention 'C' cannot be async +// tmp.zig:5:9: note: @frame() causes function to be async diff --git a/test/compile_errors/stage1/obj/function_alignment_non_power_of_2.zig b/test/compile_errors/stage1/obj/function_alignment_non_power_of_2.zig new file mode 100644 index 0000000000..949e11c115 --- /dev/null +++ b/test/compile_errors/stage1/obj/function_alignment_non_power_of_2.zig @@ -0,0 +1,6 @@ +extern fn foo() align(3) void; +export fn entry() void { return foo(); } + +// function alignment non power of 2 +// +// tmp.zig:1:23: error: alignment value 3 is not a power of 2 diff --git a/test/compile_errors/stage1/obj/function_call_assigned_to_incorrect_type.zig b/test/compile_errors/stage1/obj/function_call_assigned_to_incorrect_type.zig new file mode 100644 index 0000000000..4257b802c1 --- /dev/null +++ b/test/compile_errors/stage1/obj/function_call_assigned_to_incorrect_type.zig @@ -0,0 +1,11 @@ +export fn entry() void { + var arr: [4]f32 = undefined; + arr = concat(); +} +fn concat() [16]f32 { + return [1]f32{0}**16; +} + +// function call assigned to incorrect type +// +// tmp.zig:3:17: error: expected type '[4]f32', found '[16]f32' diff --git a/test/compile_errors/stage1/obj/function_parameter_is_opaque.zig b/test/compile_errors/stage1/obj/function_parameter_is_opaque.zig new file mode 100644 index 0000000000..12e50ca59b --- /dev/null +++ b/test/compile_errors/stage1/obj/function_parameter_is_opaque.zig @@ -0,0 +1,27 @@ +const FooType = opaque {}; +export fn entry1() void { + const someFuncPtr: fn (FooType) void = undefined; + _ = someFuncPtr; +} + +export fn entry2() void { + const someFuncPtr: fn (@TypeOf(null)) void = undefined; + _ = someFuncPtr; +} + +fn foo(p: FooType) void {_ = p;} +export fn entry3() void { + _ = foo; +} + +fn bar(p: @TypeOf(null)) void {_ = p;} +export fn entry4() void { + _ = bar; +} + +// function parameter is opaque +// +// tmp.zig:3:28: error: parameter of opaque type 'FooType' not allowed +// tmp.zig:8:28: error: parameter of type '@Type(.Null)' not allowed +// tmp.zig:12:11: error: parameter of opaque type 'FooType' not allowed +// tmp.zig:17:11: error: parameter of type '@Type(.Null)' not allowed diff --git a/test/compile_errors/stage1/obj/function_prototype_with_no_body.zig b/test/compile_errors/stage1/obj/function_prototype_with_no_body.zig new file mode 100644 index 0000000000..07597af015 --- /dev/null +++ b/test/compile_errors/stage1/obj/function_prototype_with_no_body.zig @@ -0,0 +1,8 @@ +fn foo() void; +export fn entry() void { + foo(); +} + +// function prototype with no body +// +// tmp.zig:1:1: error: non-extern function has no body diff --git a/test/compile_errors/stage1/obj/function_returning_opaque_type.zig b/test/compile_errors/stage1/obj/function_returning_opaque_type.zig new file mode 100644 index 0000000000..956a4ed224 --- /dev/null +++ b/test/compile_errors/stage1/obj/function_returning_opaque_type.zig @@ -0,0 +1,17 @@ +const FooType = opaque {}; +export fn bar() !FooType { + return error.InvalidValue; +} +export fn bav() !@TypeOf(null) { + return error.InvalidValue; +} +export fn baz() !@TypeOf(undefined) { + return error.InvalidValue; +} + +// function returning opaque type +// +// tmp.zig:2:18: error: Opaque return type 'FooType' not allowed +// tmp.zig:1:1: note: type declared here +// tmp.zig:5:18: error: Null return type '@Type(.Null)' not allowed +// tmp.zig:8:18: error: Undefined return type '@Type(.Undefined)' not allowed diff --git a/test/compile_errors/stage1/obj/function_with_ccc_indirectly_calling_async_function.zig b/test/compile_errors/stage1/obj/function_with_ccc_indirectly_calling_async_function.zig new file mode 100644 index 0000000000..1ccf486be6 --- /dev/null +++ b/test/compile_errors/stage1/obj/function_with_ccc_indirectly_calling_async_function.zig @@ -0,0 +1,16 @@ +export fn entry() void { + foo(); +} +fn foo() void { + bar(); +} +fn bar() void { + suspend {} +} + +// function with ccc indirectly calling async function +// +// tmp.zig:1:1: error: function with calling convention 'C' cannot be async +// tmp.zig:2:8: note: async function call here +// tmp.zig:5:8: note: async function call here +// tmp.zig:8:5: note: suspends here diff --git a/test/compile_errors/stage1/obj/function_with_invalid_return_type.zig b/test/compile_errors/stage1/obj/function_with_invalid_return_type.zig new file mode 100644 index 0000000000..acedbac7d1 --- /dev/null +++ b/test/compile_errors/stage1/obj/function_with_invalid_return_type.zig @@ -0,0 +1,5 @@ +export fn foo() boid {} + +// function with invalid return type +// +// tmp.zig:1:17: error: use of undeclared identifier 'boid' diff --git a/test/compile_errors/stage1/obj/function_with_non-extern_non-packed_enum_parameter.zig b/test/compile_errors/stage1/obj/function_with_non-extern_non-packed_enum_parameter.zig new file mode 100644 index 0000000000..9c1913305d --- /dev/null +++ b/test/compile_errors/stage1/obj/function_with_non-extern_non-packed_enum_parameter.zig @@ -0,0 +1,6 @@ +const Foo = enum { A, B, C }; +export fn entry(foo: Foo) void { _ = foo; } + +// function with non-extern non-packed enum parameter +// +// tmp.zig:2:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C' diff --git a/test/compile_errors/stage1/obj/function_with_non-extern_non-packed_struct_parameter.zig b/test/compile_errors/stage1/obj/function_with_non-extern_non-packed_struct_parameter.zig new file mode 100644 index 0000000000..eb2617f279 --- /dev/null +++ b/test/compile_errors/stage1/obj/function_with_non-extern_non-packed_struct_parameter.zig @@ -0,0 +1,10 @@ +const Foo = struct { + A: i32, + B: f32, + C: bool, +}; +export fn entry(foo: Foo) void { _ = foo; } + +// function with non-extern non-packed struct parameter +// +// tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C' diff --git a/test/compile_errors/stage1/obj/function_with_non-extern_non-packed_union_parameter.zig b/test/compile_errors/stage1/obj/function_with_non-extern_non-packed_union_parameter.zig new file mode 100644 index 0000000000..662ffd349b --- /dev/null +++ b/test/compile_errors/stage1/obj/function_with_non-extern_non-packed_union_parameter.zig @@ -0,0 +1,10 @@ +const Foo = union { + A: i32, + B: f32, + C: bool, +}; +export fn entry(foo: Foo) void { _ = foo; } + +// function with non-extern non-packed union parameter +// +// tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C' diff --git a/test/compile_errors/stage1/obj/generic_fn_as_parameter_without_comptime_keyword.zig b/test/compile_errors/stage1/obj/generic_fn_as_parameter_without_comptime_keyword.zig new file mode 100644 index 0000000000..fceea0961b --- /dev/null +++ b/test/compile_errors/stage1/obj/generic_fn_as_parameter_without_comptime_keyword.zig @@ -0,0 +1,9 @@ +fn f(_: fn (anytype) void) void {} +fn g(_: anytype) void {} +export fn entry() void { + f(g); +} + +// generic fn as parameter without comptime keyword +// +// tmp.zig:1:9: error: parameter of type 'fn(anytype) anytype' must be declared comptime diff --git a/test/compile_errors/stage1/obj/generic_function_call_assigned_to_incorrect_type.zig b/test/compile_errors/stage1/obj/generic_function_call_assigned_to_incorrect_type.zig new file mode 100644 index 0000000000..b48d5def57 --- /dev/null +++ b/test/compile_errors/stage1/obj/generic_function_call_assigned_to_incorrect_type.zig @@ -0,0 +1,11 @@ +pub export fn entry() void { + var res: []i32 = undefined; + res = myAlloc(i32); +} +fn myAlloc(comptime arg: type) anyerror!arg{ + unreachable; +} + +// generic function call assigned to incorrect type +// +// tmp.zig:3:18: error: expected type '[]i32', found 'anyerror!i32 diff --git a/test/compile_errors/stage1/obj/generic_function_instance_with_non-constant_expression.zig b/test/compile_errors/stage1/obj/generic_function_instance_with_non-constant_expression.zig new file mode 100644 index 0000000000..3698370b57 --- /dev/null +++ b/test/compile_errors/stage1/obj/generic_function_instance_with_non-constant_expression.zig @@ -0,0 +1,10 @@ +fn foo(comptime x: i32, y: i32) i32 { return x + y; } +fn test1(a: i32, b: i32) i32 { + return foo(a, b); +} + +export fn entry() usize { return @sizeOf(@TypeOf(test1)); } + +// generic function instance with non-constant expression +// +// tmp.zig:3:16: error: runtime value cannot be passed to comptime arg diff --git a/test/compile_errors/stage1/obj/generic_function_returning_opaque_type.zig b/test/compile_errors/stage1/obj/generic_function_returning_opaque_type.zig new file mode 100644 index 0000000000..c109a5ce7c --- /dev/null +++ b/test/compile_errors/stage1/obj/generic_function_returning_opaque_type.zig @@ -0,0 +1,23 @@ +const FooType = opaque {}; +fn generic(comptime T: type) !T { + return undefined; +} +export fn bar() void { + _ = generic(FooType); +} +export fn bav() void { + _ = generic(@TypeOf(null)); +} +export fn baz() void { + _ = generic(@TypeOf(undefined)); +} + +// generic function returning opaque type +// +// tmp.zig:6:16: error: call to generic function with Opaque return type 'FooType' not allowed +// tmp.zig:2:1: note: function declared here +// tmp.zig:1:1: note: type declared here +// tmp.zig:9:16: error: call to generic function with Null return type '@Type(.Null)' not allowed +// tmp.zig:2:1: note: function declared here +// tmp.zig:12:16: error: call to generic function with Undefined return type '@Type(.Undefined)' not allowed +// tmp.zig:2:1: note: function declared here diff --git a/test/compile_errors/stage1/obj/generic_function_where_return_type_is_self-referenced.zig b/test/compile_errors/stage1/obj/generic_function_where_return_type_is_self-referenced.zig new file mode 100644 index 0000000000..18237a5023 --- /dev/null +++ b/test/compile_errors/stage1/obj/generic_function_where_return_type_is_self-referenced.zig @@ -0,0 +1,13 @@ +fn Foo(comptime T: type) Foo(T) { + return struct{ x: T }; +} +export fn entry() void { + const t = Foo(u32) { + .x = 1 + }; + _ = t; +} + +// generic function where return type is self-referenced +// +// tmp.zig:1:29: error: evaluation exceeded 1000 backwards branches diff --git a/test/compile_errors/stage1/obj/global_variable_alignment_non_power_of_2.zig b/test/compile_errors/stage1/obj/global_variable_alignment_non_power_of_2.zig new file mode 100644 index 0000000000..a6c4ccaa98 --- /dev/null +++ b/test/compile_errors/stage1/obj/global_variable_alignment_non_power_of_2.zig @@ -0,0 +1,6 @@ +const some_data: [100]u8 align(3) = undefined; +export fn entry() usize { return @sizeOf(@TypeOf(some_data)); } + +// global variable alignment non power of 2 +// +// tmp.zig:1:32: error: alignment value 3 is not a power of 2 diff --git a/test/compile_errors/stage1/obj/global_variable_initializer_must_be_constant_expression.zig b/test/compile_errors/stage1/obj/global_variable_initializer_must_be_constant_expression.zig new file mode 100644 index 0000000000..1d6c20f3af --- /dev/null +++ b/test/compile_errors/stage1/obj/global_variable_initializer_must_be_constant_expression.zig @@ -0,0 +1,7 @@ +extern fn foo() i32; +const x = foo(); +export fn entry() i32 { return x; } + +// global variable initializer must be constant expression +// +// tmp.zig:2:11: error: unable to evaluate constant expression diff --git a/test/compile_errors/stage1/obj/hasDecl_with_non-container.zig b/test/compile_errors/stage1/obj/hasDecl_with_non-container.zig new file mode 100644 index 0000000000..50f1231997 --- /dev/null +++ b/test/compile_errors/stage1/obj/hasDecl_with_non-container.zig @@ -0,0 +1,7 @@ +export fn entry() void { + _ = @hasDecl(i32, "hi"); +} + +// @hasDecl with non-container +// +// tmp.zig:2:18: error: expected struct, enum, or union; found 'i32' diff --git a/test/compile_errors/stage1/obj/if_condition_is_bool_not_int.zig b/test/compile_errors/stage1/obj/if_condition_is_bool_not_int.zig new file mode 100644 index 0000000000..e8b7c61417 --- /dev/null +++ b/test/compile_errors/stage1/obj/if_condition_is_bool_not_int.zig @@ -0,0 +1,7 @@ +export fn f() void { + if (0) {} +} + +// if condition is bool, not int +// +// tmp.zig:2:9: error: expected type 'bool', found 'comptime_int' diff --git a/test/compile_errors/stage1/obj/ignored_assert-err-ok_return_value.zig b/test/compile_errors/stage1/obj/ignored_assert-err-ok_return_value.zig new file mode 100644 index 0000000000..53fbcaa8b5 --- /dev/null +++ b/test/compile_errors/stage1/obj/ignored_assert-err-ok_return_value.zig @@ -0,0 +1,8 @@ +export fn foo() void { + bar() catch unreachable; +} +fn bar() anyerror!i32 { return 0; } + +// ignored assert-err-ok return value +// +// tmp.zig:2:11: error: expression value is ignored diff --git a/test/compile_errors/stage1/obj/ignored_comptime_statement_value.zig b/test/compile_errors/stage1/obj/ignored_comptime_statement_value.zig new file mode 100644 index 0000000000..80925d6c84 --- /dev/null +++ b/test/compile_errors/stage1/obj/ignored_comptime_statement_value.zig @@ -0,0 +1,7 @@ +export fn foo() void { + comptime {1;} +} + +// ignored comptime statement value +// +// tmp.zig:2:15: error: expression value is ignored diff --git a/test/compile_errors/stage1/obj/ignored_comptime_value.zig b/test/compile_errors/stage1/obj/ignored_comptime_value.zig new file mode 100644 index 0000000000..375a5d242c --- /dev/null +++ b/test/compile_errors/stage1/obj/ignored_comptime_value.zig @@ -0,0 +1,7 @@ +export fn foo() void { + comptime 1; +} + +// ignored comptime value +// +// tmp.zig:2:5: error: expression value is ignored diff --git a/test/compile_errors/stage1/obj/ignored_deferred_function_call.zig b/test/compile_errors/stage1/obj/ignored_deferred_function_call.zig new file mode 100644 index 0000000000..58b85da985 --- /dev/null +++ b/test/compile_errors/stage1/obj/ignored_deferred_function_call.zig @@ -0,0 +1,8 @@ +export fn foo() void { + defer bar(); +} +fn bar() anyerror!i32 { return 0; } + +// ignored deferred function call +// +// tmp.zig:2:14: error: error is ignored. consider using `try`, `catch`, or `if` diff --git a/test/compile_errors/stage1/obj/ignored_deferred_statement_value.zig b/test/compile_errors/stage1/obj/ignored_deferred_statement_value.zig new file mode 100644 index 0000000000..effc79b039 --- /dev/null +++ b/test/compile_errors/stage1/obj/ignored_deferred_statement_value.zig @@ -0,0 +1,7 @@ +export fn foo() void { + defer {1;} +} + +// ignored deferred statement value +// +// tmp.zig:2:12: error: expression value is ignored diff --git a/test/compile_errors/stage1/obj/ignored_expression_in_while_continuation.zig b/test/compile_errors/stage1/obj/ignored_expression_in_while_continuation.zig new file mode 100644 index 0000000000..fb205924e3 --- /dev/null +++ b/test/compile_errors/stage1/obj/ignored_expression_in_while_continuation.zig @@ -0,0 +1,20 @@ +export fn a() void { + while (true) : (bad()) {} +} +export fn b() void { + var x: anyerror!i32 = 1234; + while (x) |_| : (bad()) {} else |_| {} +} +export fn c() void { + var x: ?i32 = 1234; + while (x) |_| : (bad()) {} +} +fn bad() anyerror!void { + return error.Bad; +} + +// ignored expression in while continuation +// +// tmp.zig:2:24: error: error is ignored. consider using `try`, `catch`, or `if` +// tmp.zig:6:25: error: error is ignored. consider using `try`, `catch`, or `if` +// tmp.zig:10:25: error: error is ignored. consider using `try`, `catch`, or `if` diff --git a/test/compile_errors/stage1/obj/ignored_return_value.zig b/test/compile_errors/stage1/obj/ignored_return_value.zig new file mode 100644 index 0000000000..9c8cfa0aa4 --- /dev/null +++ b/test/compile_errors/stage1/obj/ignored_return_value.zig @@ -0,0 +1,8 @@ +export fn foo() void { + bar(); +} +fn bar() i32 { return 0; } + +// ignored return value +// +// tmp.zig:2:8: error: expression value is ignored diff --git a/test/compile_errors/stage1/obj/ignored_statement_value.zig b/test/compile_errors/stage1/obj/ignored_statement_value.zig new file mode 100644 index 0000000000..7855cf584b --- /dev/null +++ b/test/compile_errors/stage1/obj/ignored_statement_value.zig @@ -0,0 +1,7 @@ +export fn foo() void { + 1; +} + +// ignored statement value +// +// tmp.zig:2:5: error: expression value is ignored diff --git a/test/compile_errors/stage1/obj/illegal_comparison_of_types.zig b/test/compile_errors/stage1/obj/illegal_comparison_of_types.zig new file mode 100644 index 0000000000..462664a400 --- /dev/null +++ b/test/compile_errors/stage1/obj/illegal_comparison_of_types.zig @@ -0,0 +1,18 @@ +fn bad_eql_1(a: []u8, b: []u8) bool { + return a == b; +} +const EnumWithData = union(enum) { + One: void, + Two: i32, +}; +fn bad_eql_2(a: *const EnumWithData, b: *const EnumWithData) bool { + return a.* == b.*; +} + +export fn entry1() usize { return @sizeOf(@TypeOf(bad_eql_1)); } +export fn entry2() usize { return @sizeOf(@TypeOf(bad_eql_2)); } + +// illegal comparison of types +// +// tmp.zig:2:14: error: operator not allowed for type '[]u8' +// tmp.zig:9:16: error: operator not allowed for type 'EnumWithData' diff --git a/test/compile_errors/stage1/obj/implicit_cast_between_C_pointer_and_Zig_pointer-bad_const-align-child.zig b/test/compile_errors/stage1/obj/implicit_cast_between_C_pointer_and_Zig_pointer-bad_const-align-child.zig new file mode 100644 index 0000000000..1dd751f989 --- /dev/null +++ b/test/compile_errors/stage1/obj/implicit_cast_between_C_pointer_and_Zig_pointer-bad_const-align-child.zig @@ -0,0 +1,40 @@ +export fn a() void { + var x: [*c]u8 = undefined; + var y: *align(4) u8 = x; + _ = y; +} +export fn b() void { + var x: [*c]const u8 = undefined; + var y: *u8 = x; + _ = y; +} +export fn c() void { + var x: [*c]u8 = undefined; + var y: *u32 = x; + _ = y; +} +export fn d() void { + var y: *align(1) u32 = undefined; + var x: [*c]u32 = y; + _ = x; +} +export fn e() void { + var y: *const u8 = undefined; + var x: [*c]u8 = y; + _ = x; +} +export fn f() void { + var y: *u8 = undefined; + var x: [*c]u32 = y; + _ = x; +} + +// implicit cast between C pointer and Zig pointer - bad const/align/child +// +// tmp.zig:3:27: error: cast increases pointer alignment +// tmp.zig:8:18: error: cast discards const qualifier +// tmp.zig:13:19: error: expected type '*u32', found '[*c]u8' +// tmp.zig:13:19: note: pointer type child 'u8' cannot cast into pointer type child 'u32' +// tmp.zig:18:22: error: cast increases pointer alignment +// tmp.zig:23:21: error: cast discards const qualifier +// tmp.zig:28:22: error: expected type '[*c]u32', found '*u8' diff --git a/test/compile_errors/stage1/obj/implicit_cast_const_array_to_mutable_slice.zig b/test/compile_errors/stage1/obj/implicit_cast_const_array_to_mutable_slice.zig new file mode 100644 index 0000000000..f38c2c9fe1 --- /dev/null +++ b/test/compile_errors/stage1/obj/implicit_cast_const_array_to_mutable_slice.zig @@ -0,0 +1,10 @@ +export fn entry() void { + const buffer: [1]u8 = [_]u8{8}; + const sliceA: []u8 = &buffer; + _ = sliceA; +} + +// implicit cast const array to mutable slice +// +// tmp.zig:3:27: error: cannot cast pointer to array literal to slice type '[]u8' +// tmp.zig:3:27: note: cast discards const qualifier diff --git a/test/compile_errors/stage1/obj/implicit_cast_from_array_to_mutable_slice.zig b/test/compile_errors/stage1/obj/implicit_cast_from_array_to_mutable_slice.zig new file mode 100644 index 0000000000..60fc5baf1f --- /dev/null +++ b/test/compile_errors/stage1/obj/implicit_cast_from_array_to_mutable_slice.zig @@ -0,0 +1,9 @@ +var global_array: [10]i32 = undefined; +fn foo(param: []i32) void {_ = param;} +export fn entry() void { + foo(global_array); +} + +// implicit cast from array to mutable slice +// +// tmp.zig:4:9: error: expected type '[]i32', found '[10]i32' diff --git a/test/compile_errors/stage1/obj/implicit_cast_from_f64_to_f32.zig b/test/compile_errors/stage1/obj/implicit_cast_from_f64_to_f32.zig new file mode 100644 index 0000000000..d1d4417f34 --- /dev/null +++ b/test/compile_errors/stage1/obj/implicit_cast_from_f64_to_f32.zig @@ -0,0 +1,8 @@ +var x: f64 = 1.0; +var y: f32 = x; + +export fn entry() usize { return @sizeOf(@TypeOf(y)); } + +// implicit cast from f64 to f32 +// +// tmp.zig:2:14: error: expected type 'f32', found 'f64' diff --git a/test/compile_errors/stage1/obj/implicit_cast_of_error_set_not_a_subset.zig b/test/compile_errors/stage1/obj/implicit_cast_of_error_set_not_a_subset.zig new file mode 100644 index 0000000000..9cfce6524f --- /dev/null +++ b/test/compile_errors/stage1/obj/implicit_cast_of_error_set_not_a_subset.zig @@ -0,0 +1,14 @@ +const Set1 = error{A, B}; +const Set2 = error{A, C}; +export fn entry() void { + foo(Set1.B); +} +fn foo(set1: Set1) void { + var x: Set2 = set1; + _ = x; +} + +// implicit cast of error set not a subset +// +// tmp.zig:7:19: error: expected type 'Set2', found 'Set1' +// tmp.zig:1:23: note: 'error.B' not a member of destination error set diff --git a/test/compile_errors/stage1/obj/implicit_casting_C_pointers_which_would_mess_up_null_semantics.zig b/test/compile_errors/stage1/obj/implicit_casting_C_pointers_which_would_mess_up_null_semantics.zig new file mode 100644 index 0000000000..cdc35e3963 --- /dev/null +++ b/test/compile_errors/stage1/obj/implicit_casting_C_pointers_which_would_mess_up_null_semantics.zig @@ -0,0 +1,24 @@ +export fn entry() void { + var slice: []const u8 = "aoeu"; + const opt_many_ptr: [*]const u8 = slice.ptr; + var ptr_opt_many_ptr = &opt_many_ptr; + var c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr; + ptr_opt_many_ptr = c_ptr; +} +export fn entry2() void { + var buf: [4]u8 = "aoeu".*; + var slice: []u8 = &buf; + var opt_many_ptr: [*]u8 = slice.ptr; + var ptr_opt_many_ptr = &opt_many_ptr; + var c_ptr: [*c][*c]const u8 = ptr_opt_many_ptr; + _ = c_ptr; +} + +// implicit casting C pointers which would mess up null semantics +// +// tmp.zig:6:24: error: expected type '*const [*]const u8', found '[*c]const [*c]const u8' +// tmp.zig:6:24: note: pointer type child '[*c]const u8' cannot cast into pointer type child '[*]const u8' +// tmp.zig:6:24: note: '[*c]const u8' could have null values which are illegal in type '[*]const u8' +// tmp.zig:13:35: error: expected type '[*c][*c]const u8', found '*[*]u8' +// tmp.zig:13:35: note: pointer type child '[*]u8' cannot cast into pointer type child '[*c]const u8' +// tmp.zig:13:35: note: mutable '[*c]const u8' allows illegal null values stored to type '[*]u8' diff --git a/test/compile_errors/stage1/obj/implicit_casting_null_c_pointer_to_zig_pointer.zig b/test/compile_errors/stage1/obj/implicit_casting_null_c_pointer_to_zig_pointer.zig new file mode 100644 index 0000000000..29dd6d06f9 --- /dev/null +++ b/test/compile_errors/stage1/obj/implicit_casting_null_c_pointer_to_zig_pointer.zig @@ -0,0 +1,9 @@ +comptime { + var c_ptr: [*c]u8 = 0; + var zig_ptr: *u8 = c_ptr; + _ = zig_ptr; +} + +// implicit casting null c pointer to zig pointer +// +// tmp.zig:3:24: error: null pointer casted to type '*u8' diff --git a/test/compile_errors/stage1/obj/implicit_casting_too_big_integers_to_C_pointers.zig b/test/compile_errors/stage1/obj/implicit_casting_too_big_integers_to_C_pointers.zig new file mode 100644 index 0000000000..3deb817b76 --- /dev/null +++ b/test/compile_errors/stage1/obj/implicit_casting_too_big_integers_to_C_pointers.zig @@ -0,0 +1,14 @@ +export fn a() void { + var ptr: [*c]u8 = (1 << 64) + 1; + _ = ptr; +} +export fn b() void { + var x: u65 = 0x1234; + var ptr: [*c]u8 = x; + _ = ptr; +} + +// implicit casting too big integers to C pointers +// +// tmp.zig:2:33: error: integer value 18446744073709551617 cannot be coerced to type 'usize' +// tmp.zig:7:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8' diff --git a/test/compile_errors/stage1/obj/implicit_casting_undefined_c_pointer_to_zig_pointer.zig b/test/compile_errors/stage1/obj/implicit_casting_undefined_c_pointer_to_zig_pointer.zig new file mode 100644 index 0000000000..4c19f57442 --- /dev/null +++ b/test/compile_errors/stage1/obj/implicit_casting_undefined_c_pointer_to_zig_pointer.zig @@ -0,0 +1,9 @@ +comptime { + var c_ptr: [*c]u8 = undefined; + var zig_ptr: *u8 = c_ptr; + _ = zig_ptr; +} + +// implicit casting undefined c pointer to zig pointer +// +// tmp.zig:3:24: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/implicit_semicolon-block_expr.zig b/test/compile_errors/stage1/obj/implicit_semicolon-block_expr.zig new file mode 100644 index 0000000000..bacd484c0c --- /dev/null +++ b/test/compile_errors/stage1/obj/implicit_semicolon-block_expr.zig @@ -0,0 +1,10 @@ +export fn entry() void { + _ = {}; + var good = {}; + _ = {} + var bad = {}; +} + +// implicit semicolon - block expr +// +// tmp.zig:4:11: error: expected ';' after statement diff --git a/test/compile_errors/stage1/obj/implicit_semicolon-block_statement.zig b/test/compile_errors/stage1/obj/implicit_semicolon-block_statement.zig new file mode 100644 index 0000000000..dca8998ee6 --- /dev/null +++ b/test/compile_errors/stage1/obj/implicit_semicolon-block_statement.zig @@ -0,0 +1,10 @@ +export fn entry() void { + {} + var good = {}; + ({}) + var bad = {}; +} + +// implicit semicolon - block statement +// +// tmp.zig:4:9: error: expected ';' after statement diff --git a/test/compile_errors/stage1/obj/implicit_semicolon-comptime_expression.zig b/test/compile_errors/stage1/obj/implicit_semicolon-comptime_expression.zig new file mode 100644 index 0000000000..a3f679a59a --- /dev/null +++ b/test/compile_errors/stage1/obj/implicit_semicolon-comptime_expression.zig @@ -0,0 +1,10 @@ +export fn entry() void { + _ = comptime {}; + var good = {}; + _ = comptime {} + var bad = {}; +} + +// implicit semicolon - comptime expression +// +// tmp.zig:4:20: error: expected ';' after statement diff --git a/test/compile_errors/stage1/obj/implicit_semicolon-comptime_statement.zig b/test/compile_errors/stage1/obj/implicit_semicolon-comptime_statement.zig new file mode 100644 index 0000000000..299b081e4b --- /dev/null +++ b/test/compile_errors/stage1/obj/implicit_semicolon-comptime_statement.zig @@ -0,0 +1,10 @@ +export fn entry() void { + comptime {} + var good = {}; + comptime ({}) + var bad = {}; +} + +// implicit semicolon - comptime statement +// +// tmp.zig:4:18: error: expected ';' after statement diff --git a/test/compile_errors/stage1/obj/implicit_semicolon-defer.zig b/test/compile_errors/stage1/obj/implicit_semicolon-defer.zig new file mode 100644 index 0000000000..7e58d930d6 --- /dev/null +++ b/test/compile_errors/stage1/obj/implicit_semicolon-defer.zig @@ -0,0 +1,10 @@ +export fn entry() void { + defer {} + var good = {}; + defer ({}) + var bad = {}; +} + +// implicit semicolon - defer +// +// tmp.zig:4:15: error: expected ';' after statement diff --git a/test/compile_errors/stage1/obj/implicit_semicolon-for_expression.zig b/test/compile_errors/stage1/obj/implicit_semicolon-for_expression.zig new file mode 100644 index 0000000000..3e332ef189 --- /dev/null +++ b/test/compile_errors/stage1/obj/implicit_semicolon-for_expression.zig @@ -0,0 +1,10 @@ +export fn entry() void { + _ = for(foo()) |_| {}; + var good = {}; + _ = for(foo()) |_| {} + var bad = {}; +} + +// implicit semicolon - for expression +// +// tmp.zig:4:26: error: expected ';' after statement diff --git a/test/compile_errors/stage1/obj/implicit_semicolon-for_statement.zig b/test/compile_errors/stage1/obj/implicit_semicolon-for_statement.zig new file mode 100644 index 0000000000..092c28889f --- /dev/null +++ b/test/compile_errors/stage1/obj/implicit_semicolon-for_statement.zig @@ -0,0 +1,10 @@ +export fn entry() void { + for(foo()) |_| {} + var good = {}; + for(foo()) |_| ({}) + var bad = {}; +} + +// implicit semicolon - for statement +// +// tmp.zig:4:24: error: expected ';' or 'else' after statement diff --git a/test/compile_errors/stage1/obj/implicit_semicolon-if-else-if-else_expression.zig b/test/compile_errors/stage1/obj/implicit_semicolon-if-else-if-else_expression.zig new file mode 100644 index 0000000000..fd55529a8f --- /dev/null +++ b/test/compile_errors/stage1/obj/implicit_semicolon-if-else-if-else_expression.zig @@ -0,0 +1,10 @@ +export fn entry() void { + _ = if(true) {} else if(true) {} else {}; + var good = {}; + _ = if(true) {} else if(true) {} else {} + var bad = {}; +} + +// implicit semicolon - if-else-if-else expression +// +// tmp.zig:4:45: error: expected ';' after statement diff --git a/test/compile_errors/stage1/obj/implicit_semicolon-if-else-if-else_statement.zig b/test/compile_errors/stage1/obj/implicit_semicolon-if-else-if-else_statement.zig new file mode 100644 index 0000000000..3d59e38aa9 --- /dev/null +++ b/test/compile_errors/stage1/obj/implicit_semicolon-if-else-if-else_statement.zig @@ -0,0 +1,10 @@ +export fn entry() void { + if(true) {} else if(true) {} else {} + var good = {}; + if(true) ({}) else if(true) ({}) else ({}) + var bad = {}; +} + +// implicit semicolon - if-else-if-else statement +// +// tmp.zig:4:47: error: expected ';' after statement diff --git a/test/compile_errors/stage1/obj/implicit_semicolon-if-else-if_expression.zig b/test/compile_errors/stage1/obj/implicit_semicolon-if-else-if_expression.zig new file mode 100644 index 0000000000..2caaad52b8 --- /dev/null +++ b/test/compile_errors/stage1/obj/implicit_semicolon-if-else-if_expression.zig @@ -0,0 +1,10 @@ +export fn entry() void { + _ = if(true) {} else if(true) {}; + var good = {}; + _ = if(true) {} else if(true) {} + var bad = {}; +} + +// implicit semicolon - if-else-if expression +// +// tmp.zig:4:37: error: expected ';' after statement diff --git a/test/compile_errors/stage1/obj/implicit_semicolon-if-else-if_statement.zig b/test/compile_errors/stage1/obj/implicit_semicolon-if-else-if_statement.zig new file mode 100644 index 0000000000..263aa36da3 --- /dev/null +++ b/test/compile_errors/stage1/obj/implicit_semicolon-if-else-if_statement.zig @@ -0,0 +1,10 @@ +export fn entry() void { + if(true) {} else if(true) {} + var good = {}; + if(true) ({}) else if(true) ({}) + var bad = {}; +} + +// implicit semicolon - if-else-if statement +// +// tmp.zig:4:37: error: expected ';' or 'else' after statement diff --git a/test/compile_errors/stage1/obj/implicit_semicolon-if-else_expression.zig b/test/compile_errors/stage1/obj/implicit_semicolon-if-else_expression.zig new file mode 100644 index 0000000000..12d993f6a7 --- /dev/null +++ b/test/compile_errors/stage1/obj/implicit_semicolon-if-else_expression.zig @@ -0,0 +1,10 @@ +export fn entry() void { + _ = if(true) {} else {}; + var good = {}; + _ = if(true) {} else {} + var bad = {}; +} + +// implicit semicolon - if-else expression +// +// tmp.zig:4:28: error: expected ';' after statement diff --git a/test/compile_errors/stage1/obj/implicit_semicolon-if-else_statement.zig b/test/compile_errors/stage1/obj/implicit_semicolon-if-else_statement.zig new file mode 100644 index 0000000000..401fc46a51 --- /dev/null +++ b/test/compile_errors/stage1/obj/implicit_semicolon-if-else_statement.zig @@ -0,0 +1,10 @@ +export fn entry() void { + if(true) {} else {} + var good = {}; + if(true) ({}) else ({}) + var bad = {}; +} + +// implicit semicolon - if-else statement +// +// tmp.zig:4:28: error: expected ';' after statement diff --git a/test/compile_errors/stage1/obj/implicit_semicolon-if_expression.zig b/test/compile_errors/stage1/obj/implicit_semicolon-if_expression.zig new file mode 100644 index 0000000000..b3a81e9d36 --- /dev/null +++ b/test/compile_errors/stage1/obj/implicit_semicolon-if_expression.zig @@ -0,0 +1,10 @@ +export fn entry() void { + _ = if(true) {}; + var good = {}; + _ = if(true) {} + var bad = {}; +} + +// implicit semicolon - if expression +// +// tmp.zig:4:20: error: expected ';' after statement diff --git a/test/compile_errors/stage1/obj/implicit_semicolon-if_statement.zig b/test/compile_errors/stage1/obj/implicit_semicolon-if_statement.zig new file mode 100644 index 0000000000..e543925d78 --- /dev/null +++ b/test/compile_errors/stage1/obj/implicit_semicolon-if_statement.zig @@ -0,0 +1,10 @@ +export fn entry() void { + if(true) {} + var good = {}; + if(true) ({}) + var bad = {}; +} + +// implicit semicolon - if statement +// +// tmp.zig:4:18: error: expected ';' or 'else' after statement diff --git a/test/compile_errors/stage1/obj/implicit_semicolon-test_expression.zig b/test/compile_errors/stage1/obj/implicit_semicolon-test_expression.zig new file mode 100644 index 0000000000..1702bec048 --- /dev/null +++ b/test/compile_errors/stage1/obj/implicit_semicolon-test_expression.zig @@ -0,0 +1,10 @@ +export fn entry() void { + _ = if (foo()) |_| {}; + var good = {}; + _ = if (foo()) |_| {} + var bad = {}; +} + +// implicit semicolon - test expression +// +// tmp.zig:4:26: error: expected ';' after statement diff --git a/test/compile_errors/stage1/obj/implicit_semicolon-test_statement.zig b/test/compile_errors/stage1/obj/implicit_semicolon-test_statement.zig new file mode 100644 index 0000000000..8715ca9ac0 --- /dev/null +++ b/test/compile_errors/stage1/obj/implicit_semicolon-test_statement.zig @@ -0,0 +1,10 @@ +export fn entry() void { + if (foo()) |_| {} + var good = {}; + if (foo()) |_| ({}) + var bad = {}; +} + +// implicit semicolon - test statement +// +// tmp.zig:4:24: error: expected ';' or 'else' after statement diff --git a/test/compile_errors/stage1/obj/implicit_semicolon-while-continue_expression.zig b/test/compile_errors/stage1/obj/implicit_semicolon-while-continue_expression.zig new file mode 100644 index 0000000000..b1a7bdbab8 --- /dev/null +++ b/test/compile_errors/stage1/obj/implicit_semicolon-while-continue_expression.zig @@ -0,0 +1,10 @@ +export fn entry() void { + _ = while(true):({}) {}; + var good = {}; + _ = while(true):({}) {} + var bad = {}; +} + +// implicit semicolon - while-continue expression +// +// tmp.zig:4:28: error: expected ';' after statement diff --git a/test/compile_errors/stage1/obj/implicit_semicolon-while-continue_statement.zig b/test/compile_errors/stage1/obj/implicit_semicolon-while-continue_statement.zig new file mode 100644 index 0000000000..601f1f0318 --- /dev/null +++ b/test/compile_errors/stage1/obj/implicit_semicolon-while-continue_statement.zig @@ -0,0 +1,10 @@ +export fn entry() void { + while(true):({}) {} + var good = {}; + while(true):({}) ({}) + var bad = {}; +} + +// implicit semicolon - while-continue statement +// +// tmp.zig:4:26: error: expected ';' or 'else' after statement diff --git a/test/compile_errors/stage1/obj/implicit_semicolon-while_expression.zig b/test/compile_errors/stage1/obj/implicit_semicolon-while_expression.zig new file mode 100644 index 0000000000..9580889bd7 --- /dev/null +++ b/test/compile_errors/stage1/obj/implicit_semicolon-while_expression.zig @@ -0,0 +1,10 @@ +export fn entry() void { + _ = while(true) {}; + var good = {}; + _ = while(true) {} + var bad = {}; +} + +// implicit semicolon - while expression +// +// tmp.zig:4:23: error: expected ';' after statement diff --git a/test/compile_errors/stage1/obj/implicit_semicolon-while_statement.zig b/test/compile_errors/stage1/obj/implicit_semicolon-while_statement.zig new file mode 100644 index 0000000000..ab64dd991d --- /dev/null +++ b/test/compile_errors/stage1/obj/implicit_semicolon-while_statement.zig @@ -0,0 +1,10 @@ +export fn entry() void { + while(true) {} + var good = {}; + while(true) 1 + var bad = {}; +} + +// implicit semicolon - while statement +// +// tmp.zig:4:18: error: expected ';' or 'else' after statement diff --git a/test/compile_errors/stage1/obj/implicitly_casting_enum_to_tag_type.zig b/test/compile_errors/stage1/obj/implicitly_casting_enum_to_tag_type.zig new file mode 100644 index 0000000000..26806a3914 --- /dev/null +++ b/test/compile_errors/stage1/obj/implicitly_casting_enum_to_tag_type.zig @@ -0,0 +1,15 @@ +const Small = enum(u2) { + One, + Two, + Three, + Four, +}; + +export fn entry() void { + var x: u2 = Small.Two; + _ = x; +} + +// implicitly casting enum to tag type +// +// tmp.zig:9:22: error: expected type 'u2', found 'Small' diff --git a/test/compile_errors/stage1/obj/implicitly_increasing_pointer_alignment.zig b/test/compile_errors/stage1/obj/implicitly_increasing_pointer_alignment.zig new file mode 100644 index 0000000000..8f743a3b59 --- /dev/null +++ b/test/compile_errors/stage1/obj/implicitly_increasing_pointer_alignment.zig @@ -0,0 +1,17 @@ +const Foo = packed struct { + a: u8, + b: u32, +}; + +export fn entry() void { + var foo = Foo { .a = 1, .b = 10 }; + bar(&foo.b); +} + +fn bar(x: *u32) void { + x.* += 1; +} + +// implicitly increasing pointer alignment +// +// tmp.zig:8:13: error: expected type '*u32', found '*align(1) u32' diff --git a/test/compile_errors/stage1/obj/implicitly_increasing_slice_alignment.zig b/test/compile_errors/stage1/obj/implicitly_increasing_slice_alignment.zig new file mode 100644 index 0000000000..c1d4ec2a0f --- /dev/null +++ b/test/compile_errors/stage1/obj/implicitly_increasing_slice_alignment.zig @@ -0,0 +1,20 @@ +const Foo = packed struct { + a: u8, + b: u32, +}; + +export fn entry() void { + var foo = Foo { .a = 1, .b = 10 }; + foo.b += 1; + bar(@as(*[1]u32, &foo.b)[0..]); +} + +fn bar(x: []u32) void { + x[0] += 1; +} + +// implicitly increasing slice alignment +// +// tmp.zig:9:26: error: cast increases pointer alignment +// tmp.zig:9:26: note: '*align(1) u32' has alignment 1 +// tmp.zig:9:26: note: '*[1]u32' has alignment 4 diff --git a/test/compile_errors/stage1/obj/import_outside_package_path.zig b/test/compile_errors/stage1/obj/import_outside_package_path.zig new file mode 100644 index 0000000000..843de67b63 --- /dev/null +++ b/test/compile_errors/stage1/obj/import_outside_package_path.zig @@ -0,0 +1,7 @@ +comptime{ + _ = @import("../a.zig"); +} + +// import outside package path +// +// tmp.zig:2:9: error: import of file outside package path: '../a.zig' diff --git a/test/compile_errors/stage1/obj/incorrect_return_type.zig b/test/compile_errors/stage1/obj/incorrect_return_type.zig new file mode 100644 index 0000000000..86c5f23dc3 --- /dev/null +++ b/test/compile_errors/stage1/obj/incorrect_return_type.zig @@ -0,0 +1,19 @@ + pub export fn entry() void{ + _ = foo(); + } + const A = struct { + a: u32, + }; + fn foo() A { + return bar(); + } + const B = struct { + a: u32, + }; + fn bar() B { + unreachable; + } + +// incorrect return type +// +// tmp.zig:8:16: error: expected type 'A', found 'B' diff --git a/test/compile_errors/stage1/obj/increase_pointer_alignment_in_ptrCast.zig b/test/compile_errors/stage1/obj/increase_pointer_alignment_in_ptrCast.zig new file mode 100644 index 0000000000..01d8ac821e --- /dev/null +++ b/test/compile_errors/stage1/obj/increase_pointer_alignment_in_ptrCast.zig @@ -0,0 +1,11 @@ +export fn entry() u32 { + var bytes: [4]u8 = [_]u8{0x01, 0x02, 0x03, 0x04}; + const ptr = @ptrCast(*u32, &bytes[0]); + return ptr.*; +} + +// increase pointer alignment in @ptrCast +// +// tmp.zig:3:17: error: cast increases pointer alignment +// tmp.zig:3:38: note: '*u8' has alignment 1 +// tmp.zig:3:26: note: '*u32' has alignment 4 diff --git a/test/compile_errors/stage1/obj/indexing_a_undefined_slice_at_comptime.zig b/test/compile_errors/stage1/obj/indexing_a_undefined_slice_at_comptime.zig new file mode 100644 index 0000000000..4653d8668e --- /dev/null +++ b/test/compile_errors/stage1/obj/indexing_a_undefined_slice_at_comptime.zig @@ -0,0 +1,8 @@ +comptime { + var slice: []u8 = undefined; + slice[0] = 2; +} + +// indexing a undefined slice at comptime +// +// tmp.zig:3:10: error: index 0 outside slice of size 0 diff --git a/test/compile_errors/stage1/obj/indexing_an_array_of_size_zero.zig b/test/compile_errors/stage1/obj/indexing_an_array_of_size_zero.zig new file mode 100644 index 0000000000..9066985de5 --- /dev/null +++ b/test/compile_errors/stage1/obj/indexing_an_array_of_size_zero.zig @@ -0,0 +1,9 @@ +const array = [_]u8{}; +export fn foo() void { + const pointer = &array[0]; + _ = pointer; +} + +// indexing an array of size zero +// +// tmp.zig:3:27: error: accessing a zero length array is not allowed diff --git a/test/compile_errors/stage1/obj/indexing_an_array_of_size_zero_with_runtime_index.zig b/test/compile_errors/stage1/obj/indexing_an_array_of_size_zero_with_runtime_index.zig new file mode 100644 index 0000000000..c5f3acb3cc --- /dev/null +++ b/test/compile_errors/stage1/obj/indexing_an_array_of_size_zero_with_runtime_index.zig @@ -0,0 +1,10 @@ +const array = [_]u8{}; +export fn foo() void { + var index: usize = 0; + const pointer = &array[index]; + _ = pointer; +} + +// indexing an array of size zero with runtime index +// +// tmp.zig:4:27: error: accessing a zero length array is not allowed diff --git a/test/compile_errors/stage1/obj/indexing_single-item_pointer.zig b/test/compile_errors/stage1/obj/indexing_single-item_pointer.zig new file mode 100644 index 0000000000..e228083964 --- /dev/null +++ b/test/compile_errors/stage1/obj/indexing_single-item_pointer.zig @@ -0,0 +1,7 @@ +export fn entry(ptr: *i32) i32 { + return ptr[1]; +} + +// indexing single-item pointer +// +// tmp.zig:2:15: error: index of single-item pointer diff --git a/test/compile_errors/stage1/obj/indirect_recursion_of_async_functions_detected.zig b/test/compile_errors/stage1/obj/indirect_recursion_of_async_functions_detected.zig new file mode 100644 index 0000000000..5765f7aae1 --- /dev/null +++ b/test/compile_errors/stage1/obj/indirect_recursion_of_async_functions_detected.zig @@ -0,0 +1,34 @@ +var frame: ?anyframe = null; + +export fn a() void { + _ = async rangeSum(10); + while (frame) |f| resume f; +} + +fn rangeSum(x: i32) i32 { + suspend { + frame = @frame(); + } + frame = null; + + if (x == 0) return 0; + var child = rangeSumIndirect(x - 1); + return child + 1; +} + +fn rangeSumIndirect(x: i32) i32 { + suspend { + frame = @frame(); + } + frame = null; + + if (x == 0) return 0; + var child = rangeSum(x - 1); + return child + 1; +} + +// indirect recursion of async functions detected +// +// tmp.zig:8:1: error: '@Frame(rangeSum)' depends on itself +// tmp.zig:15:33: note: when analyzing type '@Frame(rangeSum)' here +// tmp.zig:26:25: note: when analyzing type '@Frame(rangeSumIndirect)' here diff --git a/test/compile_errors/stage1/obj/indirect_struct_loop.zig b/test/compile_errors/stage1/obj/indirect_struct_loop.zig new file mode 100644 index 0000000000..903a1bda39 --- /dev/null +++ b/test/compile_errors/stage1/obj/indirect_struct_loop.zig @@ -0,0 +1,8 @@ +const A = struct { b : B, }; +const B = struct { c : C, }; +const C = struct { a : A, }; +export fn entry() usize { return @sizeOf(A); } + +// indirect struct loop +// +// tmp.zig:1:11: error: struct 'A' depends on itself diff --git a/test/compile_errors/stage1/obj/inferred_array_size_invalid_here.zig b/test/compile_errors/stage1/obj/inferred_array_size_invalid_here.zig new file mode 100644 index 0000000000..a45b6aa027 --- /dev/null +++ b/test/compile_errors/stage1/obj/inferred_array_size_invalid_here.zig @@ -0,0 +1,14 @@ +export fn entry() void { + const x = [_]u8; + _ = x; +} +export fn entry2() void { + const S = struct { a: *const [_]u8 }; + var a = .{ S{} }; + _ = a; +} + +// inferred array size invalid here +// +// tmp.zig:2:16: error: unable to infer array size +// tmp.zig:6:35: error: unable to infer array size diff --git a/test/compile_errors/stage1/obj/inferring_error_set_of_function_pointer.zig b/test/compile_errors/stage1/obj/inferring_error_set_of_function_pointer.zig new file mode 100644 index 0000000000..ead5afd248 --- /dev/null +++ b/test/compile_errors/stage1/obj/inferring_error_set_of_function_pointer.zig @@ -0,0 +1,7 @@ +comptime { + const z: ?fn()!void = null; +} + +// inferring error set of function pointer +// +// tmp.zig:2:19: error: function prototype may not have inferred error set diff --git a/test/compile_errors/stage1/obj/initializing_array_with_struct_syntax.zig b/test/compile_errors/stage1/obj/initializing_array_with_struct_syntax.zig new file mode 100644 index 0000000000..15412ac5ab --- /dev/null +++ b/test/compile_errors/stage1/obj/initializing_array_with_struct_syntax.zig @@ -0,0 +1,8 @@ +export fn entry() void { + const x = [_]u8{ .y = 2 }; + _ = x; +} + +// initializing array with struct syntax +// +// tmp.zig:2:15: error: initializing array with struct syntax diff --git a/test/compile_errors/stage1/obj/instantiating_an_undefined_value_for_an_invalid_struct_that_contains_itself.zig b/test/compile_errors/stage1/obj/instantiating_an_undefined_value_for_an_invalid_struct_that_contains_itself.zig new file mode 100644 index 0000000000..c39908c9b5 --- /dev/null +++ b/test/compile_errors/stage1/obj/instantiating_an_undefined_value_for_an_invalid_struct_that_contains_itself.zig @@ -0,0 +1,13 @@ +const Foo = struct { + x: Foo, +}; + +var foo: Foo = undefined; + +export fn entry() usize { + return @sizeOf(@TypeOf(foo.x)); +} + +// instantiating an undefined value for an invalid struct that contains itself +// +// tmp.zig:1:13: error: struct 'Foo' depends on itself diff --git a/test/compile_errors/stage1/obj/intToPtr_with_misaligned_address.zig b/test/compile_errors/stage1/obj/intToPtr_with_misaligned_address.zig new file mode 100644 index 0000000000..a04f318f0c --- /dev/null +++ b/test/compile_errors/stage1/obj/intToPtr_with_misaligned_address.zig @@ -0,0 +1,8 @@ +pub fn main() void { + var y = @intToPtr([*]align(4) u8, 5); + _ = y; +} + +// intToPtr with misaligned address +// +// tmp.zig:2:13: error: pointer type '[*]align(4) u8' requires aligned address diff --git a/test/compile_errors/stage1/obj/int_to_err_global_invalid_number.zig b/test/compile_errors/stage1/obj/int_to_err_global_invalid_number.zig new file mode 100644 index 0000000000..180da60ab2 --- /dev/null +++ b/test/compile_errors/stage1/obj/int_to_err_global_invalid_number.zig @@ -0,0 +1,13 @@ +const Set1 = error{ + A, + B, +}; +comptime { + var x: u16 = 3; + var y = @intToError(x); + _ = y; +} + +// int to err global invalid number +// +// tmp.zig:7:13: error: integer value 3 represents no error diff --git a/test/compile_errors/stage1/obj/int_to_err_non_global_invalid_number.zig b/test/compile_errors/stage1/obj/int_to_err_non_global_invalid_number.zig new file mode 100644 index 0000000000..a6627891d0 --- /dev/null +++ b/test/compile_errors/stage1/obj/int_to_err_non_global_invalid_number.zig @@ -0,0 +1,17 @@ +const Set1 = error{ + A, + B, +}; +const Set2 = error{ + A, + C, +}; +comptime { + var x = @errorToInt(Set1.B); + var y = @errSetCast(Set2, @intToError(x)); + _ = y; +} + +// int to err non global invalid number +// +// tmp.zig:11:13: error: error.B not a member of error set 'Set2' diff --git a/test/compile_errors/stage1/obj/int_to_ptr_of_0_bits.zig b/test/compile_errors/stage1/obj/int_to_ptr_of_0_bits.zig new file mode 100644 index 0000000000..7047600c1b --- /dev/null +++ b/test/compile_errors/stage1/obj/int_to_ptr_of_0_bits.zig @@ -0,0 +1,9 @@ +export fn foo() void { + var x: usize = 0x1000; + var y: *void = @intToPtr(*void, x); + _ = y; +} + +// int to ptr of 0 bits +// +// tmp.zig:3:30: error: type '*void' has 0 bits and cannot store information diff --git a/test/compile_errors/stage1/obj/integer_cast_truncates_bits.zig b/test/compile_errors/stage1/obj/integer_cast_truncates_bits.zig new file mode 100644 index 0000000000..a5c8036152 --- /dev/null +++ b/test/compile_errors/stage1/obj/integer_cast_truncates_bits.zig @@ -0,0 +1,29 @@ +export fn entry1() void { + const spartan_count: u16 = 300; + const byte = @intCast(u8, spartan_count); + _ = byte; +} +export fn entry2() void { + const spartan_count: u16 = 300; + const byte: u8 = spartan_count; + _ = byte; +} +export fn entry3() void { + var spartan_count: u16 = 300; + var byte: u8 = spartan_count; + _ = byte; +} +export fn entry4() void { + var signed: i8 = -1; + var unsigned: u64 = signed; + _ = unsigned; +} + +// integer cast truncates bits +// +// tmp.zig:3:18: error: cast from 'u16' to 'u8' truncates bits +// tmp.zig:8:22: error: integer value 300 cannot be coerced to type 'u8' +// tmp.zig:13:20: error: expected type 'u8', found 'u16' +// tmp.zig:13:20: note: unsigned 8-bit int cannot represent all possible unsigned 16-bit values +// tmp.zig:18:25: error: expected type 'u64', found 'i8' +// tmp.zig:18:25: note: unsigned 64-bit int cannot represent all possible signed 8-bit values diff --git a/test/compile_errors/stage1/obj/integer_overflow_error.zig b/test/compile_errors/stage1/obj/integer_overflow_error.zig new file mode 100644 index 0000000000..568cc5034b --- /dev/null +++ b/test/compile_errors/stage1/obj/integer_overflow_error.zig @@ -0,0 +1,6 @@ +const x : u8 = 300; +export fn entry() usize { return @sizeOf(@TypeOf(x)); } + +// integer overflow error +// +// tmp.zig:1:16: error: integer value 300 cannot be coerced to type 'u8' diff --git a/test/compile_errors/stage1/obj/integer_underflow_error.zig b/test/compile_errors/stage1/obj/integer_underflow_error.zig new file mode 100644 index 0000000000..01171589d9 --- /dev/null +++ b/test/compile_errors/stage1/obj/integer_underflow_error.zig @@ -0,0 +1,7 @@ +export fn entry() void { + _ = @intToPtr(*anyopaque, ~@as(usize, @import("std").math.maxInt(usize)) - 1); +} + +// integer underflow error +// +// :2:78: error: operation caused overflow diff --git a/test/compile_errors/stage1/obj/invalid_break_expression.zig b/test/compile_errors/stage1/obj/invalid_break_expression.zig new file mode 100644 index 0000000000..b6d27d6ea5 --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_break_expression.zig @@ -0,0 +1,7 @@ +export fn f() void { + break; +} + +// invalid break expression +// +// tmp.zig:2:5: error: break expression outside loop diff --git a/test/compile_errors/stage1/obj/invalid_builtin_fn.zig b/test/compile_errors/stage1/obj/invalid_builtin_fn.zig new file mode 100644 index 0000000000..e10baf5965 --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_builtin_fn.zig @@ -0,0 +1,7 @@ +fn f() @bogus(foo) { +} +export fn entry() void { _ = f(); } + +// invalid builtin fn +// +// tmp.zig:1:8: error: invalid builtin function: '@bogus' diff --git a/test/compile_errors/stage1/obj/invalid_cast_from_integral_type_to_enum.zig b/test/compile_errors/stage1/obj/invalid_cast_from_integral_type_to_enum.zig new file mode 100644 index 0000000000..476a4929ef --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_cast_from_integral_type_to_enum.zig @@ -0,0 +1,15 @@ +const E = enum(usize) { One, Two }; + +export fn entry() void { + foo(1); +} + +fn foo(x: usize) void { + switch (x) { + E.One => {}, + } +} + +// invalid cast from integral type to enum +// +// tmp.zig:9:10: error: expected type 'usize', found 'E' diff --git a/test/compile_errors/stage1/obj/invalid_comparison_for_function_pointers.zig b/test/compile_errors/stage1/obj/invalid_comparison_for_function_pointers.zig new file mode 100644 index 0000000000..f7827ed0e9 --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_comparison_for_function_pointers.zig @@ -0,0 +1,8 @@ +fn foo() void {} +const invalid = foo > foo; + +export fn entry() usize { return @sizeOf(@TypeOf(invalid)); } + +// invalid comparison for function pointers +// +// tmp.zig:2:21: error: operator not allowed for type 'fn() void' diff --git a/test/compile_errors/stage1/obj/invalid_continue_expression.zig b/test/compile_errors/stage1/obj/invalid_continue_expression.zig new file mode 100644 index 0000000000..9bd40c516a --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_continue_expression.zig @@ -0,0 +1,7 @@ +export fn f() void { + continue; +} + +// invalid continue expression +// +// tmp.zig:2:5: error: continue expression outside loop diff --git a/test/compile_errors/stage1/obj/invalid_deref_on_switch_target.zig b/test/compile_errors/stage1/obj/invalid_deref_on_switch_target.zig new file mode 100644 index 0000000000..47dc0a52c1 --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_deref_on_switch_target.zig @@ -0,0 +1,15 @@ +comptime { + var tile = Tile.Empty; + switch (tile.*) { + Tile.Empty => {}, + Tile.Filled => {}, + } +} +const Tile = enum { + Empty, + Filled, +}; + +// invalid deref on switch target +// +// tmp.zig:3:17: error: attempt to dereference non-pointer type 'Tile' diff --git a/test/compile_errors/stage1/obj/invalid_empty_unicode_escape.zig b/test/compile_errors/stage1/obj/invalid_empty_unicode_escape.zig new file mode 100644 index 0000000000..d8853110a4 --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_empty_unicode_escape.zig @@ -0,0 +1,7 @@ +export fn entry() void { + const a = '\u{}'; +} + +// invalid empty unicode escape +// +// tmp.zig:2:19: error: empty unicode escape sequence diff --git a/test/compile_errors/stage1/obj/invalid_exponent_in_float_literal-1.zig b/test/compile_errors/stage1/obj/invalid_exponent_in_float_literal-1.zig new file mode 100644 index 0000000000..4f13de2a62 --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_exponent_in_float_literal-1.zig @@ -0,0 +1,9 @@ +fn main() void { + var bad: f128 = 0x1.0p1ab1; + _ = bad; +} + +// invalid exponent in float literal - 1 +// +// tmp.zig:2:21: error: expected expression, found 'invalid bytes' +// tmp.zig:2:28: note: invalid byte: 'a' diff --git a/test/compile_errors/stage1/obj/invalid_exponent_in_float_literal-2.zig b/test/compile_errors/stage1/obj/invalid_exponent_in_float_literal-2.zig new file mode 100644 index 0000000000..f612d8c510 --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_exponent_in_float_literal-2.zig @@ -0,0 +1,9 @@ +fn main() void { + var bad: f128 = 0x1.0p50F; + _ = bad; +} + +// invalid exponent in float literal - 2 +// +// tmp.zig:2:21: error: expected expression, found 'invalid bytes' +// tmp.zig:2:29: note: invalid byte: 'F' diff --git a/test/compile_errors/stage1/obj/invalid_field_access_in_comptime.zig b/test/compile_errors/stage1/obj/invalid_field_access_in_comptime.zig new file mode 100644 index 0000000000..e8395b5e7a --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_field_access_in_comptime.zig @@ -0,0 +1,5 @@ +comptime { var x = doesnt_exist.whatever; _ = x; } + +// invalid field access in comptime +// +// tmp.zig:1:20: error: use of undeclared identifier 'doesnt_exist' diff --git a/test/compile_errors/stage1/obj/invalid_field_in_struct_value_expression.zig b/test/compile_errors/stage1/obj/invalid_field_in_struct_value_expression.zig new file mode 100644 index 0000000000..41511f0d0a --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_field_in_struct_value_expression.zig @@ -0,0 +1,17 @@ +const A = struct { + x : i32, + y : i32, + z : i32, +}; +export fn f() void { + const a = A { + .z = 4, + .y = 2, + .foo = 42, + }; + _ = a; +} + +// invalid field in struct value expression +// +// tmp.zig:10:9: error: no member named 'foo' in struct 'A' diff --git a/test/compile_errors/stage1/obj/invalid_float_literal.zig b/test/compile_errors/stage1/obj/invalid_float_literal.zig new file mode 100644 index 0000000000..5d9a26032f --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_float_literal.zig @@ -0,0 +1,11 @@ +const std = @import("std"); + +pub fn main() void { + var bad_float :f32 = 0.0; + bad_float = bad_float + .20; + std.debug.assert(bad_float < 1.0); +} + +// invalid float literal +// +// tmp.zig:5:29: error: expected expression, found '.' diff --git a/test/compile_errors/stage1/obj/invalid_legacy_unicode_escape.zig b/test/compile_errors/stage1/obj/invalid_legacy_unicode_escape.zig new file mode 100644 index 0000000000..58e1390345 --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_legacy_unicode_escape.zig @@ -0,0 +1,8 @@ +export fn entry() void { + const a = '\U1234'; +} + +// invalid legacy unicode escape +// +// tmp.zig:2:15: error: expected expression, found 'invalid bytes' +// tmp.zig:2:18: note: invalid byte: '1' diff --git a/test/compile_errors/stage1/obj/invalid_maybe_type.zig b/test/compile_errors/stage1/obj/invalid_maybe_type.zig new file mode 100644 index 0000000000..9edc313526 --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_maybe_type.zig @@ -0,0 +1,7 @@ +export fn f() void { + if (true) |x| { _ = x; } +} + +// invalid maybe type +// +// tmp.zig:2:9: error: expected optional type, found 'bool' diff --git a/test/compile_errors/stage1/obj/invalid_member_of_builtin_enum.zig b/test/compile_errors/stage1/obj/invalid_member_of_builtin_enum.zig new file mode 100644 index 0000000000..32888ff84b --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_member_of_builtin_enum.zig @@ -0,0 +1,9 @@ +const builtin = @import("std").builtin; +export fn entry() void { + const foo = builtin.Mode.x86; + _ = foo; +} + +// invalid member of builtin enum +// +// tmp.zig:3:29: error: container 'std.builtin.Mode' has no member called 'x86' diff --git a/test/compile_errors/stage1/obj/invalid_multiple_dereferences.zig b/test/compile_errors/stage1/obj/invalid_multiple_dereferences.zig new file mode 100644 index 0000000000..bdf5ccb228 --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_multiple_dereferences.zig @@ -0,0 +1,17 @@ +export fn a() void { + var box = Box{ .field = 0 }; + box.*.field = 1; +} +export fn b() void { + var box = Box{ .field = 0 }; + var boxPtr = &box; + boxPtr.*.*.field = 1; +} +pub const Box = struct { + field: i32, +}; + +// invalid multiple dereferences +// +// tmp.zig:3:8: error: attempt to dereference non-pointer type 'Box' +// tmp.zig:8:13: error: attempt to dereference non-pointer type 'Box' diff --git a/test/compile_errors/stage1/obj/invalid_optional_type_in_extern_struct.zig b/test/compile_errors/stage1/obj/invalid_optional_type_in_extern_struct.zig new file mode 100644 index 0000000000..17d9477abf --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_optional_type_in_extern_struct.zig @@ -0,0 +1,8 @@ +const stroo = extern struct { + moo: ?[*c]u8, +}; +export fn testf(fluff: *stroo) void { _ = fluff; } + +// invalid optional type in extern struct +// +// tmp.zig:2:5: error: extern structs cannot contain fields of type '?[*c]u8' diff --git a/test/compile_errors/stage1/obj/invalid_pointer_for_var_type.zig b/test/compile_errors/stage1/obj/invalid_pointer_for_var_type.zig new file mode 100644 index 0000000000..599aef54f2 --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_pointer_for_var_type.zig @@ -0,0 +1,11 @@ +extern fn ext() usize; +var bytes: [ext()]u8 = undefined; +export fn f() void { + for (bytes) |*b, i| { + b.* = @as(u8, i); + } +} + +// invalid pointer for var type +// +// tmp.zig:2:13: error: unable to evaluate constant expression diff --git a/test/compile_errors/stage1/obj/invalid_pointer_syntax.zig b/test/compile_errors/stage1/obj/invalid_pointer_syntax.zig new file mode 100644 index 0000000000..d4b68200b6 --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_pointer_syntax.zig @@ -0,0 +1,7 @@ +export fn foo() void { + var guid: *:0 const u8 = undefined; +} + +// invalid pointer syntax +// +// tmp.zig:2:16: error: expected type expression, found ':' diff --git a/test/compile_errors/stage1/obj/invalid_shift_amount_error.zig b/test/compile_errors/stage1/obj/invalid_shift_amount_error.zig new file mode 100644 index 0000000000..f4fe1cb2ff --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_shift_amount_error.zig @@ -0,0 +1,9 @@ +const x : u8 = 2; +fn f() u16 { + return x << 8; +} +export fn entry() u16 { return f(); } + +// invalid shift amount error +// +// tmp.zig:3:17: error: integer value 8 cannot be coerced to type 'u3' diff --git a/test/compile_errors/stage1/obj/invalid_struct_field.zig b/test/compile_errors/stage1/obj/invalid_struct_field.zig new file mode 100644 index 0000000000..2d85914907 --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_struct_field.zig @@ -0,0 +1,17 @@ +const A = struct { x : i32, }; +export fn f() void { + var a : A = undefined; + a.foo = 1; + const y = a.bar; + _ = y; +} +export fn g() void { + var a : A = undefined; + const y = a.bar; + _ = y; +} + +// invalid struct field +// +// tmp.zig:4:6: error: no member named 'foo' in struct 'A' +// tmp.zig:10:16: error: no member named 'bar' in struct 'A' diff --git a/test/compile_errors/stage1/obj/invalid_suspend_in_exported_function.zig b/test/compile_errors/stage1/obj/invalid_suspend_in_exported_function.zig new file mode 100644 index 0000000000..da808563a5 --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_suspend_in_exported_function.zig @@ -0,0 +1,13 @@ +export fn entry() void { + var frame = async func(); + var result = await frame; + _ = result; +} +fn func() void { + suspend {} +} + +// invalid suspend in exported function +// +// tmp.zig:1:1: error: function with calling convention 'C' cannot be async +// tmp.zig:3:18: note: await here is a suspend point diff --git a/test/compile_errors/stage1/obj/invalid_type.zig b/test/compile_errors/stage1/obj/invalid_type.zig new file mode 100644 index 0000000000..0307300517 --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_type.zig @@ -0,0 +1,6 @@ +fn a() bogus {} +export fn entry() void { _ = a(); } + +// invalid type +// +// tmp.zig:1:8: error: use of undeclared identifier 'bogus' diff --git a/test/compile_errors/stage1/obj/invalid_type_used_in_array_type.zig b/test/compile_errors/stage1/obj/invalid_type_used_in_array_type.zig new file mode 100644 index 0000000000..26f0e6a7db --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_type_used_in_array_type.zig @@ -0,0 +1,12 @@ +const Item = struct { + field: SomeNonexistentType, +}; +var items: [100]Item = undefined; +export fn entry() void { + const a = items[0]; + _ = a; +} + +// invalid type used in array type +// +// tmp.zig:2:12: error: use of undeclared identifier 'SomeNonexistentType' diff --git a/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-1.zig b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-1.zig new file mode 100644 index 0000000000..5cea540104 --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-1.zig @@ -0,0 +1,9 @@ +fn main() void { + var bad: f128 = 0._0; + _ = bad; +} + +// invalid underscore placement in float literal - 1 +// +// tmp.zig:2:21: error: expected expression, found 'invalid bytes' +// tmp.zig:2:23: note: invalid byte: '_' diff --git a/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-10.zig b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-10.zig new file mode 100644 index 0000000000..d789579a2b --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-10.zig @@ -0,0 +1,9 @@ +fn main() void { + var bad: f128 = 1.0__0e-1; + _ = bad; +} + +// invalid underscore placement in float literal - 10 +// +// tmp.zig:2:21: error: expected expression, found 'invalid bytes' +// tmp.zig:2:25: note: invalid byte: '_' diff --git a/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-11.zig b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-11.zig new file mode 100644 index 0000000000..197b114090 --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-11.zig @@ -0,0 +1,9 @@ +fn main() void { + var bad: f128 = 1.0e-1__0; + _ = bad; +} + +// invalid underscore placement in float literal - 11 +// +// tmp.zig:2:21: error: expected expression, found 'invalid bytes' +// tmp.zig:2:28: note: invalid byte: '_' diff --git a/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-12.zig b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-12.zig new file mode 100644 index 0000000000..1d25c9f4b4 --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-12.zig @@ -0,0 +1,9 @@ +fn main() void { + var bad: f128 = 0_x0.0; + _ = bad; +} + +// invalid underscore placement in float literal - 12 +// +// tmp.zig:2:21: error: expected expression, found 'invalid bytes' +// tmp.zig:2:23: note: invalid byte: 'x' diff --git a/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-13.zig b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-13.zig new file mode 100644 index 0000000000..c3de75ed32 --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-13.zig @@ -0,0 +1,9 @@ +fn main() void { + var bad: f128 = 0x_0.0; + _ = bad; +} + +// invalid underscore placement in float literal - 13 +// +// tmp.zig:2:21: error: expected expression, found 'invalid bytes' +// tmp.zig:2:23: note: invalid byte: '_' diff --git a/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-14.zig b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-14.zig new file mode 100644 index 0000000000..cbb967e926 --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-14.zig @@ -0,0 +1,9 @@ +fn main() void { + var bad: f128 = 0x0.0_p1; + _ = bad; +} + +// invalid underscore placement in float literal - 14 +// +// tmp.zig:2:21: error: expected expression, found 'invalid bytes' +// tmp.zig:2:27: note: invalid byte: 'p' diff --git a/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-2.zig b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-2.zig new file mode 100644 index 0000000000..e83c1b420b --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-2.zig @@ -0,0 +1,9 @@ +fn main() void { + var bad: f128 = 0_.0; + _ = bad; +} + +// invalid underscore placement in float literal - 2 +// +// tmp.zig:2:21: error: expected expression, found 'invalid bytes' +// tmp.zig:2:23: note: invalid byte: '.' diff --git a/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-3.zig b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-3.zig new file mode 100644 index 0000000000..f9ca8e0d7c --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-3.zig @@ -0,0 +1,9 @@ +fn main() void { + var bad: f128 = 0.0_; + _ = bad; +} + +// invalid underscore placement in float literal - 3 +// +// tmp.zig:2:21: error: expected expression, found 'invalid bytes' +// tmp.zig:2:25: note: invalid byte: ';' diff --git a/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-4.zig b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-4.zig new file mode 100644 index 0000000000..20e8d3692e --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-4.zig @@ -0,0 +1,9 @@ +fn main() void { + var bad: f128 = 1.0e_1; + _ = bad; +} + +// invalid underscore placement in float literal - 4 +// +// tmp.zig:2:21: error: expected expression, found 'invalid bytes' +// tmp.zig:2:25: note: invalid byte: '_' diff --git a/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-5.zig b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-5.zig new file mode 100644 index 0000000000..3719f54e06 --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-5.zig @@ -0,0 +1,9 @@ +fn main() void { + var bad: f128 = 1.0e+_1; + _ = bad; +} + +// invalid underscore placement in float literal - 5 +// +// tmp.zig:2:21: error: expected expression, found 'invalid bytes' +// tmp.zig:2:26: note: invalid byte: '_' diff --git a/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-6.zig b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-6.zig new file mode 100644 index 0000000000..64a439538a --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-6.zig @@ -0,0 +1,9 @@ +fn main() void { + var bad: f128 = 1.0e-_1; + _ = bad; +} + +// invalid underscore placement in float literal - 6 +// +// tmp.zig:2:21: error: expected expression, found 'invalid bytes' +// tmp.zig:2:26: note: invalid byte: '_' diff --git a/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-7.zig b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-7.zig new file mode 100644 index 0000000000..311b27339a --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-7.zig @@ -0,0 +1,9 @@ +fn main() void { + var bad: f128 = 1.0e-1_; + _ = bad; +} + +// invalid underscore placement in float literal - 7 +// +// tmp.zig:2:21: error: expected expression, found 'invalid bytes' +// tmp.zig:2:28: note: invalid byte: ';' diff --git a/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-9.zig b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-9.zig new file mode 100644 index 0000000000..ecd1149f22 --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-9.zig @@ -0,0 +1,9 @@ +fn main() void { + var bad: f128 = 1__0.0e-1; + _ = bad; +} + +// invalid underscore placement in float literal - 9 +// +// tmp.zig:2:21: error: expected expression, found 'invalid bytes' +// tmp.zig:2:23: note: invalid byte: '_' diff --git a/test/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-1.zig b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-1.zig new file mode 100644 index 0000000000..47da090745 --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-1.zig @@ -0,0 +1,9 @@ +fn main() void { + var bad: u128 = 0010_; + _ = bad; +} + +// invalid underscore placement in int literal - 1 +// +// tmp.zig:2:21: error: expected expression, found 'invalid bytes' +// tmp.zig:2:26: note: invalid byte: ';' diff --git a/test/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-2.zig b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-2.zig new file mode 100644 index 0000000000..bb230daa9e --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-2.zig @@ -0,0 +1,9 @@ +fn main() void { + var bad: u128 = 0b0010_; + _ = bad; +} + +// invalid underscore placement in int literal - 2 +// +// tmp.zig:2:21: error: expected expression, found 'invalid bytes' +// tmp.zig:2:28: note: invalid byte: ';' diff --git a/test/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-3.zig b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-3.zig new file mode 100644 index 0000000000..7808b6ee4d --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-3.zig @@ -0,0 +1,9 @@ +fn main() void { + var bad: u128 = 0o0010_; + _ = bad; +} + +// invalid underscore placement in int literal - 3 +// +// tmp.zig:2:21: error: expected expression, found 'invalid bytes' +// tmp.zig:2:28: note: invalid byte: ';' diff --git a/test/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-4.zig b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-4.zig new file mode 100644 index 0000000000..51ddb3d061 --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-4.zig @@ -0,0 +1,9 @@ +fn main() void { + var bad: u128 = 0x0010_; + _ = bad; +} + +// invalid underscore placement in int literal - 4 +// +// tmp.zig:2:21: error: expected expression, found 'invalid bytes' +// tmp.zig:2:28: note: invalid byte: ';' diff --git a/test/compile_errors/stage1/obj/invalid_union_field_access_in_comptime.zig b/test/compile_errors/stage1/obj/invalid_union_field_access_in_comptime.zig new file mode 100644 index 0000000000..d570dca0b9 --- /dev/null +++ b/test/compile_errors/stage1/obj/invalid_union_field_access_in_comptime.zig @@ -0,0 +1,13 @@ +const Foo = union { + Bar: u8, + Baz: void, +}; +comptime { + var foo = Foo {.Baz = {}}; + const bar_val = foo.Bar; + _ = bar_val; +} + +// invalid union field access in comptime +// +// tmp.zig:7:24: error: accessing union field 'Bar' while field 'Baz' is set diff --git a/test/compile_errors/stage1/obj/issue_2032_compile_diagnostic_string_for_top_level_decl_type.zig b/test/compile_errors/stage1/obj/issue_2032_compile_diagnostic_string_for_top_level_decl_type.zig new file mode 100644 index 0000000000..9e353a4d38 --- /dev/null +++ b/test/compile_errors/stage1/obj/issue_2032_compile_diagnostic_string_for_top_level_decl_type.zig @@ -0,0 +1,8 @@ +export fn entry() void { + var foo: u32 = @This(){}; + _ = foo; +} + +// compile diagnostic string for top level decl type (issue 2032) +// +// tmp.zig:2:27: error: type 'u32' does not support array initialization diff --git a/test/compile_errors/stage1/obj/issue_2687_coerce_from_undefined_array_pointer_to_slice.zig b/test/compile_errors/stage1/obj/issue_2687_coerce_from_undefined_array_pointer_to_slice.zig new file mode 100644 index 0000000000..7c125b85ce --- /dev/null +++ b/test/compile_errors/stage1/obj/issue_2687_coerce_from_undefined_array_pointer_to_slice.zig @@ -0,0 +1,25 @@ +export fn foo1() void { + const a: *[1]u8 = undefined; + var b: []u8 = a; + _ = b; +} +export fn foo2() void { + comptime { + var a: *[1]u8 = undefined; + var b: []u8 = a; + _ = b; + } +} +export fn foo3() void { + comptime { + const a: *[1]u8 = undefined; + var b: []u8 = a; + _ = b; + } +} + +// issue #2687: coerce from undefined array pointer to slice +// +// tmp.zig:3:19: error: use of undefined value here causes undefined behavior +// tmp.zig:9:23: error: use of undefined value here causes undefined behavior +// tmp.zig:16:23: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/issue_3818_bitcast_from_parray-slice_to_u16.zig b/test/compile_errors/stage1/obj/issue_3818_bitcast_from_parray-slice_to_u16.zig new file mode 100644 index 0000000000..1c9d9cd1b1 --- /dev/null +++ b/test/compile_errors/stage1/obj/issue_3818_bitcast_from_parray-slice_to_u16.zig @@ -0,0 +1,15 @@ +export fn foo1() void { + var bytes = [_]u8{1, 2}; + const word: u16 = @bitCast(u16, bytes[0..]); + _ = word; +} +export fn foo2() void { + var bytes: []const u8 = &[_]u8{1, 2}; + const word: u16 = @bitCast(u16, bytes); + _ = word; +} + +// issue #3818: bitcast from parray/slice to u16 +// +// tmp.zig:3:42: error: unable to @bitCast from pointer type '*[2]u8' +// tmp.zig:8:32: error: destination type 'u16' has size 2 but source type '[]const u8' has size 16 diff --git a/test/compile_errors/stage1/obj/issue_4207_coerce_from_non-terminated-slice_to_terminated-pointer.zig b/test/compile_errors/stage1/obj/issue_4207_coerce_from_non-terminated-slice_to_terminated-pointer.zig new file mode 100644 index 0000000000..bfb0595cce --- /dev/null +++ b/test/compile_errors/stage1/obj/issue_4207_coerce_from_non-terminated-slice_to_terminated-pointer.zig @@ -0,0 +1,9 @@ +export fn foo() [*:0]const u8 { + var buffer: [64]u8 = undefined; + return buffer[0..]; +} + +// issue #4207: coerce from non-terminated-slice to terminated-pointer +// +// :3:18: error: expected type '[*:0]const u8', found '*[64]u8' +// :3:18: note: destination pointer requires a terminating '0' sentinel diff --git a/test/compile_errors/stage1/obj/issue_5221_invalid_struct_init_type_referenced_by_typeInfo_and_passed_into_function.zig b/test/compile_errors/stage1/obj/issue_5221_invalid_struct_init_type_referenced_by_typeInfo_and_passed_into_function.zig new file mode 100644 index 0000000000..aa839bc72c --- /dev/null +++ b/test/compile_errors/stage1/obj/issue_5221_invalid_struct_init_type_referenced_by_typeInfo_and_passed_into_function.zig @@ -0,0 +1,14 @@ +fn ignore(comptime param: anytype) void {_ = param;} + +export fn foo() void { + const MyStruct = struct { + wrong_type: []u8 = "foo", + }; + + comptime ignore(@typeInfo(MyStruct).Struct.fields[0]); +} + +// issue #5221: invalid struct init type referenced by @typeInfo and passed into function +// +// :5:28: error: cannot cast pointer to array literal to slice type '[]u8' +// :5:28: note: cast discards const qualifier diff --git a/test/compile_errors/stage1/obj/issue_5618_coercion_of_optional_anyopaque_to_anyopaque_must_fail.zig b/test/compile_errors/stage1/obj/issue_5618_coercion_of_optional_anyopaque_to_anyopaque_must_fail.zig new file mode 100644 index 0000000000..daa8a91f40 --- /dev/null +++ b/test/compile_errors/stage1/obj/issue_5618_coercion_of_optional_anyopaque_to_anyopaque_must_fail.zig @@ -0,0 +1,9 @@ +export fn foo() void { + var u: ?*anyopaque = null; + var v: *anyopaque = undefined; + v = u; +} + +// Issue #5618: coercion of ?*anyopaque to *anyopaque must fail. +// +// tmp.zig:4:9: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type '*anyopaque', found '?*anyopaque' diff --git a/test/compile_errors/stage1/obj/issue_7810-comptime_slice-len_increment_beyond_bounds.zig b/test/compile_errors/stage1/obj/issue_7810-comptime_slice-len_increment_beyond_bounds.zig new file mode 100644 index 0000000000..533ac928b4 --- /dev/null +++ b/test/compile_errors/stage1/obj/issue_7810-comptime_slice-len_increment_beyond_bounds.zig @@ -0,0 +1,12 @@ +export fn foo_slice_len_increment_beyond_bounds() void { + comptime { + var buf_storage: [8]u8 = undefined; + var buf: []const u8 = buf_storage[0..]; + buf.len += 1; + buf[8] = 42; + } +} + +// comptime slice-len increment beyond bounds +// +// :6:12: error: out of bounds slice diff --git a/test/compile_errors/stage1/obj/issue_9346_return_outside_of_function_scope.zig b/test/compile_errors/stage1/obj/issue_9346_return_outside_of_function_scope.zig new file mode 100644 index 0000000000..6be92e2ee8 --- /dev/null +++ b/test/compile_errors/stage1/obj/issue_9346_return_outside_of_function_scope.zig @@ -0,0 +1,5 @@ +pub const empty = return 1; + +// issue #9346: return outside of function scope +// +// tmp.zig:1:19: error: 'return' outside function scope diff --git a/test/compile_errors/stage1/obj/labeled_break_not_found.zig b/test/compile_errors/stage1/obj/labeled_break_not_found.zig new file mode 100644 index 0000000000..0f4632d74d --- /dev/null +++ b/test/compile_errors/stage1/obj/labeled_break_not_found.zig @@ -0,0 +1,11 @@ +export fn entry() void { + blah: while (true) { + while (true) { + break :outer; + } + } +} + +// labeled break not found +// +// tmp.zig:4:20: error: label not found: 'outer' diff --git a/test/compile_errors/stage1/obj/labeled_continue_not_found.zig b/test/compile_errors/stage1/obj/labeled_continue_not_found.zig new file mode 100644 index 0000000000..8f95a0fce1 --- /dev/null +++ b/test/compile_errors/stage1/obj/labeled_continue_not_found.zig @@ -0,0 +1,12 @@ +export fn entry() void { + var i: usize = 0; + blah: while (i < 10) : (i += 1) { + while (true) { + continue :outer; + } + } +} + +// labeled continue not found +// +// tmp.zig:5:23: error: label not found: 'outer' diff --git a/test/compile_errors/stage1/obj/lazy_pointer_with_undefined_element_type.zig b/test/compile_errors/stage1/obj/lazy_pointer_with_undefined_element_type.zig new file mode 100644 index 0000000000..47b271a05e --- /dev/null +++ b/test/compile_errors/stage1/obj/lazy_pointer_with_undefined_element_type.zig @@ -0,0 +1,10 @@ +export fn foo() void { + comptime var T: type = undefined; + const S = struct { x: *T }; + const I = @typeInfo(S); + _ = I; +} + +// lazy pointer with undefined element type +// +// :3:28: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/load_too_many_bytes_from_comptime_reinterpreted_pointer.zig b/test/compile_errors/stage1/obj/load_too_many_bytes_from_comptime_reinterpreted_pointer.zig new file mode 100644 index 0000000000..2c5e1c7327 --- /dev/null +++ b/test/compile_errors/stage1/obj/load_too_many_bytes_from_comptime_reinterpreted_pointer.zig @@ -0,0 +1,11 @@ +export fn entry() void { + const float: f32 = 5.99999999999994648725e-01; + const float_ptr = &float; + const int_ptr = @ptrCast(*const i64, float_ptr); + const int_val = int_ptr.*; + _ = int_val; +} + +// load too many bytes from comptime reinterpreted pointer +// +// tmp.zig:5:28: error: attempt to read 8 bytes from pointer to f32 which is 4 bytes diff --git a/test/compile_errors/stage1/obj/load_vector_pointer_with_unknown_runtime_index.zig b/test/compile_errors/stage1/obj/load_vector_pointer_with_unknown_runtime_index.zig new file mode 100644 index 0000000000..fe28fa9102 --- /dev/null +++ b/test/compile_errors/stage1/obj/load_vector_pointer_with_unknown_runtime_index.zig @@ -0,0 +1,15 @@ +export fn entry() void { + var v: @import("std").meta.Vector(4, i32) = [_]i32{ 1, 5, 3, undefined }; + + var i: u32 = 0; + var x = loadv(&v[i]); + _ = x; +} + +fn loadv(ptr: anytype) i32 { + return ptr.*; +} + +// load vector pointer with unknown runtime index +// +// tmp.zig:10:12: error: unable to determine vector element index of type '*align(16:0:4:?) i32 diff --git a/test/compile_errors/stage1/obj/local_shadows_global_that_occurs_later.zig b/test/compile_errors/stage1/obj/local_shadows_global_that_occurs_later.zig new file mode 100644 index 0000000000..2265a34f18 --- /dev/null +++ b/test/compile_errors/stage1/obj/local_shadows_global_that_occurs_later.zig @@ -0,0 +1,10 @@ +pub fn main() void { + var foo = true; + _ = foo; +} +fn foo() void {} + +// local shadows global that occurs later +// +// tmp.zig:2:9: error: local shadows declaration of 'foo' +// tmp.zig:5:1: note: declared here diff --git a/test/compile_errors/stage1/obj/local_variable_redeclaration.zig b/test/compile_errors/stage1/obj/local_variable_redeclaration.zig new file mode 100644 index 0000000000..2367963edb --- /dev/null +++ b/test/compile_errors/stage1/obj/local_variable_redeclaration.zig @@ -0,0 +1,9 @@ +export fn f() void { + const a : i32 = 0; + var a = 0; +} + +// local variable redeclaration +// +// tmp.zig:3:9: error: redeclaration of local constant 'a' +// tmp.zig:2:11: note: previous declaration here diff --git a/test/compile_errors/stage1/obj/local_variable_redeclares_parameter.zig b/test/compile_errors/stage1/obj/local_variable_redeclares_parameter.zig new file mode 100644 index 0000000000..e624e14e31 --- /dev/null +++ b/test/compile_errors/stage1/obj/local_variable_redeclares_parameter.zig @@ -0,0 +1,9 @@ +fn f(a : i32) void { + const a = 0; +} +export fn entry() void { f(1); } + +// local variable redeclares parameter +// +// tmp.zig:2:11: error: redeclaration of function parameter 'a' +// tmp.zig:1:6: note: previous declaration here diff --git a/test/compile_errors/stage1/obj/local_variable_shadowing_global.zig b/test/compile_errors/stage1/obj/local_variable_shadowing_global.zig new file mode 100644 index 0000000000..c824cb3df7 --- /dev/null +++ b/test/compile_errors/stage1/obj/local_variable_shadowing_global.zig @@ -0,0 +1,12 @@ +const Foo = struct {}; +const Bar = struct {}; + +export fn entry() void { + var Bar : i32 = undefined; + _ = Bar; +} + +// local variable shadowing global +// +// tmp.zig:5:9: error: local shadows declaration of 'Bar' +// tmp.zig:2:1: note: declared here diff --git a/test/compile_errors/stage1/obj/locally_shadowing_a_primitive_type.zig b/test/compile_errors/stage1/obj/locally_shadowing_a_primitive_type.zig new file mode 100644 index 0000000000..457cea418c --- /dev/null +++ b/test/compile_errors/stage1/obj/locally_shadowing_a_primitive_type.zig @@ -0,0 +1,10 @@ +export fn foo() void { + const u8 = u16; + const a: u8 = 300; + _ = a; +} + +// locally shadowing a primitive type +// +// tmp.zig:2:11: error: name shadows primitive 'u8' +// tmp.zig:2:11: note: consider using @"u8" to disambiguate diff --git a/test/compile_errors/stage1/obj/main_function_with_bogus_args_type.zig b/test/compile_errors/stage1/obj/main_function_with_bogus_args_type.zig new file mode 100644 index 0000000000..3954c4b846 --- /dev/null +++ b/test/compile_errors/stage1/obj/main_function_with_bogus_args_type.zig @@ -0,0 +1,5 @@ +pub fn main(args: [][]bogus) !void {_ = args;} + +// main function with bogus args type +// +// tmp.zig:1:23: error: use of undeclared identifier 'bogus' diff --git a/test/compile_errors/stage1/obj/method_call_with_first_arg_type_primitive.zig b/test/compile_errors/stage1/obj/method_call_with_first_arg_type_primitive.zig new file mode 100644 index 0000000000..9763e84fba --- /dev/null +++ b/test/compile_errors/stage1/obj/method_call_with_first_arg_type_primitive.zig @@ -0,0 +1,19 @@ +const Foo = struct { + x: i32, + + fn init(x: i32) Foo { + return Foo { + .x = x, + }; + } +}; + +export fn f() void { + const derp = Foo.init(3); + + derp.init(); +} + +// method call with first arg type primitive +// +// tmp.zig:14:5: error: expected type 'i32', found 'Foo' diff --git a/test/compile_errors/stage1/obj/method_call_with_first_arg_type_wrong_container.zig b/test/compile_errors/stage1/obj/method_call_with_first_arg_type_wrong_container.zig new file mode 100644 index 0000000000..ccbc7e32e3 --- /dev/null +++ b/test/compile_errors/stage1/obj/method_call_with_first_arg_type_wrong_container.zig @@ -0,0 +1,28 @@ +pub const List = struct { + len: usize, + allocator: *Allocator, + + pub fn init(allocator: *Allocator) List { + return List { + .len = 0, + .allocator = allocator, + }; + } +}; + +pub var global_allocator = Allocator { + .field = 1234, +}; + +pub const Allocator = struct { + field: i32, +}; + +export fn foo() void { + var x = List.init(&global_allocator); + x.init(); +} + +// method call with first arg type wrong container +// +// tmp.zig:23:5: error: expected type '*Allocator', found '*List' diff --git a/test/compile_errors/stage1/obj/missing_boolean_switch_value.zig b/test/compile_errors/stage1/obj/missing_boolean_switch_value.zig new file mode 100644 index 0000000000..63a12c4e6f --- /dev/null +++ b/test/compile_errors/stage1/obj/missing_boolean_switch_value.zig @@ -0,0 +1,17 @@ +comptime { + const x = switch (true) { + true => false, + }; + _ = x; +} +comptime { + const x = switch (true) { + false => true, + }; + _ = x; +} + +// missing boolean switch value +// +// tmp.zig:2:15: error: switch must handle all possibilities +// tmp.zig:8:15: error: switch must handle all possibilities diff --git a/test/compile_errors/stage1/obj/missing_const_in_slice_with_nested_array_type.zig b/test/compile_errors/stage1/obj/missing_const_in_slice_with_nested_array_type.zig new file mode 100644 index 0000000000..4f552284d7 --- /dev/null +++ b/test/compile_errors/stage1/obj/missing_const_in_slice_with_nested_array_type.zig @@ -0,0 +1,16 @@ +const Geo3DTex2D = struct { vertices: [][2]f32 }; +pub fn getGeo3DTex2D() Geo3DTex2D { + return Geo3DTex2D{ + .vertices = [_][2]f32{ + [_]f32{ -0.5, -0.5}, + }, + }; +} +export fn entry() void { + var geo_data = getGeo3DTex2D(); + _ = geo_data; +} + +// missing const in slice with nested array type +// +// tmp.zig:4:30: error: array literal requires address-of operator (&) to coerce to slice type '[][2]f32' diff --git a/test/compile_errors/stage1/obj/missing_else_clause.zig b/test/compile_errors/stage1/obj/missing_else_clause.zig new file mode 100644 index 0000000000..28adfd21e8 --- /dev/null +++ b/test/compile_errors/stage1/obj/missing_else_clause.zig @@ -0,0 +1,14 @@ +fn f(b: bool) void { + const x : i32 = if (b) h: { break :h 1; }; + _ = x; +} +fn g(b: bool) void { + const y = if (b) h: { break :h @as(i32, 1); }; + _ = y; +} +export fn entry() void { f(true); g(true); } + +// missing else clause +// +// tmp.zig:2:21: error: expected type 'i32', found 'void' +// tmp.zig:6:15: error: incompatible types: 'i32' and 'void' diff --git a/test/compile_errors/stage1/obj/missing_field_in_struct_value_expression.zig b/test/compile_errors/stage1/obj/missing_field_in_struct_value_expression.zig new file mode 100644 index 0000000000..bea4021a5a --- /dev/null +++ b/test/compile_errors/stage1/obj/missing_field_in_struct_value_expression.zig @@ -0,0 +1,18 @@ +const A = struct { + x : i32, + y : i32, + z : i32, +}; +export fn f() void { + // we want the error on the '{' not the 'A' because + // the A could be a complicated expression + const a = A { + .z = 4, + .y = 2, + }; + _ = a; +} + +// missing field in struct value expression +// +// tmp.zig:9:17: error: missing field: 'x' diff --git a/test/compile_errors/stage1/obj/missing_function_call_param.zig b/test/compile_errors/stage1/obj/missing_function_call_param.zig new file mode 100644 index 0000000000..45a7259814 --- /dev/null +++ b/test/compile_errors/stage1/obj/missing_function_call_param.zig @@ -0,0 +1,29 @@ +const Foo = struct { + a: i32, + b: i32, + + fn member_a(foo: *const Foo) i32 { + return foo.a; + } + fn member_b(foo: *const Foo) i32 { + return foo.b; + } +}; + +const member_fn_type = @TypeOf(Foo.member_a); +const members = [_]member_fn_type { + Foo.member_a, + Foo.member_b, +}; + +fn f(foo: *const Foo, index: usize) void { + const result = members[index](); + _ = foo; + _ = result; +} + +export fn entry() usize { return @sizeOf(@TypeOf(f)); } + +// missing function call param +// +// tmp.zig:20:34: error: expected 1 argument(s), found 0 diff --git a/test/compile_errors/stage1/obj/missing_function_name.zig b/test/compile_errors/stage1/obj/missing_function_name.zig new file mode 100644 index 0000000000..194f5eb6a8 --- /dev/null +++ b/test/compile_errors/stage1/obj/missing_function_name.zig @@ -0,0 +1,6 @@ +fn () void {} +export fn entry() usize { return @sizeOf(@TypeOf(f)); } + +// missing function name +// +// tmp.zig:1:1: error: missing function name diff --git a/test/compile_errors/stage1/obj/missing_param_name.zig b/test/compile_errors/stage1/obj/missing_param_name.zig new file mode 100644 index 0000000000..1c379dd245 --- /dev/null +++ b/test/compile_errors/stage1/obj/missing_param_name.zig @@ -0,0 +1,6 @@ +fn f(i32) void {} +export fn entry() usize { return @sizeOf(@TypeOf(f)); } + +// missing param name +// +// tmp.zig:1:6: error: missing parameter name diff --git a/test/compile_errors/stage1/obj/missing_parameter_name_of_generic_function.zig b/test/compile_errors/stage1/obj/missing_parameter_name_of_generic_function.zig new file mode 100644 index 0000000000..3a3ccd28a8 --- /dev/null +++ b/test/compile_errors/stage1/obj/missing_parameter_name_of_generic_function.zig @@ -0,0 +1,9 @@ +fn dump(anytype) void {} +export fn entry() void { + var a: u8 = 9; + dump(a); +} + +// missing parameter name of generic function +// +// tmp.zig:1:9: error: missing parameter name diff --git a/test/compile_errors/stage1/obj/missing_result_type_for_phi_node.zig b/test/compile_errors/stage1/obj/missing_result_type_for_phi_node.zig new file mode 100644 index 0000000000..3ef99e0859 --- /dev/null +++ b/test/compile_errors/stage1/obj/missing_result_type_for_phi_node.zig @@ -0,0 +1,10 @@ +fn foo() !void { + return anyerror.Foo; +} +export fn entry() void { + foo() catch 0; +} + +// missing result type for phi node +// +// tmp.zig:5:17: error: integer value 0 cannot be coerced to type 'void' diff --git a/test/compile_errors/stage1/obj/misspelled_type_with_pointer_only_reference.zig b/test/compile_errors/stage1/obj/misspelled_type_with_pointer_only_reference.zig new file mode 100644 index 0000000000..6b3f647c02 --- /dev/null +++ b/test/compile_errors/stage1/obj/misspelled_type_with_pointer_only_reference.zig @@ -0,0 +1,35 @@ +const JasonHM = u8; +const JasonList = *JsonNode; + +const JsonOA = union(enum) { + JSONArray: JsonList, + JSONObject: JasonHM, +}; + +const JsonType = union(enum) { + JSONNull: void, + JSONInteger: isize, + JSONDouble: f64, + JSONBool: bool, + JSONString: []u8, + JSONArray: void, + JSONObject: void, +}; + +pub const JsonNode = struct { + kind: JsonType, + jobject: ?JsonOA, +}; + +fn foo() void { + var jll: JasonList = undefined; + jll.init(1234); + var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} }; + _ = jd; +} + +export fn entry() usize { return @sizeOf(@TypeOf(foo)); } + +// misspelled type with pointer only reference +// +// tmp.zig:5:16: error: use of undeclared identifier 'JsonList' diff --git a/test/compile_errors/stage1/obj/mod_assign_on_undefined_value.zig b/test/compile_errors/stage1/obj/mod_assign_on_undefined_value.zig new file mode 100644 index 0000000000..3165970d44 --- /dev/null +++ b/test/compile_errors/stage1/obj/mod_assign_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: i64 = undefined; + a %= a; +} + +// mod assign on undefined value +// +// tmp.zig:3:5: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/mod_on_undefined_value.zig b/test/compile_errors/stage1/obj/mod_on_undefined_value.zig new file mode 100644 index 0000000000..3b33f6ed82 --- /dev/null +++ b/test/compile_errors/stage1/obj/mod_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: i64 = undefined; + _ = a % a; +} + +// mod on undefined value +// +// tmp.zig:3:9: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/mul_overflow_in_function_evaluation.zig b/test/compile_errors/stage1/obj/mul_overflow_in_function_evaluation.zig new file mode 100644 index 0000000000..ea8eea5ab5 --- /dev/null +++ b/test/compile_errors/stage1/obj/mul_overflow_in_function_evaluation.zig @@ -0,0 +1,10 @@ +const y = mul(300, 6000); +fn mul(a: u16, b: u16) u16 { + return a * b; +} + +export fn entry() usize { return @sizeOf(@TypeOf(y)); } + +// mul overflow in function evaluation +// +// tmp.zig:3:14: error: operation caused overflow diff --git a/test/compile_errors/stage1/obj/mult_assign_on_undefined_value.zig b/test/compile_errors/stage1/obj/mult_assign_on_undefined_value.zig new file mode 100644 index 0000000000..4617c5f62b --- /dev/null +++ b/test/compile_errors/stage1/obj/mult_assign_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: i64 = undefined; + a *= a; +} + +// mult assign on undefined value +// +// tmp.zig:3:5: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/mult_on_undefined_value.zig b/test/compile_errors/stage1/obj/mult_on_undefined_value.zig new file mode 100644 index 0000000000..836b59e19d --- /dev/null +++ b/test/compile_errors/stage1/obj/mult_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: i64 = undefined; + _ = a * a; +} + +// mult on undefined value +// +// tmp.zig:3:9: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/mult_wrap_assign_on_undefined_value.zig b/test/compile_errors/stage1/obj/mult_wrap_assign_on_undefined_value.zig new file mode 100644 index 0000000000..38bd38bf79 --- /dev/null +++ b/test/compile_errors/stage1/obj/mult_wrap_assign_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: i64 = undefined; + a *%= a; +} + +// mult wrap assign on undefined value +// +// tmp.zig:3:5: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/mult_wrap_on_undefined_value.zig b/test/compile_errors/stage1/obj/mult_wrap_on_undefined_value.zig new file mode 100644 index 0000000000..0c0ca46540 --- /dev/null +++ b/test/compile_errors/stage1/obj/mult_wrap_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: i64 = undefined; + _ = a *% a; +} + +// mult wrap on undefined value +// +// tmp.zig:3:9: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/multiple_function_definitions.zig b/test/compile_errors/stage1/obj/multiple_function_definitions.zig new file mode 100644 index 0000000000..c4efefce8d --- /dev/null +++ b/test/compile_errors/stage1/obj/multiple_function_definitions.zig @@ -0,0 +1,8 @@ +fn a() void {} +fn a() void {} +export fn entry() void { a(); } + +// multiple function definitions +// +// tmp.zig:2:1: error: redeclaration of 'a' +// tmp.zig:1:1: note: other declaration here diff --git a/test/compile_errors/stage1/obj/negate_on_undefined_value.zig b/test/compile_errors/stage1/obj/negate_on_undefined_value.zig new file mode 100644 index 0000000000..7e7e392104 --- /dev/null +++ b/test/compile_errors/stage1/obj/negate_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: i64 = undefined; + _ = -a; +} + +// negate on undefined value +// +// tmp.zig:3:10: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/negate_wrap_on_undefined_value.zig b/test/compile_errors/stage1/obj/negate_wrap_on_undefined_value.zig new file mode 100644 index 0000000000..f49c6eac34 --- /dev/null +++ b/test/compile_errors/stage1/obj/negate_wrap_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: i64 = undefined; + _ = -%a; +} + +// negate wrap on undefined value +// +// tmp.zig:3:11: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/negation_overflow_in_function_evaluation.zig b/test/compile_errors/stage1/obj/negation_overflow_in_function_evaluation.zig new file mode 100644 index 0000000000..ca69b6fb5d --- /dev/null +++ b/test/compile_errors/stage1/obj/negation_overflow_in_function_evaluation.zig @@ -0,0 +1,10 @@ +const y = neg(-128); +fn neg(x: i8) i8 { + return -x; +} + +export fn entry() usize { return @sizeOf(@TypeOf(y)); } + +// negation overflow in function evaluation +// +// tmp.zig:3:12: error: negation caused overflow diff --git a/test/compile_errors/stage1/obj/nested_error_set_mismatch.zig b/test/compile_errors/stage1/obj/nested_error_set_mismatch.zig new file mode 100644 index 0000000000..6c677049df --- /dev/null +++ b/test/compile_errors/stage1/obj/nested_error_set_mismatch.zig @@ -0,0 +1,18 @@ +const NextError = error{NextError}; +const OtherError = error{OutOfMemory}; + +export fn entry() void { + const a: ?NextError!i32 = foo(); + _ = a; +} + +fn foo() ?OtherError!i32 { + return null; +} + +// nested error set mismatch +// +// tmp.zig:5:34: error: expected type '?NextError!i32', found '?OtherError!i32' +// tmp.zig:5:34: note: optional type child 'OtherError!i32' cannot cast into optional type child 'NextError!i32' +// tmp.zig:5:34: note: error set 'OtherError' cannot cast into error set 'NextError' +// tmp.zig:2:26: note: 'error.OutOfMemory' not a member of destination error set diff --git a/test/compile_errors/stage1/obj/no_else_prong_on_switch_on_global_error_set.zig b/test/compile_errors/stage1/obj/no_else_prong_on_switch_on_global_error_set.zig new file mode 100644 index 0000000000..7de3f189f0 --- /dev/null +++ b/test/compile_errors/stage1/obj/no_else_prong_on_switch_on_global_error_set.zig @@ -0,0 +1,12 @@ +export fn entry() void { + foo(error.A); +} +fn foo(a: anyerror) void { + switch (a) { + error.A => {}, + } +} + +// no else prong on switch on global error set +// +// tmp.zig:5:5: error: else prong required when switching on type 'anyerror' diff --git a/test/compile_errors/stage1/obj/noalias_on_non_pointer_param.zig b/test/compile_errors/stage1/obj/noalias_on_non_pointer_param.zig new file mode 100644 index 0000000000..3419dc8c99 --- /dev/null +++ b/test/compile_errors/stage1/obj/noalias_on_non_pointer_param.zig @@ -0,0 +1,6 @@ +fn f(noalias x: i32) void { _ = x; } +export fn entry() void { f(1234); } + +// noalias on non pointer param +// +// tmp.zig:1:6: error: noalias on non-pointer parameter diff --git a/test/compile_errors/stage1/obj/non-async_function_pointer_eventually_is_inferred_to_become_async.zig b/test/compile_errors/stage1/obj/non-async_function_pointer_eventually_is_inferred_to_become_async.zig new file mode 100644 index 0000000000..93391daaef --- /dev/null +++ b/test/compile_errors/stage1/obj/non-async_function_pointer_eventually_is_inferred_to_become_async.zig @@ -0,0 +1,13 @@ +export fn a() void { + var non_async_fn: fn () void = undefined; + non_async_fn = func; +} +fn func() void { + suspend {} +} + +// non-async function pointer eventually is inferred to become async +// +// tmp.zig:5:1: error: 'func' cannot be async +// tmp.zig:3:20: note: required to be non-async here +// tmp.zig:6:5: note: suspends here diff --git a/test/compile_errors/stage1/obj/non-const_expression_function_call_with_struct_return_value_outside_function.zig b/test/compile_errors/stage1/obj/non-const_expression_function_call_with_struct_return_value_outside_function.zig new file mode 100644 index 0000000000..d6a463e71f --- /dev/null +++ b/test/compile_errors/stage1/obj/non-const_expression_function_call_with_struct_return_value_outside_function.zig @@ -0,0 +1,15 @@ +const Foo = struct { + x: i32, +}; +const a = get_it(); +fn get_it() Foo { + global_side_effect = true; + return Foo {.x = 13}; +} +var global_side_effect = false; + +export fn entry() usize { return @sizeOf(@TypeOf(a)); } + +// non-const expression function call with struct return value outside function +// +// tmp.zig:6:26: error: unable to evaluate constant expression diff --git a/test/compile_errors/stage1/obj/non-const_expression_in_struct_literal_outside_function.zig b/test/compile_errors/stage1/obj/non-const_expression_in_struct_literal_outside_function.zig new file mode 100644 index 0000000000..ef7b1309c3 --- /dev/null +++ b/test/compile_errors/stage1/obj/non-const_expression_in_struct_literal_outside_function.zig @@ -0,0 +1,11 @@ +const Foo = struct { + x: i32, +}; +const a = Foo {.x = get_it()}; +extern fn get_it() i32; + +export fn entry() usize { return @sizeOf(@TypeOf(a)); } + +// non-const expression in struct literal outside function +// +// tmp.zig:4:21: error: unable to evaluate constant expression diff --git a/test/compile_errors/stage1/obj/non-const_switch_number_literal.zig b/test/compile_errors/stage1/obj/non-const_switch_number_literal.zig new file mode 100644 index 0000000000..aecaa7dcb6 --- /dev/null +++ b/test/compile_errors/stage1/obj/non-const_switch_number_literal.zig @@ -0,0 +1,15 @@ +export fn foo() void { + const x = switch (bar()) { + 1, 2 => 1, + 3, 4 => 2, + else => 3, + }; + _ = x; +} +fn bar() i32 { + return 2; +} + +// non-const switch number literal +// +// tmp.zig:5:17: error: cannot store runtime value in type 'comptime_int' diff --git a/test/compile_errors/stage1/obj/non-const_variables_of_things_that_require_const_variables.zig b/test/compile_errors/stage1/obj/non-const_variables_of_things_that_require_const_variables.zig new file mode 100644 index 0000000000..0598e04e4b --- /dev/null +++ b/test/compile_errors/stage1/obj/non-const_variables_of_things_that_require_const_variables.zig @@ -0,0 +1,49 @@ +export fn entry1() void { + var m2 = &2; + _ = m2; +} +export fn entry2() void { + var a = undefined; + _ = a; +} +export fn entry3() void { + var b = 1; + _ = b; +} +export fn entry4() void { + var c = 1.0; + _ = c; +} +export fn entry5() void { + var d = null; + _ = d; +} +export fn entry6(opaque_: *Opaque) void { + var e = opaque_.*; + _ = e; +} +export fn entry7() void { + var f = i32; + _ = f; +} +export fn entry8() void { + var h = (Foo {}).bar; + _ = h; +} +const Opaque = opaque {}; +const Foo = struct { + fn bar(self: *const Foo) void {_ = self;} +}; + +// non-const variables of things that require const variables +// +// tmp.zig:2:4: error: variable of type '*const comptime_int' must be const or comptime +// tmp.zig:6:4: error: variable of type '@Type(.Undefined)' must be const or comptime +// tmp.zig:10:4: error: variable of type 'comptime_int' must be const or comptime +// tmp.zig:10:4: note: to modify this variable at runtime, it must be given an explicit fixed-size number type +// tmp.zig:14:4: error: variable of type 'comptime_float' must be const or comptime +// tmp.zig:14:4: note: to modify this variable at runtime, it must be given an explicit fixed-size number type +// tmp.zig:18:4: error: variable of type '@Type(.Null)' must be const or comptime +// tmp.zig:22:4: error: variable of type 'Opaque' not allowed +// tmp.zig:26:4: error: variable of type 'type' must be const or comptime +// tmp.zig:30:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime diff --git a/test/compile_errors/stage1/obj/non-enum_tag_type_passed_to_union.zig b/test/compile_errors/stage1/obj/non-enum_tag_type_passed_to_union.zig new file mode 100644 index 0000000000..3161f16b28 --- /dev/null +++ b/test/compile_errors/stage1/obj/non-enum_tag_type_passed_to_union.zig @@ -0,0 +1,11 @@ +const Foo = union(u32) { + A: i32, +}; +export fn entry() void { + const x = @typeInfo(Foo).Union.tag_type.?; + _ = x; +} + +// non-enum tag type passed to union +// +// tmp.zig:1:19: error: expected enum tag type, found 'u32' diff --git a/test/compile_errors/stage1/obj/non-extern_function_with_var_args.zig b/test/compile_errors/stage1/obj/non-extern_function_with_var_args.zig new file mode 100644 index 0000000000..02b99383c1 --- /dev/null +++ b/test/compile_errors/stage1/obj/non-extern_function_with_var_args.zig @@ -0,0 +1,8 @@ +fn foo(args: ...) void {} +export fn entry() void { + foo(); +} + +// non-extern function with var args +// +// tmp.zig:1:14: error: expected type expression, found '...' diff --git a/test/compile_errors/stage1/obj/non-inline_for_loop_on_a_type_that_requires_comptime.zig b/test/compile_errors/stage1/obj/non-inline_for_loop_on_a_type_that_requires_comptime.zig new file mode 100644 index 0000000000..9190e7cea8 --- /dev/null +++ b/test/compile_errors/stage1/obj/non-inline_for_loop_on_a_type_that_requires_comptime.zig @@ -0,0 +1,12 @@ +const Foo = struct { + name: []const u8, + T: type, +}; +export fn entry() void { + const xx: [2]Foo = undefined; + for (xx) |f| { _ = f;} +} + +// non-inline for loop on a type that requires comptime +// +// tmp.zig:7:5: error: values of type 'Foo' must be comptime known, but index value is runtime known diff --git a/test/compile_errors/stage1/obj/non-integer_tag_type_to_automatic_union_enum.zig b/test/compile_errors/stage1/obj/non-integer_tag_type_to_automatic_union_enum.zig new file mode 100644 index 0000000000..a84ca36f6c --- /dev/null +++ b/test/compile_errors/stage1/obj/non-integer_tag_type_to_automatic_union_enum.zig @@ -0,0 +1,11 @@ +const Foo = union(enum(f32)) { + A: i32, +}; +export fn entry() void { + const x = @typeInfo(Foo).Union.tag_type.?; + _ = x; +} + +// non-integer tag type to automatic union enum +// +// tmp.zig:1:24: error: expected integer tag type, found 'f32' diff --git a/test/compile_errors/stage1/obj/non-pure_function_returns_type.zig b/test/compile_errors/stage1/obj/non-pure_function_returns_type.zig new file mode 100644 index 0000000000..0925207b9f --- /dev/null +++ b/test/compile_errors/stage1/obj/non-pure_function_returns_type.zig @@ -0,0 +1,22 @@ +var a: u32 = 0; +pub fn List(comptime T: type) type { + a += 1; + return SmallList(T, 8); +} + +pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) type { + return struct { + items: []T, + length: usize, + prealloc_items: [STATIC_SIZE]T, + }; +} + +export fn function_with_return_type_type() void { + var list: List(i32) = undefined; + list.length = 10; +} + +// non-pure function returns type +// +// tmp.zig:3:7: error: unable to evaluate constant expression diff --git a/test/compile_errors/stage1/obj/non_async_function_pointer_passed_to_asyncCall.zig b/test/compile_errors/stage1/obj/non_async_function_pointer_passed_to_asyncCall.zig new file mode 100644 index 0000000000..73c4fd96ca --- /dev/null +++ b/test/compile_errors/stage1/obj/non_async_function_pointer_passed_to_asyncCall.zig @@ -0,0 +1,10 @@ +export fn entry() void { + var ptr = afunc; + var bytes: [100]u8 align(16) = undefined; + _ = @asyncCall(&bytes, {}, ptr, .{}); +} +fn afunc() void { } + +// non async function pointer passed to @asyncCall +// +// tmp.zig:4:32: error: expected async function, found 'fn() void' diff --git a/test/compile_errors/stage1/obj/non_compile_time_array_concatenation.zig b/test/compile_errors/stage1/obj/non_compile_time_array_concatenation.zig new file mode 100644 index 0000000000..c119cc03f7 --- /dev/null +++ b/test/compile_errors/stage1/obj/non_compile_time_array_concatenation.zig @@ -0,0 +1,9 @@ +fn f() []u8 { + return s ++ "foo"; +} +var s: [10]u8 = undefined; +export fn entry() usize { return @sizeOf(@TypeOf(f)); } + +// non compile time array concatenation +// +// tmp.zig:2:12: error: unable to evaluate constant expression diff --git a/test/compile_errors/stage1/obj/non_constant_expression_in_array_size.zig b/test/compile_errors/stage1/obj/non_constant_expression_in_array_size.zig new file mode 100644 index 0000000000..fe28921265 --- /dev/null +++ b/test/compile_errors/stage1/obj/non_constant_expression_in_array_size.zig @@ -0,0 +1,12 @@ +const Foo = struct { + y: [get()]u8, +}; +var global_var: usize = 1; +fn get() usize { return global_var; } + +export fn entry() usize { return @sizeOf(@TypeOf(Foo)); } + +// non constant expression in array size +// +// tmp.zig:5:25: error: cannot store runtime value in compile time variable +// tmp.zig:2:12: note: called from here diff --git a/test/compile_errors/stage1/obj/non_error_sets_used_in_merge_error_sets_operator.zig b/test/compile_errors/stage1/obj/non_error_sets_used_in_merge_error_sets_operator.zig new file mode 100644 index 0000000000..c600bea8b0 --- /dev/null +++ b/test/compile_errors/stage1/obj/non_error_sets_used_in_merge_error_sets_operator.zig @@ -0,0 +1,15 @@ +export fn foo() void { + const Errors = u8 || u16; + _ = Errors; +} +export fn bar() void { + const Errors = error{} || u16; + _ = Errors; +} + +// non error sets used in merge error sets operator +// +// tmp.zig:2:20: error: expected error set type, found type 'u8' +// tmp.zig:2:23: note: `||` merges error sets; `or` performs boolean OR +// tmp.zig:6:31: error: expected error set type, found type 'u16' +// tmp.zig:6:28: note: `||` merges error sets; `or` performs boolean OR diff --git a/test/compile_errors/stage1/obj/non_float_passed_to_floatToInt.zig b/test/compile_errors/stage1/obj/non_float_passed_to_floatToInt.zig new file mode 100644 index 0000000000..cad658ba5a --- /dev/null +++ b/test/compile_errors/stage1/obj/non_float_passed_to_floatToInt.zig @@ -0,0 +1,8 @@ +export fn entry() void { + const x = @floatToInt(i32, @as(i32, 54)); + _ = x; +} + +// non float passed to @floatToInt +// +// tmp.zig:2:32: error: expected float type, found 'i32' diff --git a/test/compile_errors/stage1/obj/non_int_passed_to_intToFloat.zig b/test/compile_errors/stage1/obj/non_int_passed_to_intToFloat.zig new file mode 100644 index 0000000000..8b985c2b0b --- /dev/null +++ b/test/compile_errors/stage1/obj/non_int_passed_to_intToFloat.zig @@ -0,0 +1,8 @@ +export fn entry() void { + const x = @intToFloat(f32, 1.1); + _ = x; +} + +// non int passed to @intToFloat +// +// tmp.zig:2:32: error: expected int type, found 'comptime_float' diff --git a/test/compile_errors/stage1/obj/non_pointer_given_to_ptrToInt.zig b/test/compile_errors/stage1/obj/non_pointer_given_to_ptrToInt.zig new file mode 100644 index 0000000000..1d4d3087da --- /dev/null +++ b/test/compile_errors/stage1/obj/non_pointer_given_to_ptrToInt.zig @@ -0,0 +1,7 @@ +export fn entry(x: i32) usize { + return @ptrToInt(x); +} + +// non pointer given to @ptrToInt +// +// tmp.zig:2:22: error: expected pointer, found 'i32' diff --git a/test/compile_errors/stage1/obj/normal_string_with_newline.zig b/test/compile_errors/stage1/obj/normal_string_with_newline.zig new file mode 100644 index 0000000000..dafc041744 --- /dev/null +++ b/test/compile_errors/stage1/obj/normal_string_with_newline.zig @@ -0,0 +1,7 @@ +const foo = "a +b"; + +// normal string with newline +// +// tmp.zig:1:13: error: expected expression, found 'invalid bytes' +// tmp.zig:1:15: note: invalid byte: '\n' diff --git a/test/compile_errors/stage1/obj/offsetOf-bad_field_name.zig b/test/compile_errors/stage1/obj/offsetOf-bad_field_name.zig new file mode 100644 index 0000000000..3b301e2677 --- /dev/null +++ b/test/compile_errors/stage1/obj/offsetOf-bad_field_name.zig @@ -0,0 +1,10 @@ +const Foo = struct { + derp: i32, +}; +export fn foo() usize { + return @offsetOf(Foo, "a",); +} + +// @offsetOf - bad field name +// +// tmp.zig:5:27: error: struct 'Foo' has no field 'a' diff --git a/test/compile_errors/stage1/obj/offsetOf-non_struct.zig b/test/compile_errors/stage1/obj/offsetOf-non_struct.zig new file mode 100644 index 0000000000..173119407a --- /dev/null +++ b/test/compile_errors/stage1/obj/offsetOf-non_struct.zig @@ -0,0 +1,8 @@ +const Foo = i32; +export fn foo() usize { + return @offsetOf(Foo, "a",); +} + +// @offsetOf - non struct +// +// tmp.zig:3:22: error: expected struct type, found 'i32' diff --git a/test/compile_errors/stage1/obj/only_equality_binary_operator_allowed_for_error_sets.zig b/test/compile_errors/stage1/obj/only_equality_binary_operator_allowed_for_error_sets.zig new file mode 100644 index 0000000000..58512ef2a6 --- /dev/null +++ b/test/compile_errors/stage1/obj/only_equality_binary_operator_allowed_for_error_sets.zig @@ -0,0 +1,8 @@ +comptime { + const z = error.A > error.B; + _ = z; +} + +// only equality binary operator allowed for error sets +// +// tmp.zig:2:23: error: operator not allowed for errors diff --git a/test/compile_errors/stage1/obj/opaque_type_with_field.zig b/test/compile_errors/stage1/obj/opaque_type_with_field.zig new file mode 100644 index 0000000000..748d5c0736 --- /dev/null +++ b/test/compile_errors/stage1/obj/opaque_type_with_field.zig @@ -0,0 +1,9 @@ +const Opaque = opaque { foo: i32 }; +export fn entry() void { + const foo: ?*Opaque = null; + _ = foo; +} + +// opaque type with field +// +// tmp.zig:1:25: error: opaque types cannot have fields diff --git a/test/compile_errors/stage1/obj/optional_pointer_to_void_in_extern_struct.zig b/test/compile_errors/stage1/obj/optional_pointer_to_void_in_extern_struct.zig new file mode 100644 index 0000000000..f4ebb577d9 --- /dev/null +++ b/test/compile_errors/stage1/obj/optional_pointer_to_void_in_extern_struct.zig @@ -0,0 +1,12 @@ +const Foo = extern struct { + x: ?*const void, +}; +const Bar = extern struct { + foo: Foo, + y: i32, +}; +export fn entry(bar: *Bar) void {_ = bar;} + +// optional pointer to void in extern struct +// +// tmp.zig:2:5: error: extern structs cannot contain fields of type '?*const void' diff --git a/test/compile_errors/stage1/obj/or_on_undefined_value.zig b/test/compile_errors/stage1/obj/or_on_undefined_value.zig new file mode 100644 index 0000000000..ac636bff9e --- /dev/null +++ b/test/compile_errors/stage1/obj/or_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: bool = undefined; + _ = a or a; +} + +// or on undefined value +// +// tmp.zig:3:9: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/orelse_on_undefined_value.zig b/test/compile_errors/stage1/obj/orelse_on_undefined_value.zig new file mode 100644 index 0000000000..28e7c4b425 --- /dev/null +++ b/test/compile_errors/stage1/obj/orelse_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: ?bool = undefined; + _ = a orelse false; +} + +// orelse on undefined value +// +// tmp.zig:3:11: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/out_of_range_comptime_int_passed_to_floatToInt.zig b/test/compile_errors/stage1/obj/out_of_range_comptime_int_passed_to_floatToInt.zig new file mode 100644 index 0000000000..581bb58ffd --- /dev/null +++ b/test/compile_errors/stage1/obj/out_of_range_comptime_int_passed_to_floatToInt.zig @@ -0,0 +1,8 @@ +export fn entry() void { + const x = @floatToInt(i8, 200); + _ = x; +} + +// out of range comptime_int passed to @floatToInt +// +// tmp.zig:2:31: error: integer value 200 cannot be coerced to type 'i8' diff --git a/test/compile_errors/stage1/obj/overflow_in_enum_value_allocation.zig b/test/compile_errors/stage1/obj/overflow_in_enum_value_allocation.zig new file mode 100644 index 0000000000..5c737e06a2 --- /dev/null +++ b/test/compile_errors/stage1/obj/overflow_in_enum_value_allocation.zig @@ -0,0 +1,12 @@ +const Moo = enum(u8) { + Last = 255, + Over, +}; +pub fn main() void { + var y = Moo.Last; + _ = y; +} + +// overflow in enum value allocation +// +// tmp.zig:3:5: error: enumeration value 256 too large for type 'u8' diff --git a/test/compile_errors/stage1/obj/packed_union_given_enum_tag_type.zig b/test/compile_errors/stage1/obj/packed_union_given_enum_tag_type.zig new file mode 100644 index 0000000000..f0bc445295 --- /dev/null +++ b/test/compile_errors/stage1/obj/packed_union_given_enum_tag_type.zig @@ -0,0 +1,18 @@ +const Letter = enum { + A, + B, + C, +}; +const Payload = packed union(Letter) { + A: i32, + B: f64, + C: bool, +}; +export fn entry() void { + var a = Payload { .A = 1234 }; + _ = a; +} + +// packed union given enum tag type +// +// tmp.zig:6:30: error: packed union does not support enum tag type diff --git a/test/compile_errors/stage1/obj/packed_union_with_automatic_layout_field.zig b/test/compile_errors/stage1/obj/packed_union_with_automatic_layout_field.zig new file mode 100644 index 0000000000..4450531a5b --- /dev/null +++ b/test/compile_errors/stage1/obj/packed_union_with_automatic_layout_field.zig @@ -0,0 +1,16 @@ +const Foo = struct { + a: u32, + b: f32, +}; +const Payload = packed union { + A: Foo, + B: bool, +}; +export fn entry() void { + var a = Payload { .B = true }; + _ = a; +} + +// packed union with automatic layout field +// +// tmp.zig:6:5: error: non-packed, non-extern struct 'Foo' not allowed in packed union; no guaranteed in-memory representation diff --git a/test/compile_errors/stage1/obj/panic_called_at_compile_time.zig b/test/compile_errors/stage1/obj/panic_called_at_compile_time.zig new file mode 100644 index 0000000000..6dd32cdf59 --- /dev/null +++ b/test/compile_errors/stage1/obj/panic_called_at_compile_time.zig @@ -0,0 +1,9 @@ +export fn entry() void { + comptime { + @panic("aoeu",); + } +} + +// @panic called at compile time +// +// tmp.zig:3:9: error: encountered @panic at compile-time diff --git a/test/compile_errors/stage1/obj/parameter_redeclaration.zig b/test/compile_errors/stage1/obj/parameter_redeclaration.zig new file mode 100644 index 0000000000..01fc507afc --- /dev/null +++ b/test/compile_errors/stage1/obj/parameter_redeclaration.zig @@ -0,0 +1,8 @@ +fn f(a : i32, a : i32) void { +} +export fn entry() void { f(1, 2); } + +// parameter redeclaration +// +// tmp.zig:1:15: error: redeclaration of function parameter 'a' +// tmp.zig:1:6: note: previous declaration here diff --git a/test/compile_errors/stage1/obj/parameter_shadowing_global.zig b/test/compile_errors/stage1/obj/parameter_shadowing_global.zig new file mode 100644 index 0000000000..a58a0b93ce --- /dev/null +++ b/test/compile_errors/stage1/obj/parameter_shadowing_global.zig @@ -0,0 +1,10 @@ +const Foo = struct {}; +fn f(Foo: i32) void {} +export fn entry() void { + f(1234); +} + +// parameter shadowing global +// +// tmp.zig:2:6: error: local shadows declaration of 'Foo' +// tmp.zig:1:1: note: declared here diff --git a/test/compile_errors/stage1/obj/pass_const_ptr_to_mutable_ptr_fn.zig b/test/compile_errors/stage1/obj/pass_const_ptr_to_mutable_ptr_fn.zig new file mode 100644 index 0000000000..ff0057bb48 --- /dev/null +++ b/test/compile_errors/stage1/obj/pass_const_ptr_to_mutable_ptr_fn.zig @@ -0,0 +1,15 @@ +fn foo() bool { + const a = @as([]const u8, "a",); + const b = &a; + return ptrEql(b, b); +} +fn ptrEql(a: *[]const u8, b: *[]const u8) bool { + _ = a; _ = b; + return true; +} + +export fn entry() usize { return @sizeOf(@TypeOf(foo)); } + +// pass const ptr to mutable ptr fn +// +// tmp.zig:4:19: error: expected type '*[]const u8', found '*const []const u8' diff --git a/test/compile_errors/stage1/obj/passing_a_not-aligned-enough_pointer_to_cmpxchg.zig b/test/compile_errors/stage1/obj/passing_a_not-aligned-enough_pointer_to_cmpxchg.zig new file mode 100644 index 0000000000..40564998b7 --- /dev/null +++ b/test/compile_errors/stage1/obj/passing_a_not-aligned-enough_pointer_to_cmpxchg.zig @@ -0,0 +1,10 @@ +const AtomicOrder = @import("std").builtin.AtomicOrder; +export fn entry() bool { + var x: i32 align(1) = 1234; + while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) {} + return x == 5678; +} + +// passing a not-aligned-enough pointer to cmpxchg +// +// tmp.zig:4:32: error: expected type '*i32', found '*align(1) i32' diff --git a/test/compile_errors/stage1/obj/passing_an_under-aligned_function_pointer.zig b/test/compile_errors/stage1/obj/passing_an_under-aligned_function_pointer.zig new file mode 100644 index 0000000000..f6c0e52cc0 --- /dev/null +++ b/test/compile_errors/stage1/obj/passing_an_under-aligned_function_pointer.zig @@ -0,0 +1,11 @@ +export fn entry() void { + testImplicitlyDecreaseFnAlign(alignedSmall, 1234); +} +fn testImplicitlyDecreaseFnAlign(ptr: fn () align(8) i32, answer: i32) void { + if (ptr() != answer) unreachable; +} +fn alignedSmall() align(4) i32 { return 1234; } + +// passing an under-aligned function pointer +// +// tmp.zig:2:35: error: expected type 'fn() align(8) i32', found 'fn() align(4) i32' diff --git a/test/compile_errors/stage1/obj/peer_cast_then_implicit_cast_const_pointer_to_mutable_C_pointer.zig b/test/compile_errors/stage1/obj/peer_cast_then_implicit_cast_const_pointer_to_mutable_C_pointer.zig new file mode 100644 index 0000000000..78f072c0d0 --- /dev/null +++ b/test/compile_errors/stage1/obj/peer_cast_then_implicit_cast_const_pointer_to_mutable_C_pointer.zig @@ -0,0 +1,9 @@ +export fn func() void { + var strValue: [*c]u8 = undefined; + strValue = strValue orelse ""; +} + +// peer cast then implicit cast const pointer to mutable C pointer +// +// tmp.zig:3:32: error: expected type '[*c]u8', found '*const [0:0]u8' +// tmp.zig:3:32: note: cast discards const qualifier diff --git a/test/compile_errors/stage1/obj/pointer_arithmetic_on_pointer-to-array.zig b/test/compile_errors/stage1/obj/pointer_arithmetic_on_pointer-to-array.zig new file mode 100644 index 0000000000..b293ae2b32 --- /dev/null +++ b/test/compile_errors/stage1/obj/pointer_arithmetic_on_pointer-to-array.zig @@ -0,0 +1,10 @@ +export fn foo() void { + var x: [10]u8 = undefined; + var y = &x; + var z = y + 1; + _ = z; +} + +// pointer arithmetic on pointer-to-array +// +// tmp.zig:4:17: error: integer value 1 cannot be coerced to type '*[10]u8' diff --git a/test/compile_errors/stage1/obj/pointer_attributes_checked_when_coercing_pointer_to_anon_literal.zig b/test/compile_errors/stage1/obj/pointer_attributes_checked_when_coercing_pointer_to_anon_literal.zig new file mode 100644 index 0000000000..079844ac7f --- /dev/null +++ b/test/compile_errors/stage1/obj/pointer_attributes_checked_when_coercing_pointer_to_anon_literal.zig @@ -0,0 +1,22 @@ +comptime { + const c: [][]const u8 = &.{"hello", "world" }; + _ = c; +} +comptime { + const c: *[2][]const u8 = &.{"hello", "world" }; + _ = c; +} +const S = struct {a: u8 = 1, b: u32 = 2}; +comptime { + const c: *S = &.{}; + _ = c; +} + +// pointer attributes checked when coercing pointer to anon literal +// +// tmp.zig:2:31: error: cannot cast pointer to array literal to slice type '[][]const u8' +// tmp.zig:2:31: note: cast discards const qualifier +// tmp.zig:6:33: error: cannot cast pointer to array literal to '*[2][]const u8' +// tmp.zig:6:33: note: cast discards const qualifier +// tmp.zig:11:21: error: expected type '*S', found '*const struct:11:21' +// tmp.zig:11:21: note: cast discards const qualifier diff --git a/test/compile_errors/stage1/obj/pointer_to_noreturn.zig b/test/compile_errors/stage1/obj/pointer_to_noreturn.zig new file mode 100644 index 0000000000..3b945919fc --- /dev/null +++ b/test/compile_errors/stage1/obj/pointer_to_noreturn.zig @@ -0,0 +1,6 @@ +fn a() *noreturn {} +export fn entry() void { _ = a(); } + +// pointer to noreturn +// +// tmp.zig:1:9: error: pointer to noreturn not allowed diff --git a/test/compile_errors/stage1/obj/popCount-non-integer.zig b/test/compile_errors/stage1/obj/popCount-non-integer.zig new file mode 100644 index 0000000000..694b794927 --- /dev/null +++ b/test/compile_errors/stage1/obj/popCount-non-integer.zig @@ -0,0 +1,7 @@ +export fn entry(x: f32) u32 { + return @popCount(f32, x); +} + +// @popCount - non-integer +// +// tmp.zig:2:22: error: expected integer type, found 'f32' diff --git a/test/compile_errors/stage1/obj/prevent_bad_implicit_casting_of_anyframe_types.zig b/test/compile_errors/stage1/obj/prevent_bad_implicit_casting_of_anyframe_types.zig new file mode 100644 index 0000000000..14bdb9cb11 --- /dev/null +++ b/test/compile_errors/stage1/obj/prevent_bad_implicit_casting_of_anyframe_types.zig @@ -0,0 +1,22 @@ +export fn a() void { + var x: anyframe = undefined; + var y: anyframe->i32 = x; + _ = y; +} +export fn b() void { + var x: i32 = undefined; + var y: anyframe->i32 = x; + _ = y; +} +export fn c() void { + var x: @Frame(func) = undefined; + var y: anyframe->i32 = &x; + _ = y; +} +fn func() void {} + +// prevent bad implicit casting of anyframe types +// +// tmp.zig:3:28: error: expected type 'anyframe->i32', found 'anyframe' +// tmp.zig:8:28: error: expected type 'anyframe->i32', found 'i32' +// tmp.zig:13:29: error: expected type 'anyframe->i32', found '*@Frame(func)' diff --git a/test/compile_errors/stage1/obj/primitives_take_precedence_over_declarations.zig b/test/compile_errors/stage1/obj/primitives_take_precedence_over_declarations.zig new file mode 100644 index 0000000000..3517c07917 --- /dev/null +++ b/test/compile_errors/stage1/obj/primitives_take_precedence_over_declarations.zig @@ -0,0 +1,9 @@ +const @"u8" = u16; +export fn entry() void { + const a: u8 = 300; + _ = a; +} + +// primitives take precedence over declarations +// +// tmp.zig:3:19: error: integer value 300 cannot be coerced to type 'u8' diff --git a/test/compile_errors/stage1/obj/ptrCast_a_0_bit_type_to_a_non-_0_bit_type.zig b/test/compile_errors/stage1/obj/ptrCast_a_0_bit_type_to_a_non-_0_bit_type.zig new file mode 100644 index 0000000000..63d0656f21 --- /dev/null +++ b/test/compile_errors/stage1/obj/ptrCast_a_0_bit_type_to_a_non-_0_bit_type.zig @@ -0,0 +1,11 @@ +export fn entry() bool { + var x: u0 = 0; + const p = @ptrCast(?*u0, &x); + return p == null; +} + +// @ptrCast a 0 bit type to a non- 0 bit type +// +// tmp.zig:3:15: error: '*u0' and '?*u0' do not have the same in-memory representation +// tmp.zig:3:31: note: '*u0' has no in-memory bits +// tmp.zig:3:24: note: '?*u0' has in-memory bits diff --git a/test/compile_errors/stage1/obj/ptrCast_discards_const_qualifier.zig b/test/compile_errors/stage1/obj/ptrCast_discards_const_qualifier.zig new file mode 100644 index 0000000000..1517fd4bd8 --- /dev/null +++ b/test/compile_errors/stage1/obj/ptrCast_discards_const_qualifier.zig @@ -0,0 +1,9 @@ +export fn entry() void { + const x: i32 = 1234; + const y = @ptrCast(*i32, &x); + _ = y; +} + +// @ptrCast discards const qualifier +// +// tmp.zig:3:15: error: cast discards const qualifier diff --git a/test/compile_errors/stage1/obj/ptrToInt_0_to_non_optional_pointer.zig b/test/compile_errors/stage1/obj/ptrToInt_0_to_non_optional_pointer.zig new file mode 100644 index 0000000000..fde1e53c1a --- /dev/null +++ b/test/compile_errors/stage1/obj/ptrToInt_0_to_non_optional_pointer.zig @@ -0,0 +1,8 @@ +export fn entry() void { + var b = @intToPtr(*i32, 0); + _ = b; +} + +// @ptrToInt 0 to non optional pointer +// +// tmp.zig:2:13: error: pointer type '*i32' does not allow address zero diff --git a/test/compile_errors/stage1/obj/ptrToInt_on_void.zig b/test/compile_errors/stage1/obj/ptrToInt_on_void.zig new file mode 100644 index 0000000000..fd43053103 --- /dev/null +++ b/test/compile_errors/stage1/obj/ptrToInt_on_void.zig @@ -0,0 +1,7 @@ +export fn entry() bool { + return @ptrToInt(&{}) == @ptrToInt(&{}); +} + +// @ptrToInt on *void +// +// tmp.zig:2:23: error: pointer to size 0 type has no address diff --git a/test/compile_errors/stage1/obj/ptrcast_to_non-pointer.zig b/test/compile_errors/stage1/obj/ptrcast_to_non-pointer.zig new file mode 100644 index 0000000000..74894d5e8a --- /dev/null +++ b/test/compile_errors/stage1/obj/ptrcast_to_non-pointer.zig @@ -0,0 +1,7 @@ +export fn entry(a: *i32) usize { + return @ptrCast(usize, a); +} + +// ptrcast to non-pointer +// +// tmp.zig:2:21: error: expected pointer, found 'usize' diff --git a/test/compile_errors/stage1/obj/range_operator_in_switch_used_on_error_set.zig b/test/compile_errors/stage1/obj/range_operator_in_switch_used_on_error_set.zig new file mode 100644 index 0000000000..4f2949c50c --- /dev/null +++ b/test/compile_errors/stage1/obj/range_operator_in_switch_used_on_error_set.zig @@ -0,0 +1,17 @@ +export fn entry() void { + try foo(452) catch |err| switch (err) { + error.A ... error.B => {}, + else => {}, + }; +} +fn foo(x: i32) !void { + switch (x) { + 0 ... 10 => return error.Foo, + 11 ... 20 => return error.Bar, + else => {}, + } +} + +// range operator in switch used on error set +// +// tmp.zig:3:17: error: operator not allowed for errors diff --git a/test/compile_errors/stage1/obj/reading_past_end_of_pointer_casted_array.zig b/test/compile_errors/stage1/obj/reading_past_end_of_pointer_casted_array.zig new file mode 100644 index 0000000000..558797d69b --- /dev/null +++ b/test/compile_errors/stage1/obj/reading_past_end_of_pointer_casted_array.zig @@ -0,0 +1,11 @@ +comptime { + const array: [4]u8 = "aoeu".*; + const sub_array = array[1..]; + const int_ptr = @ptrCast(*const u24, sub_array); + const deref = int_ptr.*; + _ = deref; +} + +// reading past end of pointer casted array +// +// tmp.zig:5:26: error: attempt to read 4 bytes from [4]u8 at index 1 which is 3 bytes diff --git a/test/compile_errors/stage1/obj/recursive_inferred_error_set.zig b/test/compile_errors/stage1/obj/recursive_inferred_error_set.zig new file mode 100644 index 0000000000..8059833923 --- /dev/null +++ b/test/compile_errors/stage1/obj/recursive_inferred_error_set.zig @@ -0,0 +1,10 @@ +export fn entry() void { + foo() catch unreachable; +} +fn foo() !void { + try foo(); +} + +// recursive inferred error set +// +// tmp.zig:5:5: error: cannot resolve inferred error set '@typeInfo(@typeInfo(@TypeOf(foo)).Fn.return_type.?).ErrorUnion.error_set': function 'foo' not fully analyzed yet diff --git a/test/compile_errors/stage1/obj/redefinition_of_enums.zig b/test/compile_errors/stage1/obj/redefinition_of_enums.zig new file mode 100644 index 0000000000..b4033536c3 --- /dev/null +++ b/test/compile_errors/stage1/obj/redefinition_of_enums.zig @@ -0,0 +1,7 @@ +const A = enum {x}; +const A = enum {x}; + +// redefinition of enums +// +// tmp.zig:2:1: error: redeclaration of 'A' +// tmp.zig:1:1: note: other declaration here diff --git a/test/compile_errors/stage1/obj/redefinition_of_global_variables.zig b/test/compile_errors/stage1/obj/redefinition_of_global_variables.zig new file mode 100644 index 0000000000..b2267423b0 --- /dev/null +++ b/test/compile_errors/stage1/obj/redefinition_of_global_variables.zig @@ -0,0 +1,7 @@ +var a : i32 = 1; +var a : i32 = 2; + +// redefinition of global variables +// +// tmp.zig:2:1: error: redeclaration of 'a' +// tmp.zig:1:1: note: other declaration here diff --git a/test/compile_errors/stage1/obj/redefinition_of_struct.zig b/test/compile_errors/stage1/obj/redefinition_of_struct.zig new file mode 100644 index 0000000000..8c169356c9 --- /dev/null +++ b/test/compile_errors/stage1/obj/redefinition_of_struct.zig @@ -0,0 +1,7 @@ +const A = struct { x : i32, }; +const A = struct { y : i32, }; + +// redefinition of struct +// +// tmp.zig:2:1: error: redeclaration of 'A' +// tmp.zig:1:1: note: other declaration here diff --git a/test/compile_errors/stage1/obj/refer_to_the_type_of_a_generic_function.zig b/test/compile_errors/stage1/obj/refer_to_the_type_of_a_generic_function.zig new file mode 100644 index 0000000000..6e23854cd6 --- /dev/null +++ b/test/compile_errors/stage1/obj/refer_to_the_type_of_a_generic_function.zig @@ -0,0 +1,9 @@ +export fn entry() void { + const Func = fn (type) void; + const f: Func = undefined; + f(i32); +} + +// refer to the type of a generic function +// +// tmp.zig:4:5: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/referring_to_a_struct_that_is_invalid.zig b/test/compile_errors/stage1/obj/referring_to_a_struct_that_is_invalid.zig new file mode 100644 index 0000000000..5f646461d8 --- /dev/null +++ b/test/compile_errors/stage1/obj/referring_to_a_struct_that_is_invalid.zig @@ -0,0 +1,15 @@ +const UsbDeviceRequest = struct { + Type: u8, +}; + +export fn foo() void { + comptime assert(@sizeOf(UsbDeviceRequest) == 0x8); +} + +fn assert(ok: bool) void { + if (!ok) unreachable; +} + +// referring to a struct that is invalid +// +// tmp.zig:10:14: error: reached unreachable code diff --git a/test/compile_errors/stage1/obj/regression_test_2980_base_type_u32_is_not_type_checked_properly_when_assigning_a_value_within_a_struct.zig b/test/compile_errors/stage1/obj/regression_test_2980_base_type_u32_is_not_type_checked_properly_when_assigning_a_value_within_a_struct.zig new file mode 100644 index 0000000000..a714b10ef6 --- /dev/null +++ b/test/compile_errors/stage1/obj/regression_test_2980_base_type_u32_is_not_type_checked_properly_when_assigning_a_value_within_a_struct.zig @@ -0,0 +1,19 @@ +const Foo = struct { + ptr: ?*usize, + uval: u32, +}; +fn get_uval(x: u32) !u32 { + _ = x; + return error.NotFound; +} +export fn entry() void { + const afoo = Foo{ + .ptr = null, + .uval = get_uval(42), + }; + _ = afoo; +} + +// regression test #2980: base type u32 is not type checked properly when assigning a value within a struct +// +// tmp.zig:12:25: error: cannot convert error union to payload type. consider using `try`, `catch`, or `if`. expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(get_uval)).Fn.return_type.?).ErrorUnion.error_set!u32' diff --git a/test/compile_errors/stage1/obj/reify_type.Fn_with_is_generic_true.zig b/test/compile_errors/stage1/obj/reify_type.Fn_with_is_generic_true.zig new file mode 100644 index 0000000000..ed33158649 --- /dev/null +++ b/test/compile_errors/stage1/obj/reify_type.Fn_with_is_generic_true.zig @@ -0,0 +1,15 @@ +const Foo = @Type(.{ + .Fn = .{ + .calling_convention = .Unspecified, + .alignment = 0, + .is_generic = true, + .is_var_args = false, + .return_type = u0, + .args = &.{}, + }, +}); +comptime { _ = Foo; } + +// @Type(.Fn) with is_generic = true +// +// tmp.zig:1:20: error: Type.Fn.is_generic must be false for @Type diff --git a/test/compile_errors/stage1/obj/reify_type.Fn_with_is_var_args_true_and_non-C_callconv.zig b/test/compile_errors/stage1/obj/reify_type.Fn_with_is_var_args_true_and_non-C_callconv.zig new file mode 100644 index 0000000000..a57484075f --- /dev/null +++ b/test/compile_errors/stage1/obj/reify_type.Fn_with_is_var_args_true_and_non-C_callconv.zig @@ -0,0 +1,15 @@ +const Foo = @Type(.{ + .Fn = .{ + .calling_convention = .Unspecified, + .alignment = 0, + .is_generic = false, + .is_var_args = true, + .return_type = u0, + .args = &.{}, + }, +}); +comptime { _ = Foo; } + +// @Type(.Fn) with is_var_args = true and non-C callconv +// +// tmp.zig:1:20: error: varargs functions must have C calling convention diff --git a/test/compile_errors/stage1/obj/reify_type.Fn_with_return_type_null.zig b/test/compile_errors/stage1/obj/reify_type.Fn_with_return_type_null.zig new file mode 100644 index 0000000000..f8ddea52cf --- /dev/null +++ b/test/compile_errors/stage1/obj/reify_type.Fn_with_return_type_null.zig @@ -0,0 +1,15 @@ +const Foo = @Type(.{ + .Fn = .{ + .calling_convention = .Unspecified, + .alignment = 0, + .is_generic = false, + .is_var_args = false, + .return_type = null, + .args = &.{}, + }, +}); +comptime { _ = Foo; } + +// @Type(.Fn) with return_type = null +// +// tmp.zig:1:20: error: Type.Fn.return_type must be non-null for @Type diff --git a/test/compile_errors/stage1/obj/reify_type.Pointer_with_invalid_address_space.zig b/test/compile_errors/stage1/obj/reify_type.Pointer_with_invalid_address_space.zig new file mode 100644 index 0000000000..78160fae58 --- /dev/null +++ b/test/compile_errors/stage1/obj/reify_type.Pointer_with_invalid_address_space.zig @@ -0,0 +1,16 @@ +export fn entry() void { + _ = @Type(.{ .Pointer = .{ + .size = .One, + .is_const = false, + .is_volatile = false, + .alignment = 1, + .address_space = .gs, + .child = u8, + .is_allowzero = false, + .sentinel = null, + }}); +} + +// @Type(.Pointer) with invalid address space +// +// tmp.zig:2:16: error: address space 'gs' not available in stage 1 compiler, must be .generic diff --git a/test/compile_errors/stage1/obj/reify_type_for_exhaustive_enum_with_non-integer_tag_type.zig b/test/compile_errors/stage1/obj/reify_type_for_exhaustive_enum_with_non-integer_tag_type.zig new file mode 100644 index 0000000000..e77c2eb627 --- /dev/null +++ b/test/compile_errors/stage1/obj/reify_type_for_exhaustive_enum_with_non-integer_tag_type.zig @@ -0,0 +1,16 @@ +const Tag = @Type(.{ + .Enum = .{ + .layout = .Auto, + .tag_type = bool, + .fields = &.{}, + .decls = &.{}, + .is_exhaustive = false, + }, +}); +export fn entry() void { + _ = @intToEnum(Tag, 0); +} + +// @Type for exhaustive enum with non-integer tag type +// +// tmp.zig:1:20: error: Type.Enum.tag_type must be an integer type, not 'bool' diff --git a/test/compile_errors/stage1/obj/reify_type_for_exhaustive_enum_with_undefined_tag_type.zig b/test/compile_errors/stage1/obj/reify_type_for_exhaustive_enum_with_undefined_tag_type.zig new file mode 100644 index 0000000000..6a00516387 --- /dev/null +++ b/test/compile_errors/stage1/obj/reify_type_for_exhaustive_enum_with_undefined_tag_type.zig @@ -0,0 +1,16 @@ +const Tag = @Type(.{ + .Enum = .{ + .layout = .Auto, + .tag_type = undefined, + .fields = &.{}, + .decls = &.{}, + .is_exhaustive = false, + }, +}); +export fn entry() void { + _ = @intToEnum(Tag, 0); +} + +// @Type for exhaustive enum with undefined tag type +// +// tmp.zig:1:20: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/reify_type_for_exhaustive_enum_with_zero_fields.zig b/test/compile_errors/stage1/obj/reify_type_for_exhaustive_enum_with_zero_fields.zig new file mode 100644 index 0000000000..87689247aa --- /dev/null +++ b/test/compile_errors/stage1/obj/reify_type_for_exhaustive_enum_with_zero_fields.zig @@ -0,0 +1,16 @@ +const Tag = @Type(.{ + .Enum = .{ + .layout = .Auto, + .tag_type = u1, + .fields = &.{}, + .decls = &.{}, + .is_exhaustive = true, + }, +}); +export fn entry() void { + _ = @intToEnum(Tag, 0); +} + +// @Type for exhaustive enum with zero fields +// +// tmp.zig:1:20: error: enums must have 1 or more fields diff --git a/test/compile_errors/stage1/obj/reify_type_for_tagged_union_with_extra_enum_field.zig b/test/compile_errors/stage1/obj/reify_type_for_tagged_union_with_extra_enum_field.zig new file mode 100644 index 0000000000..f9155d7161 --- /dev/null +++ b/test/compile_errors/stage1/obj/reify_type_for_tagged_union_with_extra_enum_field.zig @@ -0,0 +1,32 @@ +const Tag = @Type(.{ + .Enum = .{ + .layout = .Auto, + .tag_type = u2, + .fields = &.{ + .{ .name = "signed", .value = 0 }, + .{ .name = "unsigned", .value = 1 }, + .{ .name = "arst", .value = 2 }, + }, + .decls = &.{}, + .is_exhaustive = true, + }, +}); +const Tagged = @Type(.{ + .Union = .{ + .layout = .Auto, + .tag_type = Tag, + .fields = &.{ + .{ .name = "signed", .field_type = i32, .alignment = @alignOf(i32) }, + .{ .name = "unsigned", .field_type = u32, .alignment = @alignOf(u32) }, + }, + .decls = &.{}, + }, +}); +export fn entry() void { + var tagged = Tagged{ .signed = -1 }; + tagged = .{ .unsigned = 1 }; +} + +// @Type for tagged union with extra enum field +// +// tmp.zig:14:23: error: enum field missing: 'arst' diff --git a/test/compile_errors/stage1/obj/reify_type_for_tagged_union_with_extra_union_field.zig b/test/compile_errors/stage1/obj/reify_type_for_tagged_union_with_extra_union_field.zig new file mode 100644 index 0000000000..9cd82213df --- /dev/null +++ b/test/compile_errors/stage1/obj/reify_type_for_tagged_union_with_extra_union_field.zig @@ -0,0 +1,33 @@ +const Tag = @Type(.{ + .Enum = .{ + .layout = .Auto, + .tag_type = u1, + .fields = &.{ + .{ .name = "signed", .value = 0 }, + .{ .name = "unsigned", .value = 1 }, + }, + .decls = &.{}, + .is_exhaustive = true, + }, +}); +const Tagged = @Type(.{ + .Union = .{ + .layout = .Auto, + .tag_type = Tag, + .fields = &.{ + .{ .name = "signed", .field_type = i32, .alignment = @alignOf(i32) }, + .{ .name = "unsigned", .field_type = u32, .alignment = @alignOf(u32) }, + .{ .name = "arst", .field_type = f32, .alignment = @alignOf(f32) }, + }, + .decls = &.{}, + }, +}); +export fn entry() void { + var tagged = Tagged{ .signed = -1 }; + tagged = .{ .unsigned = 1 }; +} + +// @Type for tagged union with extra union field +// +// tmp.zig:13:23: error: enum field not found: 'arst' +// tmp.zig:1:20: note: enum declared here diff --git a/test/compile_errors/stage1/obj/reify_type_for_union_with_opaque_field.zig b/test/compile_errors/stage1/obj/reify_type_for_union_with_opaque_field.zig new file mode 100644 index 0000000000..374ccb544b --- /dev/null +++ b/test/compile_errors/stage1/obj/reify_type_for_union_with_opaque_field.zig @@ -0,0 +1,17 @@ +const Untagged = @Type(.{ + .Union = .{ + .layout = .Auto, + .tag_type = null, + .fields = &.{ + .{ .name = "foo", .field_type = opaque {}, .alignment = 1 }, + }, + .decls = &.{}, + }, +}); +export fn entry() void { + _ = Untagged{}; +} + +// @Type for union with opaque field +// +// tmp.zig:1:25: error: opaque types have unknown size and therefore cannot be directly embedded in unions diff --git a/test/compile_errors/stage1/obj/reify_type_for_union_with_zero_fields.zig b/test/compile_errors/stage1/obj/reify_type_for_union_with_zero_fields.zig new file mode 100644 index 0000000000..8243ff3292 --- /dev/null +++ b/test/compile_errors/stage1/obj/reify_type_for_union_with_zero_fields.zig @@ -0,0 +1,15 @@ +const Untagged = @Type(.{ + .Union = .{ + .layout = .Auto, + .tag_type = null, + .fields = &.{}, + .decls = &.{}, + }, +}); +export fn entry() void { + _ = Untagged{}; +} + +// @Type for union with zero fields +// +// tmp.zig:1:25: error: unions must have 1 or more fields diff --git a/test/compile_errors/stage1/obj/reify_type_union_payload_is_undefined.zig b/test/compile_errors/stage1/obj/reify_type_union_payload_is_undefined.zig new file mode 100644 index 0000000000..43261dc32f --- /dev/null +++ b/test/compile_errors/stage1/obj/reify_type_union_payload_is_undefined.zig @@ -0,0 +1,8 @@ +const Foo = @Type(.{ + .Struct = undefined, +}); +comptime { _ = Foo; } + +// @Type() union payload is undefined +// +// tmp.zig:1:20: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/reify_type_with_Type.Int.zig b/test/compile_errors/stage1/obj/reify_type_with_Type.Int.zig new file mode 100644 index 0000000000..cea09d3f19 --- /dev/null +++ b/test/compile_errors/stage1/obj/reify_type_with_Type.Int.zig @@ -0,0 +1,11 @@ +const builtin = @import("std").builtin; +export fn entry() void { + _ = @Type(builtin.Type.Int{ + .signedness = .signed, + .bits = 8, + }); +} + +// @Type with Type.Int +// +// tmp.zig:3:31: error: expected type 'std.builtin.Type', found 'std.builtin.Type.Int' diff --git a/test/compile_errors/stage1/obj/reify_type_with_non-constant_expression.zig b/test/compile_errors/stage1/obj/reify_type_with_non-constant_expression.zig new file mode 100644 index 0000000000..a58b2a6b33 --- /dev/null +++ b/test/compile_errors/stage1/obj/reify_type_with_non-constant_expression.zig @@ -0,0 +1,9 @@ +const builtin = @import("std").builtin; +var globalTypeInfo : builtin.Type = undefined; +export fn entry() void { + _ = @Type(globalTypeInfo); +} + +// @Type with non-constant expression +// +// tmp.zig:4:15: error: unable to evaluate constant expression diff --git a/test/compile_errors/stage1/obj/reify_type_with_undefined.zig b/test/compile_errors/stage1/obj/reify_type_with_undefined.zig new file mode 100644 index 0000000000..984c9ac555 --- /dev/null +++ b/test/compile_errors/stage1/obj/reify_type_with_undefined.zig @@ -0,0 +1,18 @@ +comptime { + _ = @Type(.{ .Array = .{ .len = 0, .child = u8, .sentinel = undefined } }); +} +comptime { + _ = @Type(.{ + .Struct = .{ + .fields = undefined, + .decls = undefined, + .is_tuple = false, + .layout = .Auto, + }, + }); +} + +// @Type with undefined +// +// tmp.zig:2:16: error: use of undefined value here causes undefined behavior +// tmp.zig:5:16: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/result_location_incompatibility_mismatching_handle_is_ptr.zig b/test/compile_errors/stage1/obj/result_location_incompatibility_mismatching_handle_is_ptr.zig new file mode 100644 index 0000000000..a45fd9f41a --- /dev/null +++ b/test/compile_errors/stage1/obj/result_location_incompatibility_mismatching_handle_is_ptr.zig @@ -0,0 +1,16 @@ +export fn entry() void { + var damn = Container{ + .not_optional = getOptional(), + }; + _ = damn; +} +pub fn getOptional() ?i32 { + return 0; +} +pub const Container = struct { + not_optional: i32, +}; + +// result location incompatibility mismatching handle_is_ptr +// +// tmp.zig:3:36: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'i32', found '?i32' diff --git a/test/compile_errors/stage1/obj/result_location_incompatibility_mismatching_handle_is_ptr_generic_call.zig b/test/compile_errors/stage1/obj/result_location_incompatibility_mismatching_handle_is_ptr_generic_call.zig new file mode 100644 index 0000000000..8b913bd15c --- /dev/null +++ b/test/compile_errors/stage1/obj/result_location_incompatibility_mismatching_handle_is_ptr_generic_call.zig @@ -0,0 +1,16 @@ +export fn entry() void { + var damn = Container{ + .not_optional = getOptional(i32), + }; + _ = damn; +} +pub fn getOptional(comptime T: type) ?T { + return 0; +} +pub const Container = struct { + not_optional: i32, +}; + +// result location incompatibility mismatching handle_is_ptr (generic call) +// +// tmp.zig:3:36: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'i32', found '?i32' diff --git a/test/compile_errors/stage1/obj/return_from_defer_expression.zig b/test/compile_errors/stage1/obj/return_from_defer_expression.zig new file mode 100644 index 0000000000..0f4ac8e071 --- /dev/null +++ b/test/compile_errors/stage1/obj/return_from_defer_expression.zig @@ -0,0 +1,19 @@ +pub fn testTrickyDefer() !void { + defer canFail() catch {}; + + defer try canFail(); + + const a = maybeInt() orelse return; +} + +fn canFail() anyerror!void { } + +pub fn maybeInt() ?i32 { + return 0; +} + +export fn entry() usize { return @sizeOf(@TypeOf(testTrickyDefer)); } + +// return from defer expression +// +// tmp.zig:4:11: error: 'try' not allowed inside defer expression diff --git a/test/compile_errors/stage1/obj/returning_error_from_void_async_function.zig b/test/compile_errors/stage1/obj/returning_error_from_void_async_function.zig new file mode 100644 index 0000000000..a00422dd12 --- /dev/null +++ b/test/compile_errors/stage1/obj/returning_error_from_void_async_function.zig @@ -0,0 +1,10 @@ +export fn entry() void { + _ = async amain(); +} +fn amain() callconv(.Async) void { + return error.ShouldBeCompileError; +} + +// returning error from void async function +// +// tmp.zig:5:17: error: expected type 'void', found 'error{ShouldBeCompileError}' diff --git a/test/compile_errors/stage1/obj/runtime-known_async_function_called.zig b/test/compile_errors/stage1/obj/runtime-known_async_function_called.zig new file mode 100644 index 0000000000..52afd83a11 --- /dev/null +++ b/test/compile_errors/stage1/obj/runtime-known_async_function_called.zig @@ -0,0 +1,12 @@ +export fn entry() void { + _ = async amain(); +} +fn amain() void { + var ptr = afunc; + _ = ptr(); +} +fn afunc() callconv(.Async) void {} + +// runtime-known async function called +// +// tmp.zig:6:12: error: function is not comptime-known; @asyncCall required diff --git a/test/compile_errors/stage1/obj/runtime-known_function_called_with_async_keyword.zig b/test/compile_errors/stage1/obj/runtime-known_function_called_with_async_keyword.zig new file mode 100644 index 0000000000..79f0420a83 --- /dev/null +++ b/test/compile_errors/stage1/obj/runtime-known_function_called_with_async_keyword.zig @@ -0,0 +1,10 @@ +export fn entry() void { + var ptr = afunc; + _ = async ptr(); +} + +fn afunc() callconv(.Async) void { } + +// runtime-known function called with async keyword +// +// tmp.zig:3:15: error: function is not comptime-known; @asyncCall required diff --git a/test/compile_errors/stage1/obj/runtime_assignment_to_comptime_struct_type.zig b/test/compile_errors/stage1/obj/runtime_assignment_to_comptime_struct_type.zig new file mode 100644 index 0000000000..f8a3fd3ba1 --- /dev/null +++ b/test/compile_errors/stage1/obj/runtime_assignment_to_comptime_struct_type.zig @@ -0,0 +1,13 @@ +const Foo = struct { + Bar: u8, + Baz: type, +}; +export fn f() void { + var x: u8 = 0; + const foo = Foo { .Bar = x, .Baz = u8 }; + _ = foo; +} + +// runtime assignment to comptime struct type +// +// tmp.zig:7:23: error: unable to evaluate constant expression diff --git a/test/compile_errors/stage1/obj/runtime_assignment_to_comptime_union_type.zig b/test/compile_errors/stage1/obj/runtime_assignment_to_comptime_union_type.zig new file mode 100644 index 0000000000..bc4f093b0d --- /dev/null +++ b/test/compile_errors/stage1/obj/runtime_assignment_to_comptime_union_type.zig @@ -0,0 +1,13 @@ +const Foo = union { + Bar: u8, + Baz: type, +}; +export fn f() void { + var x: u8 = 0; + const foo = Foo { .Bar = x }; + _ = foo; +} + +// runtime assignment to comptime union type +// +// tmp.zig:7:23: error: unable to evaluate constant expression diff --git a/test/compile_errors/stage1/obj/runtime_cast_to_union_which_has_non-void_fields.zig b/test/compile_errors/stage1/obj/runtime_cast_to_union_which_has_non-void_fields.zig new file mode 100644 index 0000000000..8be361f2fe --- /dev/null +++ b/test/compile_errors/stage1/obj/runtime_cast_to_union_which_has_non-void_fields.zig @@ -0,0 +1,18 @@ +const Letter = enum { A, B, C }; +const Value = union(Letter) { + A: i32, + B, + C, +}; +export fn entry() void { + foo(Letter.A); +} +fn foo(l: Letter) void { + var x: Value = l; + _ = x; +} + +// runtime cast to union which has non-void fields +// +// tmp.zig:11:20: error: runtime cast to union 'Value' which has non-void fields +// tmp.zig:3:5: note: field 'A' has type 'i32' diff --git a/test/compile_errors/stage1/obj/runtime_index_into_comptime_type_slice.zig b/test/compile_errors/stage1/obj/runtime_index_into_comptime_type_slice.zig new file mode 100644 index 0000000000..4b9538c1a1 --- /dev/null +++ b/test/compile_errors/stage1/obj/runtime_index_into_comptime_type_slice.zig @@ -0,0 +1,15 @@ +const Struct = struct { + a: u32, +}; +fn getIndex() usize { + return 2; +} +export fn entry() void { + const index = getIndex(); + const field = @typeInfo(Struct).Struct.fields[index]; + _ = field; +} + +// runtime index into comptime type slice +// +// tmp.zig:9:51: error: values of type 'std.builtin.Type.StructField' must be comptime known, but index value is runtime known diff --git a/test/compile_errors/stage1/obj/saturating_arithmetic_does_not_allow_floats.zig b/test/compile_errors/stage1/obj/saturating_arithmetic_does_not_allow_floats.zig new file mode 100644 index 0000000000..57ee724e74 --- /dev/null +++ b/test/compile_errors/stage1/obj/saturating_arithmetic_does_not_allow_floats.zig @@ -0,0 +1,7 @@ +export fn a() void { + _ = @as(f32, 1.0) +| @as(f32, 1.0); +} + +// saturating arithmetic does not allow floats +// +// error: invalid operands to binary expression: 'f32' and 'f32' diff --git a/test/compile_errors/stage1/obj/saturating_shl_assign_does_not_allow_negative_rhs_at_comptime.zig b/test/compile_errors/stage1/obj/saturating_shl_assign_does_not_allow_negative_rhs_at_comptime.zig new file mode 100644 index 0000000000..9a46367ae5 --- /dev/null +++ b/test/compile_errors/stage1/obj/saturating_shl_assign_does_not_allow_negative_rhs_at_comptime.zig @@ -0,0 +1,10 @@ +export fn a() void { + comptime { + var x = @as(i32, 1); + x <<|= @as(i32, -2); + } +} + +// saturating shl assign does not allow negative rhs at comptime +// +// error: shift by negative value -2 diff --git a/test/compile_errors/stage1/obj/saturating_shl_does_not_allow_negative_rhs_at_comptime.zig b/test/compile_errors/stage1/obj/saturating_shl_does_not_allow_negative_rhs_at_comptime.zig new file mode 100644 index 0000000000..ffe715a8e3 --- /dev/null +++ b/test/compile_errors/stage1/obj/saturating_shl_does_not_allow_negative_rhs_at_comptime.zig @@ -0,0 +1,7 @@ +export fn a() void { + _ = @as(i32, 1) <<| @as(i32, -2); +} + +// saturating shl does not allow negative rhs at comptime +// +// error: shift by negative value -2 diff --git a/test/compile_errors/stage1/obj/setAlignStack_in_inline_function.zig b/test/compile_errors/stage1/obj/setAlignStack_in_inline_function.zig new file mode 100644 index 0000000000..9261ecdb18 --- /dev/null +++ b/test/compile_errors/stage1/obj/setAlignStack_in_inline_function.zig @@ -0,0 +1,10 @@ +export fn entry() void { + foo(); +} +fn foo() callconv(.Inline) void { + @setAlignStack(16); +} + +// @setAlignStack in inline function +// +// tmp.zig:5:5: error: @setAlignStack in inline function diff --git a/test/compile_errors/stage1/obj/setAlignStack_in_naked_function.zig b/test/compile_errors/stage1/obj/setAlignStack_in_naked_function.zig new file mode 100644 index 0000000000..d7146625c5 --- /dev/null +++ b/test/compile_errors/stage1/obj/setAlignStack_in_naked_function.zig @@ -0,0 +1,7 @@ +export fn entry() callconv(.Naked) void { + @setAlignStack(16); +} + +// @setAlignStack in naked function +// +// tmp.zig:2:5: error: @setAlignStack in naked function diff --git a/test/compile_errors/stage1/obj/setAlignStack_outside_function.zig b/test/compile_errors/stage1/obj/setAlignStack_outside_function.zig new file mode 100644 index 0000000000..c9ac12e6e0 --- /dev/null +++ b/test/compile_errors/stage1/obj/setAlignStack_outside_function.zig @@ -0,0 +1,7 @@ +comptime { + @setAlignStack(16); +} + +// @setAlignStack outside function +// +// tmp.zig:2:5: error: @setAlignStack outside function diff --git a/test/compile_errors/stage1/obj/setAlignStack_set_twice.zig b/test/compile_errors/stage1/obj/setAlignStack_set_twice.zig new file mode 100644 index 0000000000..de8cde7c01 --- /dev/null +++ b/test/compile_errors/stage1/obj/setAlignStack_set_twice.zig @@ -0,0 +1,9 @@ +export fn entry() void { + @setAlignStack(16); + @setAlignStack(16); +} + +// @setAlignStack set twice +// +// tmp.zig:3:5: error: alignstack set twice +// tmp.zig:2:5: note: first set here diff --git a/test/compile_errors/stage1/obj/setAlignStack_too_big.zig b/test/compile_errors/stage1/obj/setAlignStack_too_big.zig new file mode 100644 index 0000000000..669ec45204 --- /dev/null +++ b/test/compile_errors/stage1/obj/setAlignStack_too_big.zig @@ -0,0 +1,7 @@ +export fn entry() void { + @setAlignStack(511 + 1); +} + +// @setAlignStack too big +// +// tmp.zig:2:5: error: attempt to @setAlignStack(512); maximum is 256 diff --git a/test/compile_errors/stage1/obj/setFloatMode_twice_for_same_scope.zig b/test/compile_errors/stage1/obj/setFloatMode_twice_for_same_scope.zig new file mode 100644 index 0000000000..3e55604030 --- /dev/null +++ b/test/compile_errors/stage1/obj/setFloatMode_twice_for_same_scope.zig @@ -0,0 +1,9 @@ +export fn foo() void { + @setFloatMode(@import("std").builtin.FloatMode.Optimized); + @setFloatMode(@import("std").builtin.FloatMode.Optimized); +} + +// @setFloatMode twice for same scope +// +// tmp.zig:3:5: error: float mode set twice for same scope +// tmp.zig:2:5: note: first set here diff --git a/test/compile_errors/stage1/obj/setRuntimeSafety_twice_for_same_scope.zig b/test/compile_errors/stage1/obj/setRuntimeSafety_twice_for_same_scope.zig new file mode 100644 index 0000000000..741a214cde --- /dev/null +++ b/test/compile_errors/stage1/obj/setRuntimeSafety_twice_for_same_scope.zig @@ -0,0 +1,9 @@ +export fn foo() void { + @setRuntimeSafety(false); + @setRuntimeSafety(false); +} + +// @setRuntimeSafety twice for same scope +// +// tmp.zig:3:5: error: runtime safety set twice for same scope +// tmp.zig:2:5: note: first set here diff --git a/test/compile_errors/stage1/obj/setting_a_section_on_a_local_variable.zig b/test/compile_errors/stage1/obj/setting_a_section_on_a_local_variable.zig new file mode 100644 index 0000000000..eb3df0e214 --- /dev/null +++ b/test/compile_errors/stage1/obj/setting_a_section_on_a_local_variable.zig @@ -0,0 +1,8 @@ +export fn entry() i32 { + var foo: i32 linksection(".text2") = 1234; + return foo; +} + +// setting a section on a local variable +// +// tmp.zig:2:30: error: cannot set section of local variable 'foo' diff --git a/test/compile_errors/stage1/obj/shift_amount_has_to_be_an_integer_type.zig b/test/compile_errors/stage1/obj/shift_amount_has_to_be_an_integer_type.zig new file mode 100644 index 0000000000..6e54405619 --- /dev/null +++ b/test/compile_errors/stage1/obj/shift_amount_has_to_be_an_integer_type.zig @@ -0,0 +1,8 @@ +export fn entry() void { + const x = 1 << &@as(u8, 10); + _ = x; +} + +// shift amount has to be an integer type +// +// tmp.zig:2:21: error: shift amount has to be an integer type, but found '*const u8' diff --git a/test/compile_errors/stage1/obj/shift_by_negative_comptime_integer.zig b/test/compile_errors/stage1/obj/shift_by_negative_comptime_integer.zig new file mode 100644 index 0000000000..41f0ff80aa --- /dev/null +++ b/test/compile_errors/stage1/obj/shift_by_negative_comptime_integer.zig @@ -0,0 +1,8 @@ +comptime { + var a = 1 >> -1; + _ = a; +} + +// shift by negative comptime integer +// +// tmp.zig:2:18: error: shift by negative value -1 diff --git a/test/compile_errors/stage1/obj/shift_left_assign_on_undefined_value.zig b/test/compile_errors/stage1/obj/shift_left_assign_on_undefined_value.zig new file mode 100644 index 0000000000..a23d0e190c --- /dev/null +++ b/test/compile_errors/stage1/obj/shift_left_assign_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: i64 = undefined; + a >>= 2; +} + +// shift left assign on undefined value +// +// tmp.zig:3:5: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/shift_left_on_undefined_value.zig b/test/compile_errors/stage1/obj/shift_left_on_undefined_value.zig new file mode 100644 index 0000000000..aa0891133b --- /dev/null +++ b/test/compile_errors/stage1/obj/shift_left_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: i64 = undefined; + _ = a << 2; +} + +// shift left on undefined value +// +// tmp.zig:3:9: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/shift_right_assign_on_undefined_value.zig b/test/compile_errors/stage1/obj/shift_right_assign_on_undefined_value.zig new file mode 100644 index 0000000000..65f4fe50b8 --- /dev/null +++ b/test/compile_errors/stage1/obj/shift_right_assign_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: i64 = undefined; + a >>= 2; +} + +// shift right assign on undefined value +// +// tmp.zig:3:5: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/shift_right_on_undefined_value.zig b/test/compile_errors/stage1/obj/shift_right_on_undefined_value.zig new file mode 100644 index 0000000000..ccd2563c84 --- /dev/null +++ b/test/compile_errors/stage1/obj/shift_right_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: i64 = undefined; + _ = a >> 2; +} + +// shift right on undefined value +// +// tmp.zig:3:9: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/shifting_RHS_is_log2_of_LHS_int_bit_width.zig b/test/compile_errors/stage1/obj/shifting_RHS_is_log2_of_LHS_int_bit_width.zig new file mode 100644 index 0000000000..8a5d6cfee4 --- /dev/null +++ b/test/compile_errors/stage1/obj/shifting_RHS_is_log2_of_LHS_int_bit_width.zig @@ -0,0 +1,7 @@ +export fn entry(x: u8, y: u8) u8 { + return x << y; +} + +// shifting RHS is log2 of LHS int bit width +// +// tmp.zig:2:17: error: expected type 'u3', found 'u8' diff --git a/test/compile_errors/stage1/obj/shifting_without_int_type_or_comptime_known.zig b/test/compile_errors/stage1/obj/shifting_without_int_type_or_comptime_known.zig new file mode 100644 index 0000000000..380a08a95c --- /dev/null +++ b/test/compile_errors/stage1/obj/shifting_without_int_type_or_comptime_known.zig @@ -0,0 +1,7 @@ +export fn entry(x: u8) u8 { + return 0x11 << x; +} + +// shifting without int type or comptime known +// +// tmp.zig:2:17: error: LHS of shift must be a fixed-width integer type, or RHS must be compile-time known diff --git a/test/compile_errors/stage1/obj/shlExact_shifts_out_1_bits.zig b/test/compile_errors/stage1/obj/shlExact_shifts_out_1_bits.zig new file mode 100644 index 0000000000..bd6e48f25c --- /dev/null +++ b/test/compile_errors/stage1/obj/shlExact_shifts_out_1_bits.zig @@ -0,0 +1,8 @@ +comptime { + const x = @shlExact(@as(u8, 0b01010101), 2); + _ = x; +} + +// @shlExact shifts out 1 bits +// +// tmp.zig:2:15: error: operation caused overflow diff --git a/test/compile_errors/stage1/obj/shrExact_shifts_out_1_bits.zig b/test/compile_errors/stage1/obj/shrExact_shifts_out_1_bits.zig new file mode 100644 index 0000000000..004bf0c1c3 --- /dev/null +++ b/test/compile_errors/stage1/obj/shrExact_shifts_out_1_bits.zig @@ -0,0 +1,8 @@ +comptime { + const x = @shrExact(@as(u8, 0b10101010), 2); + _ = x; +} + +// @shrExact shifts out 1 bits +// +// tmp.zig:2:15: error: exact shift shifted out 1 bits diff --git a/test/compile_errors/stage1/obj/signed_integer_division.zig b/test/compile_errors/stage1/obj/signed_integer_division.zig new file mode 100644 index 0000000000..524f9fe1db --- /dev/null +++ b/test/compile_errors/stage1/obj/signed_integer_division.zig @@ -0,0 +1,7 @@ +export fn foo(a: i32, b: i32) i32 { + return a / b; +} + +// signed integer division +// +// tmp.zig:2:14: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact diff --git a/test/compile_errors/stage1/obj/signed_integer_remainder_division.zig b/test/compile_errors/stage1/obj/signed_integer_remainder_division.zig new file mode 100644 index 0000000000..e060b780d0 --- /dev/null +++ b/test/compile_errors/stage1/obj/signed_integer_remainder_division.zig @@ -0,0 +1,7 @@ +export fn foo(a: i32, b: i32) i32 { + return a % b; +} + +// signed integer remainder division +// +// tmp.zig:2:14: error: remainder division with 'i32' and 'i32': signed integers and floats must use @rem or @mod diff --git a/test/compile_errors/stage1/obj/sizeOf_bad_type.zig b/test/compile_errors/stage1/obj/sizeOf_bad_type.zig new file mode 100644 index 0000000000..1b336cf657 --- /dev/null +++ b/test/compile_errors/stage1/obj/sizeOf_bad_type.zig @@ -0,0 +1,7 @@ +export fn entry() usize { + return @sizeOf(@TypeOf(null)); +} + +// @sizeOf bad type +// +// tmp.zig:2:20: error: no size available for type '@Type(.Null)' diff --git a/test/compile_errors/stage1/obj/slice_cannot_have_its_bytes_reinterpreted.zig b/test/compile_errors/stage1/obj/slice_cannot_have_its_bytes_reinterpreted.zig new file mode 100644 index 0000000000..4f7670ba74 --- /dev/null +++ b/test/compile_errors/stage1/obj/slice_cannot_have_its_bytes_reinterpreted.zig @@ -0,0 +1,9 @@ +export fn foo() void { + const bytes = [1]u8{ 0xfa } ** 16; + var value = @ptrCast(*const []const u8, &bytes).*; + _ = value; +} + +// slice cannot have its bytes reinterpreted +// +// :3:52: error: slice '[]const u8' cannot have its bytes reinterpreted diff --git a/test/compile_errors/stage1/obj/slice_passed_as_array_init_type.zig b/test/compile_errors/stage1/obj/slice_passed_as_array_init_type.zig new file mode 100644 index 0000000000..0d29120ca4 --- /dev/null +++ b/test/compile_errors/stage1/obj/slice_passed_as_array_init_type.zig @@ -0,0 +1,8 @@ +export fn entry() void { + const x = []u8{}; + _ = x; +} + +// slice passed as array init type +// +// tmp.zig:2:15: error: array literal requires address-of operator (&) to coerce to slice type '[]u8' diff --git a/test/compile_errors/stage1/obj/slice_passed_as_array_init_type_with_elems.zig b/test/compile_errors/stage1/obj/slice_passed_as_array_init_type_with_elems.zig new file mode 100644 index 0000000000..375ed55a72 --- /dev/null +++ b/test/compile_errors/stage1/obj/slice_passed_as_array_init_type_with_elems.zig @@ -0,0 +1,8 @@ +export fn entry() void { + const x = []u8{1, 2}; + _ = x; +} + +// slice passed as array init type with elems +// +// tmp.zig:2:15: error: array literal requires address-of operator (&) to coerce to slice type '[]u8' diff --git a/test/compile_errors/stage1/obj/slice_sentinel_mismatch-1.zig b/test/compile_errors/stage1/obj/slice_sentinel_mismatch-1.zig new file mode 100644 index 0000000000..1e3c2450cb --- /dev/null +++ b/test/compile_errors/stage1/obj/slice_sentinel_mismatch-1.zig @@ -0,0 +1,8 @@ +export fn entry() void { + const y: [:1]const u8 = &[_:2]u8{ 1, 2 }; + _ = y; +} + +// slice sentinel mismatch - 1 +// +// tmp.zig:2:37: error: expected type '[:1]const u8', found '*const [2:2]u8' diff --git a/test/compile_errors/stage1/obj/slice_sentinel_mismatch-2.zig b/test/compile_errors/stage1/obj/slice_sentinel_mismatch-2.zig new file mode 100644 index 0000000000..f1d73eb9df --- /dev/null +++ b/test/compile_errors/stage1/obj/slice_sentinel_mismatch-2.zig @@ -0,0 +1,10 @@ +fn foo() [:0]u8 { + var x: []u8 = undefined; + return x; +} +comptime { _ = foo; } + +// slice sentinel mismatch - 2 +// +// tmp.zig:3:12: error: expected type '[:0]u8', found '[]u8' +// tmp.zig:3:12: note: destination pointer requires a terminating '0' sentinel diff --git a/test/compile_errors/stage1/obj/slicing_of_global_undefined_pointer.zig b/test/compile_errors/stage1/obj/slicing_of_global_undefined_pointer.zig new file mode 100644 index 0000000000..d52bfdf6a5 --- /dev/null +++ b/test/compile_errors/stage1/obj/slicing_of_global_undefined_pointer.zig @@ -0,0 +1,8 @@ +var buf: *[1]u8 = undefined; +export fn entry() void { + _ = buf[0..1]; +} + +// slicing of global undefined pointer +// +// tmp.zig:3:12: error: non-zero length slice of undefined pointer diff --git a/test/compile_errors/stage1/obj/slicing_single-item_pointer.zig b/test/compile_errors/stage1/obj/slicing_single-item_pointer.zig new file mode 100644 index 0000000000..f6bbe752b1 --- /dev/null +++ b/test/compile_errors/stage1/obj/slicing_single-item_pointer.zig @@ -0,0 +1,8 @@ +export fn entry(ptr: *i32) void { + const slice = ptr[0..2]; + _ = slice; +} + +// slicing single-item pointer +// +// tmp.zig:2:22: error: slice of single-item pointer diff --git a/test/compile_errors/stage1/obj/specify_enum_tag_type_that_is_too_small.zig b/test/compile_errors/stage1/obj/specify_enum_tag_type_that_is_too_small.zig new file mode 100644 index 0000000000..ca7c305d38 --- /dev/null +++ b/test/compile_errors/stage1/obj/specify_enum_tag_type_that_is_too_small.zig @@ -0,0 +1,16 @@ +const Small = enum (u2) { + One, + Two, + Three, + Four, + Five, +}; + +export fn entry() void { + var x = Small.One; + _ = x; +} + +// specify enum tag type that is too small +// +// tmp.zig:6:5: error: enumeration value 4 too large for type 'u2' diff --git a/test/compile_errors/stage1/obj/specify_non-integer_enum_tag_type.zig b/test/compile_errors/stage1/obj/specify_non-integer_enum_tag_type.zig new file mode 100644 index 0000000000..095a0812c1 --- /dev/null +++ b/test/compile_errors/stage1/obj/specify_non-integer_enum_tag_type.zig @@ -0,0 +1,14 @@ +const Small = enum (f32) { + One, + Two, + Three, +}; + +export fn entry() void { + var x = Small.One; + _ = x; +} + +// specify non-integer enum tag type +// +// tmp.zig:1:21: error: expected integer, found 'f32' diff --git a/test/compile_errors/stage1/obj/src_outside_function.zig b/test/compile_errors/stage1/obj/src_outside_function.zig new file mode 100644 index 0000000000..5359135066 --- /dev/null +++ b/test/compile_errors/stage1/obj/src_outside_function.zig @@ -0,0 +1,7 @@ +comptime { + @src(); +} + +// @src outside function +// +// tmp.zig:2:5: error: @src outside function diff --git a/test/compile_errors/stage1/obj/store_vector_pointer_with_unknown_runtime_index.zig b/test/compile_errors/stage1/obj/store_vector_pointer_with_unknown_runtime_index.zig new file mode 100644 index 0000000000..6ef71c863a --- /dev/null +++ b/test/compile_errors/stage1/obj/store_vector_pointer_with_unknown_runtime_index.zig @@ -0,0 +1,14 @@ +export fn entry() void { + var v: @import("std").meta.Vector(4, i32) = [_]i32{ 1, 5, 3, undefined }; + + var i: u32 = 0; + storev(&v[i], 42); +} + +fn storev(ptr: anytype, val: i32) void { + ptr.* = val; +} + +// store vector pointer with unknown runtime index +// +// tmp.zig:9:8: error: unable to determine vector element index of type '*align(16:0:4:?) i32 diff --git a/test/compile_errors/stage1/obj/storing_runtime_value_in_compile_time_variable_then_using_it.zig b/test/compile_errors/stage1/obj/storing_runtime_value_in_compile_time_variable_then_using_it.zig new file mode 100644 index 0000000000..318db771d5 --- /dev/null +++ b/test/compile_errors/stage1/obj/storing_runtime_value_in_compile_time_variable_then_using_it.zig @@ -0,0 +1,47 @@ +const Mode = @import("std").builtin.Mode; + +fn Free(comptime filename: []const u8) TestCase { + return TestCase { + .filename = filename, + .problem_type = ProblemType.Free, + }; +} + +fn LibC(comptime filename: []const u8) TestCase { + return TestCase { + .filename = filename, + .problem_type = ProblemType.LinkLibC, + }; +} + +const TestCase = struct { + filename: []const u8, + problem_type: ProblemType, +}; + +const ProblemType = enum { + Free, + LinkLibC, +}; + +export fn entry() void { + const tests = [_]TestCase { + Free("001"), + Free("002"), + LibC("078"), + Free("116"), + Free("117"), + }; + + for ([_]Mode { Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast }) |mode| { + _ = mode; + inline for (tests) |test_case| { + const foo = test_case.filename ++ ".zig"; + _ = foo; + } + } +} + +// storing runtime value in compile time variable then using it +// +// tmp.zig:38:29: error: cannot store runtime value in compile time variable diff --git a/test/compile_errors/stage1/obj/struct_depends_on_itself_via_optional_field.zig b/test/compile_errors/stage1/obj/struct_depends_on_itself_via_optional_field.zig new file mode 100644 index 0000000000..13ee95155d --- /dev/null +++ b/test/compile_errors/stage1/obj/struct_depends_on_itself_via_optional_field.zig @@ -0,0 +1,17 @@ +const LhsExpr = struct { + rhsExpr: ?AstObject, +}; +const AstObject = union { + lhsExpr: LhsExpr, +}; +export fn entry() void { + const lhsExpr = LhsExpr{ .rhsExpr = null }; + const obj = AstObject{ .lhsExpr = lhsExpr }; + _ = obj; +} + +// struct depends on itself via optional field +// +// tmp.zig:1:17: error: struct 'LhsExpr' depends on itself +// tmp.zig:5:5: note: while checking this field +// tmp.zig:2:5: note: while checking this field diff --git a/test/compile_errors/stage1/obj/struct_field_missing_type.zig b/test/compile_errors/stage1/obj/struct_field_missing_type.zig new file mode 100644 index 0000000000..669718a3d4 --- /dev/null +++ b/test/compile_errors/stage1/obj/struct_field_missing_type.zig @@ -0,0 +1,11 @@ +const Letter = struct { + A, +}; +export fn entry() void { + var a = Letter { .A = {} }; + _ = a; +} + +// struct field missing type +// +// tmp.zig:2:5: error: struct field missing type diff --git a/test/compile_errors/stage1/obj/struct_init_syntax_for_array.zig b/test/compile_errors/stage1/obj/struct_init_syntax_for_array.zig new file mode 100644 index 0000000000..4eda9622ab --- /dev/null +++ b/test/compile_errors/stage1/obj/struct_init_syntax_for_array.zig @@ -0,0 +1,8 @@ +const foo = [3]u16{ .x = 1024 }; +comptime { + _ = foo; +} + +// struct init syntax for array +// +// tmp.zig:1:13: error: initializing array with struct syntax diff --git a/test/compile_errors/stage1/obj/struct_with_declarations_unavailable_for_reify_type.zig b/test/compile_errors/stage1/obj/struct_with_declarations_unavailable_for_reify_type.zig new file mode 100644 index 0000000000..656a9b9f62 --- /dev/null +++ b/test/compile_errors/stage1/obj/struct_with_declarations_unavailable_for_reify_type.zig @@ -0,0 +1,7 @@ +export fn entry() void { + _ = @Type(@typeInfo(struct { const foo = 1; })); +} + +// struct with declarations unavailable for @Type +// +// tmp.zig:2:15: error: Type.Struct.decls must be empty for @Type diff --git a/test/compile_errors/stage1/obj/struct_with_invalid_field.zig b/test/compile_errors/stage1/obj/struct_with_invalid_field.zig new file mode 100644 index 0000000000..a2a632fbd9 --- /dev/null +++ b/test/compile_errors/stage1/obj/struct_with_invalid_field.zig @@ -0,0 +1,28 @@ +const std = @import("std",); +const Allocator = std.mem.Allocator; +const ArrayList = std.ArrayList; + +const HeaderWeight = enum { + H1, H2, H3, H4, H5, H6, +}; + +const MdText = ArrayList(u8); + +const MdNode = union(enum) { + Header: struct { + text: MdText, + weight: HeaderValue, + }, +}; + +export fn entry() void { + const a = MdNode.Header { + .text = MdText.init(std.testing.allocator), + .weight = HeaderWeight.H1, + }; + _ = a; +} + +// struct with invalid field +// +// tmp.zig:14:17: error: use of undeclared identifier 'HeaderValue' diff --git a/test/compile_errors/stage1/obj/sub_assign_on_undefined_value.zig b/test/compile_errors/stage1/obj/sub_assign_on_undefined_value.zig new file mode 100644 index 0000000000..01ef9313e5 --- /dev/null +++ b/test/compile_errors/stage1/obj/sub_assign_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: i64 = undefined; + a -= a; +} + +// sub assign on undefined value +// +// tmp.zig:3:5: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/sub_on_undefined_value.zig b/test/compile_errors/stage1/obj/sub_on_undefined_value.zig new file mode 100644 index 0000000000..80746abf0e --- /dev/null +++ b/test/compile_errors/stage1/obj/sub_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: i64 = undefined; + _ = a - a; +} + +// sub on undefined value +// +// tmp.zig:3:9: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/sub_overflow_in_function_evaluation.zig b/test/compile_errors/stage1/obj/sub_overflow_in_function_evaluation.zig new file mode 100644 index 0000000000..1084f1a111 --- /dev/null +++ b/test/compile_errors/stage1/obj/sub_overflow_in_function_evaluation.zig @@ -0,0 +1,10 @@ +const y = sub(10, 20); +fn sub(a: u16, b: u16) u16 { + return a - b; +} + +export fn entry() usize { return @sizeOf(@TypeOf(y)); } + +// sub overflow in function evaluation +// +// tmp.zig:3:14: error: operation caused overflow diff --git a/test/compile_errors/stage1/obj/sub_wrap_assign_on_undefined_value.zig b/test/compile_errors/stage1/obj/sub_wrap_assign_on_undefined_value.zig new file mode 100644 index 0000000000..3c7fd4faa5 --- /dev/null +++ b/test/compile_errors/stage1/obj/sub_wrap_assign_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: i64 = undefined; + a -%= a; +} + +// sub wrap assign on undefined value +// +// tmp.zig:3:5: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/sub_wrap_on_undefined_value.zig b/test/compile_errors/stage1/obj/sub_wrap_on_undefined_value.zig new file mode 100644 index 0000000000..367b4c9c0e --- /dev/null +++ b/test/compile_errors/stage1/obj/sub_wrap_on_undefined_value.zig @@ -0,0 +1,8 @@ +comptime { + var a: i64 = undefined; + _ = a -% a; +} + +// sub wrap on undefined value +// +// tmp.zig:3:9: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/suspend_inside_suspend_block.zig b/test/compile_errors/stage1/obj/suspend_inside_suspend_block.zig new file mode 100644 index 0000000000..2e807268ce --- /dev/null +++ b/test/compile_errors/stage1/obj/suspend_inside_suspend_block.zig @@ -0,0 +1,14 @@ +export fn entry() void { + _ = async foo(); +} +fn foo() void { + suspend { + suspend { + } + } +} + +// suspend inside suspend block +// +// tmp.zig:6:9: error: cannot suspend inside suspend block +// tmp.zig:5:5: note: other suspend block here diff --git a/test/compile_errors/stage1/obj/switch_expression-duplicate_enumeration_prong.zig b/test/compile_errors/stage1/obj/switch_expression-duplicate_enumeration_prong.zig new file mode 100644 index 0000000000..c5db39f5b2 --- /dev/null +++ b/test/compile_errors/stage1/obj/switch_expression-duplicate_enumeration_prong.zig @@ -0,0 +1,22 @@ +const Number = enum { + One, + Two, + Three, + Four, +}; +fn f(n: Number) i32 { + switch (n) { + Number.One => 1, + Number.Two => 2, + Number.Three => @as(i32, 3), + Number.Four => 4, + Number.Two => 2, + } +} + +export fn entry() usize { return @sizeOf(@TypeOf(f)); } + +// switch expression - duplicate enumeration prong +// +// tmp.zig:13:15: error: duplicate switch value +// tmp.zig:10:15: note: other value here diff --git a/test/compile_errors/stage1/obj/switch_expression-duplicate_enumeration_prong_when_else_present.zig b/test/compile_errors/stage1/obj/switch_expression-duplicate_enumeration_prong_when_else_present.zig new file mode 100644 index 0000000000..22a0c189c1 --- /dev/null +++ b/test/compile_errors/stage1/obj/switch_expression-duplicate_enumeration_prong_when_else_present.zig @@ -0,0 +1,23 @@ +const Number = enum { + One, + Two, + Three, + Four, +}; +fn f(n: Number) i32 { + switch (n) { + Number.One => 1, + Number.Two => 2, + Number.Three => @as(i32, 3), + Number.Four => 4, + Number.Two => 2, + else => 10, + } +} + +export fn entry() usize { return @sizeOf(@TypeOf(f)); } + +// switch expression - duplicate enumeration prong when else present +// +// tmp.zig:13:15: error: duplicate switch value +// tmp.zig:10:15: note: other value here diff --git a/test/compile_errors/stage1/obj/switch_expression-duplicate_or_overlapping_integer_value.zig b/test/compile_errors/stage1/obj/switch_expression-duplicate_or_overlapping_integer_value.zig new file mode 100644 index 0000000000..06ef7de62e --- /dev/null +++ b/test/compile_errors/stage1/obj/switch_expression-duplicate_or_overlapping_integer_value.zig @@ -0,0 +1,14 @@ +fn foo(x: u8) u8 { + return switch (x) { + 0 ... 100 => @as(u8, 0), + 101 ... 200 => 1, + 201, 203 ... 207 => 2, + 206 ... 255 => 3, + }; +} +export fn entry() usize { return @sizeOf(@TypeOf(foo)); } + +// switch expression - duplicate or overlapping integer value +// +// tmp.zig:6:9: error: duplicate switch value +// tmp.zig:5:14: note: previous value here diff --git a/test/compile_errors/stage1/obj/switch_expression-duplicate_type.zig b/test/compile_errors/stage1/obj/switch_expression-duplicate_type.zig new file mode 100644 index 0000000000..9ac9feaeaf --- /dev/null +++ b/test/compile_errors/stage1/obj/switch_expression-duplicate_type.zig @@ -0,0 +1,15 @@ +fn foo(comptime T: type, x: T) u8 { + _ = x; + return switch (T) { + u32 => 0, + u64 => 1, + u32 => 2, + else => 3, + }; +} +export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); } + +// switch expression - duplicate type +// +// tmp.zig:6:9: error: duplicate switch value +// tmp.zig:4:9: note: previous value here diff --git a/test/compile_errors/stage1/obj/switch_expression-duplicate_type_struct_alias.zig b/test/compile_errors/stage1/obj/switch_expression-duplicate_type_struct_alias.zig new file mode 100644 index 0000000000..b92336cac5 --- /dev/null +++ b/test/compile_errors/stage1/obj/switch_expression-duplicate_type_struct_alias.zig @@ -0,0 +1,19 @@ +const Test = struct { + bar: i32, +}; +const Test2 = Test; +fn foo(comptime T: type, x: T) u8 { + _ = x; + return switch (T) { + Test => 0, + u64 => 1, + Test2 => 2, + else => 3, + }; +} +export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); } + +// switch expression - duplicate type (struct alias) +// +// tmp.zig:10:9: error: duplicate switch value +// tmp.zig:8:9: note: previous value here diff --git a/test/compile_errors/stage1/obj/switch_expression-missing_enumeration_prong.zig b/test/compile_errors/stage1/obj/switch_expression-missing_enumeration_prong.zig new file mode 100644 index 0000000000..b6cd60c22b --- /dev/null +++ b/test/compile_errors/stage1/obj/switch_expression-missing_enumeration_prong.zig @@ -0,0 +1,19 @@ +const Number = enum { + One, + Two, + Three, + Four, +}; +fn f(n: Number) i32 { + switch (n) { + Number.One => 1, + Number.Two => 2, + Number.Three => @as(i32, 3), + } +} + +export fn entry() usize { return @sizeOf(@TypeOf(f)); } + +// switch expression - missing enumeration prong +// +// tmp.zig:8:5: error: enumeration value 'Number.Four' not handled in switch diff --git a/test/compile_errors/stage1/obj/switch_expression-multiple_else_prongs.zig b/test/compile_errors/stage1/obj/switch_expression-multiple_else_prongs.zig new file mode 100644 index 0000000000..6a7e274b56 --- /dev/null +++ b/test/compile_errors/stage1/obj/switch_expression-multiple_else_prongs.zig @@ -0,0 +1,14 @@ +fn f(x: u32) void { + const value: bool = switch (x) { + 1234 => false, + else => true, + else => true, + }; +} +export fn entry() void { + f(1234); +} + +// switch expression - multiple else prongs +// +// tmp.zig:5:9: error: multiple else prongs in switch expression diff --git a/test/compile_errors/stage1/obj/switch_expression-non_exhaustive_integer_prongs.zig b/test/compile_errors/stage1/obj/switch_expression-non_exhaustive_integer_prongs.zig new file mode 100644 index 0000000000..88fb8548de --- /dev/null +++ b/test/compile_errors/stage1/obj/switch_expression-non_exhaustive_integer_prongs.zig @@ -0,0 +1,10 @@ +fn foo(x: u8) void { + switch (x) { + 0 => {}, + } +} +export fn entry() usize { return @sizeOf(@TypeOf(foo)); } + +// switch expression - non exhaustive integer prongs +// +// tmp.zig:2:5: error: switch must handle all possibilities diff --git a/test/compile_errors/stage1/obj/switch_expression-switch_on_pointer_type_with_no_else.zig b/test/compile_errors/stage1/obj/switch_expression-switch_on_pointer_type_with_no_else.zig new file mode 100644 index 0000000000..ec7565b882 --- /dev/null +++ b/test/compile_errors/stage1/obj/switch_expression-switch_on_pointer_type_with_no_else.zig @@ -0,0 +1,11 @@ +fn foo(x: *u8) void { + switch (x) { + &y => {}, + } +} +const y: u8 = 100; +export fn entry() usize { return @sizeOf(@TypeOf(foo)); } + +// switch expression - switch on pointer type with no else +// +// tmp.zig:2:5: error: else prong required when switching on type '*u8' diff --git a/test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_bool.zig b/test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_bool.zig new file mode 100644 index 0000000000..8c36a3c289 --- /dev/null +++ b/test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_bool.zig @@ -0,0 +1,12 @@ +fn foo(x: bool) void { + switch (x) { + true => {}, + false => {}, + else => {}, + } +} +export fn entry() usize { return @sizeOf(@TypeOf(foo)); } + +// switch expression - unreachable else prong (bool) +// +// tmp.zig:5:9: error: unreachable else prong, all cases already handled diff --git a/test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_enum.zig b/test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_enum.zig new file mode 100644 index 0000000000..8207d05234 --- /dev/null +++ b/test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_enum.zig @@ -0,0 +1,22 @@ +const TestEnum = enum{ T1, T2 }; + +fn err(x: u8) TestEnum { + switch (x) { + 0 => return TestEnum.T1, + else => return TestEnum.T2, + } +} + +fn foo(x: u8) void { + switch (err(x)) { + TestEnum.T1 => {}, + TestEnum.T2 => {}, + else => {}, + } +} + +export fn entry() usize { return @sizeOf(@TypeOf(foo)); } + +// switch expression - unreachable else prong (enum) +// +// tmp.zig:14:9: error: unreachable else prong, all cases already handled diff --git a/test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_range_i8.zig b/test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_range_i8.zig new file mode 100644 index 0000000000..8750e57fae --- /dev/null +++ b/test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_range_i8.zig @@ -0,0 +1,15 @@ +fn foo(x: i8) void { + switch (x) { + -128...0 => {}, + 1 => {}, + 2 => {}, + 3 => {}, + 4...127 => {}, + else => {}, + } +} +export fn entry() usize { return @sizeOf(@TypeOf(foo)); } + +// switch expression - unreachable else prong (range i8) +// +// tmp.zig:8:9: error: unreachable else prong, all cases already handled diff --git a/test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_range_u8.zig b/test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_range_u8.zig new file mode 100644 index 0000000000..280663ae51 --- /dev/null +++ b/test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_range_u8.zig @@ -0,0 +1,15 @@ +fn foo(x: u8) void { + switch (x) { + 0 => {}, + 1 => {}, + 2 => {}, + 3 => {}, + 4...255 => {}, + else => {}, + } +} +export fn entry() usize { return @sizeOf(@TypeOf(foo)); } + +// switch expression - unreachable else prong (range u8) +// +// tmp.zig:8:9: error: unreachable else prong, all cases already handled diff --git a/test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_u1.zig b/test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_u1.zig new file mode 100644 index 0000000000..58c4f378bf --- /dev/null +++ b/test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_u1.zig @@ -0,0 +1,12 @@ +fn foo(x: u1) void { + switch (x) { + 0 => {}, + 1 => {}, + else => {}, + } +} +export fn entry() usize { return @sizeOf(@TypeOf(foo)); } + +// switch expression - unreachable else prong (u1) +// +// tmp.zig:5:9: error: unreachable else prong, all cases already handled diff --git a/test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_u2.zig b/test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_u2.zig new file mode 100644 index 0000000000..ec1804316e --- /dev/null +++ b/test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_u2.zig @@ -0,0 +1,14 @@ +fn foo(x: u2) void { + switch (x) { + 0 => {}, + 1 => {}, + 2 => {}, + 3 => {}, + else => {}, + } +} +export fn entry() usize { return @sizeOf(@TypeOf(foo)); } + +// switch expression - unreachable else prong (u2) +// +// tmp.zig:7:9: error: unreachable else prong, all cases already handled diff --git a/test/compile_errors/stage1/obj/switch_on_enum_with_1_field_with_no_prongs.zig b/test/compile_errors/stage1/obj/switch_on_enum_with_1_field_with_no_prongs.zig new file mode 100644 index 0000000000..fbfc039f59 --- /dev/null +++ b/test/compile_errors/stage1/obj/switch_on_enum_with_1_field_with_no_prongs.zig @@ -0,0 +1,10 @@ +const Foo = enum { M }; + +export fn entry() void { + var f = Foo.M; + switch (f) {} +} + +// switch on enum with 1 field with no prongs +// +// tmp.zig:5:5: error: enumeration value 'Foo.M' not handled in switch diff --git a/test/compile_errors/stage1/obj/switch_on_union_with_no_attached_enum.zig b/test/compile_errors/stage1/obj/switch_on_union_with_no_attached_enum.zig new file mode 100644 index 0000000000..f1ae750b4b --- /dev/null +++ b/test/compile_errors/stage1/obj/switch_on_union_with_no_attached_enum.zig @@ -0,0 +1,20 @@ +const Payload = union { + A: i32, + B: f64, + C: bool, +}; +export fn entry() void { + const a = Payload { .A = 1234 }; + foo(a); +} +fn foo(a: *const Payload) void { + switch (a.*) { + Payload.A => {}, + else => unreachable, + } +} + +// switch on union with no attached enum +// +// tmp.zig:11:14: error: switch on union which has no attached enum +// tmp.zig:1:17: note: consider 'union(enum)' here diff --git a/test/compile_errors/stage1/obj/switch_with_invalid_expression_parameter.zig b/test/compile_errors/stage1/obj/switch_with_invalid_expression_parameter.zig new file mode 100644 index 0000000000..f65879bc7a --- /dev/null +++ b/test/compile_errors/stage1/obj/switch_with_invalid_expression_parameter.zig @@ -0,0 +1,15 @@ +export fn entry() void { + Test(i32); +} +fn Test(comptime T: type) void { + const x = switch (T) { + []u8 => |x| x, + i32 => |x| x, + else => unreachable, + }; + _ = x; +} + +// switch with invalid expression parameter +// +// tmp.zig:7:17: error: switch on type 'type' provides no expression parameter diff --git a/test/compile_errors/stage1/obj/switch_with_overlapping_case_ranges.zig b/test/compile_errors/stage1/obj/switch_with_overlapping_case_ranges.zig new file mode 100644 index 0000000000..2818d766a7 --- /dev/null +++ b/test/compile_errors/stage1/obj/switch_with_overlapping_case_ranges.zig @@ -0,0 +1,11 @@ +export fn entry() void { + var q: u8 = 0; + switch (q) { + 1...2 => {}, + 0...255 => {}, + } +} + +// switch with overlapping case ranges +// +// tmp.zig:5:9: error: duplicate switch value diff --git a/test/compile_errors/stage1/obj/tagName_used_on_union_with_no_associated_enum_tag.zig b/test/compile_errors/stage1/obj/tagName_used_on_union_with_no_associated_enum_tag.zig new file mode 100644 index 0000000000..bd03a97cfd --- /dev/null +++ b/test/compile_errors/stage1/obj/tagName_used_on_union_with_no_associated_enum_tag.zig @@ -0,0 +1,14 @@ +const FloatInt = extern union { + Float: f32, + Int: i32, +}; +export fn entry() void { + var fi = FloatInt{.Float = 123.45}; + var tagName = @tagName(fi); + _ = tagName; +} + +// @tagName used on union with no associated enum tag +// +// tmp.zig:7:19: error: union has no associated enum +// tmp.zig:1:18: note: declared here diff --git a/test/compile_errors/stage1/obj/take_slice_of_invalid_dereference.zig b/test/compile_errors/stage1/obj/take_slice_of_invalid_dereference.zig new file mode 100644 index 0000000000..9beda30e2f --- /dev/null +++ b/test/compile_errors/stage1/obj/take_slice_of_invalid_dereference.zig @@ -0,0 +1,8 @@ +export fn entry() void { + const x = 'a'.*[0..]; + _ = x; +} + +// take slice of invalid dereference +// +// tmp.zig:2:18: error: attempt to dereference non-pointer type 'comptime_int' diff --git a/test/compile_errors/stage1/obj/taking_bit_offset_of_void_field_in_struct.zig b/test/compile_errors/stage1/obj/taking_bit_offset_of_void_field_in_struct.zig new file mode 100644 index 0000000000..936a110a61 --- /dev/null +++ b/test/compile_errors/stage1/obj/taking_bit_offset_of_void_field_in_struct.zig @@ -0,0 +1,11 @@ +const Empty = struct { + val: void, +}; +export fn foo() void { + const fieldOffset = @bitOffsetOf(Empty, "val",); + _ = fieldOffset; +} + +// taking bit offset of void field in struct +// +// tmp.zig:5:45: error: zero-bit field 'val' in struct 'Empty' has no offset diff --git a/test/compile_errors/stage1/obj/taking_byte_offset_of_void_field_in_struct.zig b/test/compile_errors/stage1/obj/taking_byte_offset_of_void_field_in_struct.zig new file mode 100644 index 0000000000..d71dbc1502 --- /dev/null +++ b/test/compile_errors/stage1/obj/taking_byte_offset_of_void_field_in_struct.zig @@ -0,0 +1,11 @@ +const Empty = struct { + val: void, +}; +export fn foo() void { + const fieldOffset = @offsetOf(Empty, "val",); + _ = fieldOffset; +} + +// taking byte offset of void field in struct +// +// tmp.zig:5:42: error: zero-bit field 'val' in struct 'Empty' has no offset diff --git a/test/compile_errors/stage1/obj/threadlocal_qualifier_on_const.zig b/test/compile_errors/stage1/obj/threadlocal_qualifier_on_const.zig new file mode 100644 index 0000000000..fa99e592ae --- /dev/null +++ b/test/compile_errors/stage1/obj/threadlocal_qualifier_on_const.zig @@ -0,0 +1,8 @@ +threadlocal const x: i32 = 1234; +export fn entry() i32 { + return x; +} + +// threadlocal qualifier on const +// +// tmp.zig:1:1: error: threadlocal variable cannot be constant diff --git a/test/compile_errors/stage1/obj/top_level_decl_dependency_loop.zig b/test/compile_errors/stage1/obj/top_level_decl_dependency_loop.zig new file mode 100644 index 0000000000..4ecdc6f67d --- /dev/null +++ b/test/compile_errors/stage1/obj/top_level_decl_dependency_loop.zig @@ -0,0 +1,10 @@ +const a : @TypeOf(b) = 0; +const b : @TypeOf(a) = 0; +export fn entry() void { + const c = a + b; + _ = c; +} + +// top level decl dependency loop +// +// tmp.zig:2:19: error: dependency loop detected diff --git a/test/compile_errors/stage1/obj/truncate_sign_mismatch.zig b/test/compile_errors/stage1/obj/truncate_sign_mismatch.zig new file mode 100644 index 0000000000..a60ca4bc7a --- /dev/null +++ b/test/compile_errors/stage1/obj/truncate_sign_mismatch.zig @@ -0,0 +1,23 @@ +export fn entry1() i8 { + var x: u32 = 10; + return @truncate(i8, x); +} +export fn entry2() u8 { + var x: i32 = -10; + return @truncate(u8, x); +} +export fn entry3() i8 { + comptime var x: u32 = 10; + return @truncate(i8, x); +} +export fn entry4() u8 { + comptime var x: i32 = -10; + return @truncate(u8, x); +} + +// truncate sign mismatch +// +// tmp.zig:3:26: error: expected signed integer type, found 'u32' +// tmp.zig:7:26: error: expected unsigned integer type, found 'i32' +// tmp.zig:11:26: error: expected signed integer type, found 'u32' +// tmp.zig:15:26: error: expected unsigned integer type, found 'i32' diff --git a/test/compile_errors/stage1/obj/truncate_undefined_value.zig b/test/compile_errors/stage1/obj/truncate_undefined_value.zig new file mode 100644 index 0000000000..9d3913f9c3 --- /dev/null +++ b/test/compile_errors/stage1/obj/truncate_undefined_value.zig @@ -0,0 +1,8 @@ +export fn entry() void { + var z = @truncate(u8, @as(u16, undefined)); + _ = z; +} + +// @truncate undefined value +// +// tmp.zig:2:27: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/try_in_function_with_non_error_return_type.zig b/test/compile_errors/stage1/obj/try_in_function_with_non_error_return_type.zig new file mode 100644 index 0000000000..d799f769b6 --- /dev/null +++ b/test/compile_errors/stage1/obj/try_in_function_with_non_error_return_type.zig @@ -0,0 +1,8 @@ +export fn f() void { + try something(); +} +fn something() anyerror!void { } + +// try in function with non error return type +// +// tmp.zig:2:5: error: expected type 'void', found 'anyerror' diff --git a/test/compile_errors/stage1/obj/type_checking_function_pointers.zig b/test/compile_errors/stage1/obj/type_checking_function_pointers.zig new file mode 100644 index 0000000000..d9bcde6bab --- /dev/null +++ b/test/compile_errors/stage1/obj/type_checking_function_pointers.zig @@ -0,0 +1,11 @@ +fn a(b: fn (*const u8) void) void { + b('a'); +} +fn c(d: u8) void {_ = d;} +export fn entry() void { + a(c); +} + +// type checking function pointers +// +// tmp.zig:6:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void' diff --git a/test/compile_errors/stage1/obj/type_variables_must_be_constant.zig b/test/compile_errors/stage1/obj/type_variables_must_be_constant.zig new file mode 100644 index 0000000000..33846d6da8 --- /dev/null +++ b/test/compile_errors/stage1/obj/type_variables_must_be_constant.zig @@ -0,0 +1,8 @@ +var foo = u8; +export fn entry() foo { + return 1; +} + +// type variables must be constant +// +// tmp.zig:1:1: error: variable of type 'type' must be constant diff --git a/test/compile_errors/stage1/obj/undeclared_identifier.zig b/test/compile_errors/stage1/obj/undeclared_identifier.zig new file mode 100644 index 0000000000..36f46a22f4 --- /dev/null +++ b/test/compile_errors/stage1/obj/undeclared_identifier.zig @@ -0,0 +1,9 @@ +export fn a() void { + return + b + + c; +} + +// undeclared identifier +// +// tmp.zig:3:5: error: use of undeclared identifier 'b' diff --git a/test/compile_errors/stage1/obj/undeclared_identifier_error_should_mark_fn_as_impure.zig b/test/compile_errors/stage1/obj/undeclared_identifier_error_should_mark_fn_as_impure.zig new file mode 100644 index 0000000000..fa629bdcb8 --- /dev/null +++ b/test/compile_errors/stage1/obj/undeclared_identifier_error_should_mark_fn_as_impure.zig @@ -0,0 +1,10 @@ +export fn foo() void { + test_a_thing(); +} +fn test_a_thing() void { + bad_fn_call(); +} + +// undeclared identifier error should mark fn as impure +// +// tmp.zig:5:5: error: use of undeclared identifier 'bad_fn_call' diff --git a/test/compile_errors/stage1/obj/undeclared_identifier_in_unanalyzed_branch.zig b/test/compile_errors/stage1/obj/undeclared_identifier_in_unanalyzed_branch.zig new file mode 100644 index 0000000000..55d952e0fd --- /dev/null +++ b/test/compile_errors/stage1/obj/undeclared_identifier_in_unanalyzed_branch.zig @@ -0,0 +1,9 @@ +export fn a() void { + if (false) { + lol_this_doesnt_exist = nonsense; + } +} + +// undeclared identifier in unanalyzed branch +// +// tmp.zig:3:9: error: use of undeclared identifier 'lol_this_doesnt_exist' diff --git a/test/compile_errors/stage1/obj/undefined_as_field_type_is_rejected.zig b/test/compile_errors/stage1/obj/undefined_as_field_type_is_rejected.zig new file mode 100644 index 0000000000..4035955387 --- /dev/null +++ b/test/compile_errors/stage1/obj/undefined_as_field_type_is_rejected.zig @@ -0,0 +1,11 @@ +const Foo = struct { + a: undefined, +}; +export fn entry1() void { + const foo: Foo = undefined; + _ = foo; +} + +// undefined as field type is rejected +// +// tmp.zig:2:8: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/undefined_function_call.zig b/test/compile_errors/stage1/obj/undefined_function_call.zig new file mode 100644 index 0000000000..ebf76aafbd --- /dev/null +++ b/test/compile_errors/stage1/obj/undefined_function_call.zig @@ -0,0 +1,7 @@ +export fn a() void { + b(); +} + +// undefined function call +// +// tmp.zig:2:5: error: use of undeclared identifier 'b' diff --git a/test/compile_errors/stage1/obj/underscore_is_not_a_declarable_symbol.zig b/test/compile_errors/stage1/obj/underscore_is_not_a_declarable_symbol.zig new file mode 100644 index 0000000000..bfcfbc3bcc --- /dev/null +++ b/test/compile_errors/stage1/obj/underscore_is_not_a_declarable_symbol.zig @@ -0,0 +1,8 @@ +export fn f1() usize { + var _: usize = 2; + return _; +} + +// `_` is not a declarable symbol +// +// tmp.zig:2:9: error: '_' used as an identifier without @"_" syntax diff --git a/test/compile_errors/stage1/obj/underscore_should_not_be_usable_inside_for.zig b/test/compile_errors/stage1/obj/underscore_should_not_be_usable_inside_for.zig new file mode 100644 index 0000000000..be2ae559f3 --- /dev/null +++ b/test/compile_errors/stage1/obj/underscore_should_not_be_usable_inside_for.zig @@ -0,0 +1,11 @@ +export fn returns() void { + for ([_]void{}) |_, i| { + for ([_]void{}) |_, j| { + return _; + } + } +} + +// `_` should not be usable inside for +// +// tmp.zig:4:20: error: '_' used as an identifier without @"_" syntax diff --git a/test/compile_errors/stage1/obj/underscore_should_not_be_usable_inside_while.zig b/test/compile_errors/stage1/obj/underscore_should_not_be_usable_inside_while.zig new file mode 100644 index 0000000000..d93ed28c9e --- /dev/null +++ b/test/compile_errors/stage1/obj/underscore_should_not_be_usable_inside_while.zig @@ -0,0 +1,14 @@ +export fn returns() void { + while (optionalReturn()) |_| { + while (optionalReturn()) |_| { + return _; + } + } +} +fn optionalReturn() ?u32 { + return 1; +} + +// `_` should not be usable inside while +// +// tmp.zig:4:20: error: '_' used as an identifier without @"_" syntax diff --git a/test/compile_errors/stage1/obj/underscore_should_not_be_usable_inside_while_else.zig b/test/compile_errors/stage1/obj/underscore_should_not_be_usable_inside_while_else.zig new file mode 100644 index 0000000000..e1e4c7b4c1 --- /dev/null +++ b/test/compile_errors/stage1/obj/underscore_should_not_be_usable_inside_while_else.zig @@ -0,0 +1,16 @@ +export fn returns() void { + while (optionalReturnError()) |_| { + while (optionalReturnError()) |_| { + return; + } else |_| { + if (_ == error.optionalReturnError) return; + } + } +} +fn optionalReturnError() !?u32 { + return error.optionalReturnError; +} + +// `_` should not be usable inside while else +// +// tmp.zig:6:17: error: '_' used as an identifier without @"_" syntax diff --git a/test/compile_errors/stage1/obj/union_auto-enum_value_already_taken.zig b/test/compile_errors/stage1/obj/union_auto-enum_value_already_taken.zig new file mode 100644 index 0000000000..377290bd7e --- /dev/null +++ b/test/compile_errors/stage1/obj/union_auto-enum_value_already_taken.zig @@ -0,0 +1,16 @@ +const MultipleChoice = union(enum(u32)) { + A = 20, + B = 40, + C = 60, + D = 1000, + E = 60, +}; +export fn entry() void { + var x = MultipleChoice { .C = {} }; + _ = x; +} + +// union auto-enum value already taken +// +// tmp.zig:6:9: error: enum tag value 60 already taken +// tmp.zig:4:9: note: other occurrence here diff --git a/test/compile_errors/stage1/obj/union_enum_field_does_not_match_enum.zig b/test/compile_errors/stage1/obj/union_enum_field_does_not_match_enum.zig new file mode 100644 index 0000000000..a924932c9f --- /dev/null +++ b/test/compile_errors/stage1/obj/union_enum_field_does_not_match_enum.zig @@ -0,0 +1,20 @@ +const Letter = enum { + A, + B, + C, +}; +const Payload = union(Letter) { + A: i32, + B: f64, + C: bool, + D: bool, +}; +export fn entry() void { + var a = Payload {.A = 1234}; + _ = a; +} + +// union enum field does not match enum +// +// tmp.zig:10:5: error: enum field not found: 'D' +// tmp.zig:1:16: note: enum declared here diff --git a/test/compile_errors/stage1/obj/union_fields_with_value_assignments.zig b/test/compile_errors/stage1/obj/union_fields_with_value_assignments.zig new file mode 100644 index 0000000000..0cf67a0eca --- /dev/null +++ b/test/compile_errors/stage1/obj/union_fields_with_value_assignments.zig @@ -0,0 +1,12 @@ +const MultipleChoice = union { + A: i32 = 20, +}; +export fn entry() void { + var x: MultipleChoice = undefined; + _ = x; +} + +// union fields with value assignments +// +// tmp.zig:1:24: error: explicitly valued tagged union missing integer tag type +// tmp.zig:2:14: note: tag value specified here diff --git a/test/compile_errors/stage1/obj/union_with_0_fields.zig b/test/compile_errors/stage1/obj/union_with_0_fields.zig new file mode 100644 index 0000000000..36086e8cce --- /dev/null +++ b/test/compile_errors/stage1/obj/union_with_0_fields.zig @@ -0,0 +1,5 @@ +const Foo = union {}; + +// union with 0 fields +// +// tmp.zig:1:13: error: union declarations must have at least one tag diff --git a/test/compile_errors/stage1/obj/union_with_specified_enum_omits_field.zig b/test/compile_errors/stage1/obj/union_with_specified_enum_omits_field.zig new file mode 100644 index 0000000000..c1c1d38f02 --- /dev/null +++ b/test/compile_errors/stage1/obj/union_with_specified_enum_omits_field.zig @@ -0,0 +1,17 @@ +const Letter = enum { + A, + B, + C, +}; +const Payload = union(Letter) { + A: i32, + B: f64, +}; +export fn entry() usize { + return @sizeOf(Payload); +} + +// union with specified enum omits field +// +// tmp.zig:6:17: error: enum field missing: 'C' +// tmp.zig:4:5: note: declared here diff --git a/test/compile_errors/stage1/obj/union_with_too_small_explicit_signed_tag_type.zig b/test/compile_errors/stage1/obj/union_with_too_small_explicit_signed_tag_type.zig new file mode 100644 index 0000000000..a3e75c25f6 --- /dev/null +++ b/test/compile_errors/stage1/obj/union_with_too_small_explicit_signed_tag_type.zig @@ -0,0 +1,14 @@ +const U = union(enum(i2)) { + A: u8, + B: u8, + C: u8, + D: u8, +}; +export fn entry() void { + _ = U{ .D = 1 }; +} + +// union with too small explicit signed tag type +// +// tmp.zig:1:22: error: specified integer tag type cannot represent every field +// tmp.zig:1:22: note: type i2 cannot fit values in range 0...3 diff --git a/test/compile_errors/stage1/obj/union_with_too_small_explicit_unsigned_tag_type.zig b/test/compile_errors/stage1/obj/union_with_too_small_explicit_unsigned_tag_type.zig new file mode 100644 index 0000000000..6f13dcda8a --- /dev/null +++ b/test/compile_errors/stage1/obj/union_with_too_small_explicit_unsigned_tag_type.zig @@ -0,0 +1,15 @@ +const U = union(enum(u2)) { + A: u8, + B: u8, + C: u8, + D: u8, + E: u8, +}; +export fn entry() void { + _ = U{ .E = 1 }; +} + +// union with too small explicit unsigned tag type +// +// tmp.zig:1:22: error: specified integer tag type cannot represent every field +// tmp.zig:1:22: note: type u2 cannot fit values in range 0...4 diff --git a/test/compile_errors/stage1/obj/unknown_length_pointer_to_opaque.zig b/test/compile_errors/stage1/obj/unknown_length_pointer_to_opaque.zig new file mode 100644 index 0000000000..a847bae599 --- /dev/null +++ b/test/compile_errors/stage1/obj/unknown_length_pointer_to_opaque.zig @@ -0,0 +1,5 @@ +export const T = [*]opaque {}; + +// unknown length pointer to opaque +// +// tmp.zig:1:21: error: unknown-length pointer to opaque diff --git a/test/compile_errors/stage1/obj/unreachable_code-double_break.zig b/test/compile_errors/stage1/obj/unreachable_code-double_break.zig new file mode 100644 index 0000000000..b030c1d24d --- /dev/null +++ b/test/compile_errors/stage1/obj/unreachable_code-double_break.zig @@ -0,0 +1,10 @@ +export fn a() void { + const b = blk: { + break :blk break :blk @as(u32, 1); + }; +} + +// unreachable code - double break +// +// tmp.zig:3:9: error: unreachable code +// tmp.zig:3:20: note: control flow is diverted here diff --git a/test/compile_errors/stage1/obj/unreachable_code-nested_returns.zig b/test/compile_errors/stage1/obj/unreachable_code-nested_returns.zig new file mode 100644 index 0000000000..7bfa8eef64 --- /dev/null +++ b/test/compile_errors/stage1/obj/unreachable_code-nested_returns.zig @@ -0,0 +1,8 @@ +export fn a() i32 { + return return 1; +} + +// unreachable code - nested returns +// +// tmp.zig:2:5: error: unreachable code +// tmp.zig:2:12: note: control flow is diverted here diff --git a/test/compile_errors/stage1/obj/unreachable_code.zig b/test/compile_errors/stage1/obj/unreachable_code.zig new file mode 100644 index 0000000000..779cd90379 --- /dev/null +++ b/test/compile_errors/stage1/obj/unreachable_code.zig @@ -0,0 +1,11 @@ +export fn a() void { + return; + b(); +} + +fn b() void {} + +// unreachable code +// +// tmp.zig:3:6: error: unreachable code +// tmp.zig:2:5: note: control flow is diverted here diff --git a/test/compile_errors/stage1/obj/unreachable_executed_at_comptime.zig b/test/compile_errors/stage1/obj/unreachable_executed_at_comptime.zig new file mode 100644 index 0000000000..857ab0417f --- /dev/null +++ b/test/compile_errors/stage1/obj/unreachable_executed_at_comptime.zig @@ -0,0 +1,14 @@ +fn foo(comptime x: i32) i32 { + comptime { + if (x >= 0) return -x; + unreachable; + } +} +export fn entry() void { + _ = foo(-42); +} + +// unreachable executed at comptime +// +// tmp.zig:4:9: error: reached unreachable code +// tmp.zig:8:12: note: called from here diff --git a/test/compile_errors/stage1/obj/unreachable_parameter.zig b/test/compile_errors/stage1/obj/unreachable_parameter.zig new file mode 100644 index 0000000000..3feed62a1e --- /dev/null +++ b/test/compile_errors/stage1/obj/unreachable_parameter.zig @@ -0,0 +1,6 @@ +fn f(a: noreturn) void { _ = a; } +export fn entry() void { f(); } + +// unreachable parameter +// +// tmp.zig:1:9: error: parameter of type 'noreturn' not allowed diff --git a/test/compile_errors/stage1/obj/unreachable_variable.zig b/test/compile_errors/stage1/obj/unreachable_variable.zig new file mode 100644 index 0000000000..8e053acd06 --- /dev/null +++ b/test/compile_errors/stage1/obj/unreachable_variable.zig @@ -0,0 +1,8 @@ +export fn f() void { + const a: noreturn = {}; + _ = a; +} + +// unreachable variable +// +// tmp.zig:2:25: error: expected type 'noreturn', found 'void' diff --git a/test/compile_errors/stage1/obj/unreachable_with_return.zig b/test/compile_errors/stage1/obj/unreachable_with_return.zig new file mode 100644 index 0000000000..ac9ecc93e3 --- /dev/null +++ b/test/compile_errors/stage1/obj/unreachable_with_return.zig @@ -0,0 +1,6 @@ +fn a() noreturn {return;} +export fn entry() void { a(); } + +// unreachable with return +// +// tmp.zig:1:18: error: expected type 'noreturn', found 'void' diff --git a/test/compile_errors/stage1/obj/unsupported_modifier_at_start_of_asm_output_constraint.zig b/test/compile_errors/stage1/obj/unsupported_modifier_at_start_of_asm_output_constraint.zig new file mode 100644 index 0000000000..c85850a61b --- /dev/null +++ b/test/compile_errors/stage1/obj/unsupported_modifier_at_start_of_asm_output_constraint.zig @@ -0,0 +1,8 @@ +export fn foo() void { + var bar: u32 = 3; + asm volatile ("" : [baz]"+r"(bar) : : ""); +} + +// unsupported modifier at start of asm output constraint +// +// tmp.zig:3:5: error: invalid modifier starting output constraint for 'baz': '+', only '=' is supported. Compiler TODO: see https://github.com/ziglang/zig/issues/215 diff --git a/test/compile_errors/stage1/obj/use_anyopaque_as_return_type_of_fn_ptr.zig b/test/compile_errors/stage1/obj/use_anyopaque_as_return_type_of_fn_ptr.zig new file mode 100644 index 0000000000..f54bc14914 --- /dev/null +++ b/test/compile_errors/stage1/obj/use_anyopaque_as_return_type_of_fn_ptr.zig @@ -0,0 +1,8 @@ +export fn entry() void { + const a: fn () anyopaque = undefined; + _ = a; +} + +// use anyopaque as return type of fn ptr +// +// tmp.zig:2:20: error: return type cannot be opaque diff --git a/test/compile_errors/stage1/obj/use_implicit_casts_to_assign_null_to_non-nullable_pointer.zig b/test/compile_errors/stage1/obj/use_implicit_casts_to_assign_null_to_non-nullable_pointer.zig new file mode 100644 index 0000000000..a8e01dbde0 --- /dev/null +++ b/test/compile_errors/stage1/obj/use_implicit_casts_to_assign_null_to_non-nullable_pointer.zig @@ -0,0 +1,12 @@ +export fn entry() void { + var x: i32 = 1234; + var p: *i32 = &x; + var pp: *?*i32 = &p; + pp.* = null; + var y = p.*; + _ = y; +} + +// use implicit casts to assign null to non-nullable pointer +// +// tmp.zig:4:23: error: expected type '*?*i32', found '**i32' diff --git a/test/compile_errors/stage1/obj/use_invalid_number_literal_as_array_index.zig b/test/compile_errors/stage1/obj/use_invalid_number_literal_as_array_index.zig new file mode 100644 index 0000000000..5ec655737e --- /dev/null +++ b/test/compile_errors/stage1/obj/use_invalid_number_literal_as_array_index.zig @@ -0,0 +1,9 @@ +var v = 25; +export fn entry() void { + var arr: [v]u8 = undefined; + _ = arr; +} + +// use invalid number literal as array index +// +// tmp.zig:1:1: error: unable to infer variable type diff --git a/test/compile_errors/stage1/obj/use_of_comptime-known_undefined_function_value.zig b/test/compile_errors/stage1/obj/use_of_comptime-known_undefined_function_value.zig new file mode 100644 index 0000000000..5facc7e753 --- /dev/null +++ b/test/compile_errors/stage1/obj/use_of_comptime-known_undefined_function_value.zig @@ -0,0 +1,11 @@ +const Cmd = struct { + exec: fn () void, +}; +export fn entry() void { + const command = Cmd{ .exec = undefined }; + command.exec(); +} + +// use of comptime-known undefined function value +// +// tmp.zig:6:12: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/use_of_undeclared_identifier.zig b/test/compile_errors/stage1/obj/use_of_undeclared_identifier.zig new file mode 100644 index 0000000000..e36453acc7 --- /dev/null +++ b/test/compile_errors/stage1/obj/use_of_undeclared_identifier.zig @@ -0,0 +1,7 @@ +export fn f() void { + b = 3; +} + +// use of undeclared identifier +// +// tmp.zig:2:5: error: use of undeclared identifier 'b' diff --git a/test/compile_errors/stage1/obj/using_an_unknown_len_ptr_type_instead_of_array.zig b/test/compile_errors/stage1/obj/using_an_unknown_len_ptr_type_instead_of_array.zig new file mode 100644 index 0000000000..983995b098 --- /dev/null +++ b/test/compile_errors/stage1/obj/using_an_unknown_len_ptr_type_instead_of_array.zig @@ -0,0 +1,11 @@ +const resolutions = [*][*]const u8{ + "[320 240 ]", + null, +}; +comptime { + _ = resolutions; +} + +// using an unknown len ptr type instead of array +// +// tmp.zig:1:21: error: expected array type or [_], found '[*][*]const u8' diff --git a/test/compile_errors/stage1/obj/using_invalid_types_in_function_call_raises_an_error.zig b/test/compile_errors/stage1/obj/using_invalid_types_in_function_call_raises_an_error.zig new file mode 100644 index 0000000000..182b5c59b0 --- /dev/null +++ b/test/compile_errors/stage1/obj/using_invalid_types_in_function_call_raises_an_error.zig @@ -0,0 +1,9 @@ +const MenuEffect = enum {}; +fn func(effect: MenuEffect) void { _ = effect; } +export fn entry() void { + func(MenuEffect.ThisDoesNotExist); +} + +// using invalid types in function call raises an error +// +// tmp.zig:1:20: error: enum declarations must have at least one tag diff --git a/test/compile_errors/stage1/obj/usingnamespace_with_wrong_type.zig b/test/compile_errors/stage1/obj/usingnamespace_with_wrong_type.zig new file mode 100644 index 0000000000..a74a8e6124 --- /dev/null +++ b/test/compile_errors/stage1/obj/usingnamespace_with_wrong_type.zig @@ -0,0 +1,5 @@ +usingnamespace void; + +// usingnamespace with wrong type +// +// tmp.zig:1:1: error: expected struct, enum, or union; found 'void' diff --git a/test/compile_errors/stage1/obj/variable_has_wrong_type.zig b/test/compile_errors/stage1/obj/variable_has_wrong_type.zig new file mode 100644 index 0000000000..1e20dde269 --- /dev/null +++ b/test/compile_errors/stage1/obj/variable_has_wrong_type.zig @@ -0,0 +1,8 @@ +export fn f() i32 { + const a = "a"; + return a; +} + +// variable has wrong type +// +// tmp.zig:3:12: error: expected type 'i32', found '*const [1:0]u8' diff --git a/test/compile_errors/stage1/obj/variable_initialization_compile_error_then_referenced.zig b/test/compile_errors/stage1/obj/variable_initialization_compile_error_then_referenced.zig new file mode 100644 index 0000000000..d96b67bc3f --- /dev/null +++ b/test/compile_errors/stage1/obj/variable_initialization_compile_error_then_referenced.zig @@ -0,0 +1,17 @@ +fn Undeclared() type { + return T; +} +fn Gen() type { + const X = Undeclared(); + return struct { + x: X, + }; +} +export fn entry() void { + const S = Gen(); + _ = S; +} + +// variable initialization compile error then referenced +// +// tmp.zig:2:12: error: use of undeclared identifier 'T' diff --git a/test/compile_errors/stage1/obj/variable_with_type_noreturn.zig b/test/compile_errors/stage1/obj/variable_with_type_noreturn.zig new file mode 100644 index 0000000000..b6cc65593b --- /dev/null +++ b/test/compile_errors/stage1/obj/variable_with_type_noreturn.zig @@ -0,0 +1,8 @@ +export fn entry9() void { + var z: noreturn = return; +} + +// variable with type 'noreturn' +// +// tmp.zig:2:5: error: unreachable code +// tmp.zig:2:23: note: control flow is diverted here diff --git a/test/compile_errors/stage1/obj/vector_index_out_of_bounds.zig b/test/compile_errors/stage1/obj/vector_index_out_of_bounds.zig new file mode 100644 index 0000000000..efdd8b5fe9 --- /dev/null +++ b/test/compile_errors/stage1/obj/vector_index_out_of_bounds.zig @@ -0,0 +1,8 @@ +export fn entry() void { + const x = @import("std").meta.Vector(3, f32){ 25, 75, 5, 0 }; + _ = x; +} + +// vector index out of bounds +// +// tmp.zig:2:62: error: index 3 outside vector of size 3 diff --git a/test/compile_errors/stage1/obj/volatile_on_global_assembly.zig b/test/compile_errors/stage1/obj/volatile_on_global_assembly.zig new file mode 100644 index 0000000000..8fc7ddfcc2 --- /dev/null +++ b/test/compile_errors/stage1/obj/volatile_on_global_assembly.zig @@ -0,0 +1,7 @@ +comptime { + asm volatile (""); +} + +// volatile on global assembly +// +// tmp.zig:2:9: error: volatile is meaningless on global assembly diff --git a/test/compile_errors/stage1/obj/wasmMemoryGrow_is_a_compile_error_in_non-Wasm_targets.zig b/test/compile_errors/stage1/obj/wasmMemoryGrow_is_a_compile_error_in_non-Wasm_targets.zig new file mode 100644 index 0000000000..363b36a0af --- /dev/null +++ b/test/compile_errors/stage1/obj/wasmMemoryGrow_is_a_compile_error_in_non-Wasm_targets.zig @@ -0,0 +1,8 @@ +export fn foo() void { + _ = @wasmMemoryGrow(0, 1); + return; +} + +// wasmMemoryGrow is a compile error in non-Wasm targets +// +// tmp.zig:2:9: error: @wasmMemoryGrow is a wasm32 feature only diff --git a/test/compile_errors/stage1/obj/wasmMemorySize_is_a_compile_error_in_non-Wasm_targets.zig b/test/compile_errors/stage1/obj/wasmMemorySize_is_a_compile_error_in_non-Wasm_targets.zig new file mode 100644 index 0000000000..419173bd01 --- /dev/null +++ b/test/compile_errors/stage1/obj/wasmMemorySize_is_a_compile_error_in_non-Wasm_targets.zig @@ -0,0 +1,8 @@ +export fn foo() void { + _ = @wasmMemorySize(0); + return; +} + +// wasmMemorySize is a compile error in non-Wasm targets +// +// tmp.zig:2:9: error: @wasmMemorySize is a wasm32 feature only diff --git a/test/compile_errors/stage1/obj/while_expected_bool_got_error_union.zig b/test/compile_errors/stage1/obj/while_expected_bool_got_error_union.zig new file mode 100644 index 0000000000..e79296694d --- /dev/null +++ b/test/compile_errors/stage1/obj/while_expected_bool_got_error_union.zig @@ -0,0 +1,8 @@ +export fn foo() void { + while (bar()) {} +} +fn bar() anyerror!i32 { return 1; } + +// while expected bool, got error union +// +// tmp.zig:2:15: error: expected type 'bool', found 'anyerror!i32' diff --git a/test/compile_errors/stage1/obj/while_expected_bool_got_optional.zig b/test/compile_errors/stage1/obj/while_expected_bool_got_optional.zig new file mode 100644 index 0000000000..7a3d184a1d --- /dev/null +++ b/test/compile_errors/stage1/obj/while_expected_bool_got_optional.zig @@ -0,0 +1,8 @@ +export fn foo() void { + while (bar()) {} +} +fn bar() ?i32 { return 1; } + +// while expected bool, got optional +// +// tmp.zig:2:15: error: expected type 'bool', found '?i32' diff --git a/test/compile_errors/stage1/obj/while_expected_error_union_got_bool.zig b/test/compile_errors/stage1/obj/while_expected_error_union_got_bool.zig new file mode 100644 index 0000000000..8f92276af6 --- /dev/null +++ b/test/compile_errors/stage1/obj/while_expected_error_union_got_bool.zig @@ -0,0 +1,8 @@ +export fn foo() void { + while (bar()) |x| {_ = x;} else |err| {_ = err;} +} +fn bar() bool { return true; } + +// while expected error union, got bool +// +// tmp.zig:2:15: error: expected error union type, found 'bool' diff --git a/test/compile_errors/stage1/obj/while_expected_error_union_got_optional.zig b/test/compile_errors/stage1/obj/while_expected_error_union_got_optional.zig new file mode 100644 index 0000000000..a67bf1ae16 --- /dev/null +++ b/test/compile_errors/stage1/obj/while_expected_error_union_got_optional.zig @@ -0,0 +1,8 @@ +export fn foo() void { + while (bar()) |x| {_ = x;} else |err| {_ = err;} +} +fn bar() ?i32 { return 1; } + +// while expected error union, got optional +// +// tmp.zig:2:15: error: expected error union type, found '?i32' diff --git a/test/compile_errors/stage1/obj/while_expected_optional_got_bool.zig b/test/compile_errors/stage1/obj/while_expected_optional_got_bool.zig new file mode 100644 index 0000000000..6fc0d880ce --- /dev/null +++ b/test/compile_errors/stage1/obj/while_expected_optional_got_bool.zig @@ -0,0 +1,8 @@ +export fn foo() void { + while (bar()) |x| {_ = x;} +} +fn bar() bool { return true; } + +// while expected optional, got bool +// +// tmp.zig:2:15: error: expected optional type, found 'bool' diff --git a/test/compile_errors/stage1/obj/while_expected_optional_got_error_union.zig b/test/compile_errors/stage1/obj/while_expected_optional_got_error_union.zig new file mode 100644 index 0000000000..472b3b81bc --- /dev/null +++ b/test/compile_errors/stage1/obj/while_expected_optional_got_error_union.zig @@ -0,0 +1,8 @@ +export fn foo() void { + while (bar()) |x| {_ = x;} +} +fn bar() anyerror!i32 { return 1; } + +// while expected optional, got error union +// +// tmp.zig:2:15: error: expected optional type, found 'anyerror!i32' diff --git a/test/compile_errors/stage1/obj/while_loop_body_expression_ignored.zig b/test/compile_errors/stage1/obj/while_loop_body_expression_ignored.zig new file mode 100644 index 0000000000..621c0d41d7 --- /dev/null +++ b/test/compile_errors/stage1/obj/while_loop_body_expression_ignored.zig @@ -0,0 +1,20 @@ +fn returns() usize { + return 2; +} +export fn f1() void { + while (true) returns(); +} +export fn f2() void { + var x: ?i32 = null; + while (x) |_| returns(); +} +export fn f3() void { + var x: anyerror!i32 = error.Bad; + while (x) |_| returns() else |_| unreachable; +} + +// while loop body expression ignored +// +// tmp.zig:5:25: error: expression value is ignored +// tmp.zig:9:26: error: expression value is ignored +// tmp.zig:13:26: error: expression value is ignored diff --git a/test/compile_errors/stage1/obj/write_to_const_global_variable.zig b/test/compile_errors/stage1/obj/write_to_const_global_variable.zig new file mode 100644 index 0000000000..327b3d02d0 --- /dev/null +++ b/test/compile_errors/stage1/obj/write_to_const_global_variable.zig @@ -0,0 +1,9 @@ +const x : i32 = 99; +fn f() void { + x = 1; +} +export fn entry() void { f(); } + +// write to const global variable +// +// tmp.zig:3:9: error: cannot assign to constant diff --git a/test/compile_errors/stage1/obj/wrong_frame_type_used_for_async_call.zig b/test/compile_errors/stage1/obj/wrong_frame_type_used_for_async_call.zig new file mode 100644 index 0000000000..ba150c45cc --- /dev/null +++ b/test/compile_errors/stage1/obj/wrong_frame_type_used_for_async_call.zig @@ -0,0 +1,14 @@ +export fn entry() void { + var frame: @Frame(foo) = undefined; + frame = async bar(); +} +fn foo() void { + suspend {} +} +fn bar() void { + suspend {} +} + +// wrong frame type used for async call +// +// tmp.zig:3:13: error: expected type '*@Frame(bar)', found '*@Frame(foo)' diff --git a/test/compile_errors/stage1/obj/wrong_function_type.zig b/test/compile_errors/stage1/obj/wrong_function_type.zig new file mode 100644 index 0000000000..c2238bb649 --- /dev/null +++ b/test/compile_errors/stage1/obj/wrong_function_type.zig @@ -0,0 +1,9 @@ +const fns = [_]fn() void { a, b, c }; +fn a() i32 {return 0;} +fn b() i32 {return 1;} +fn c() i32 {return 2;} +export fn entry() usize { return @sizeOf(@TypeOf(fns)); } + +// wrong function type +// +// tmp.zig:1:28: error: expected type 'fn() void', found 'fn() i32' diff --git a/test/compile_errors/stage1/obj/wrong_initializer_for_union_payload_of_type_type.zig b/test/compile_errors/stage1/obj/wrong_initializer_for_union_payload_of_type_type.zig new file mode 100644 index 0000000000..1d56094b6d --- /dev/null +++ b/test/compile_errors/stage1/obj/wrong_initializer_for_union_payload_of_type_type.zig @@ -0,0 +1,14 @@ +const U = union(enum) { + A: type, +}; +const S = struct { + u: U, +}; +export fn entry() void { + comptime var v: S = undefined; + v.u.A = U{ .A = i32 }; +} + +// wrong initializer for union payload of type 'type' +// +// tmp.zig:9:8: error: use of undefined value here causes undefined behavior diff --git a/test/compile_errors/stage1/obj/wrong_number_of_arguments.zig b/test/compile_errors/stage1/obj/wrong_number_of_arguments.zig new file mode 100644 index 0000000000..4cb13fdd12 --- /dev/null +++ b/test/compile_errors/stage1/obj/wrong_number_of_arguments.zig @@ -0,0 +1,8 @@ +export fn a() void { + c(1); +} +fn c(d: i32, e: i32, f: i32) void { _ = d; _ = e; _ = f; } + +// wrong number of arguments +// +// tmp.zig:2:6: error: expected 3 argument(s), found 1 diff --git a/test/compile_errors/stage1/obj/wrong_number_of_arguments_for_method_fn_call.zig b/test/compile_errors/stage1/obj/wrong_number_of_arguments_for_method_fn_call.zig new file mode 100644 index 0000000000..25449feb22 --- /dev/null +++ b/test/compile_errors/stage1/obj/wrong_number_of_arguments_for_method_fn_call.zig @@ -0,0 +1,12 @@ +const Foo = struct { + fn method(self: *const Foo, a: i32) void {_ = self; _ = a;} +}; +fn f(foo: *const Foo) void { + + foo.method(1, 2); +} +export fn entry() usize { return @sizeOf(@TypeOf(f)); } + +// wrong number of arguments for method fn call +// +// tmp.zig:6:15: error: expected 2 argument(s), found 3 diff --git a/test/compile_errors/stage1/obj/wrong_panic_signature_generic_function.zig b/test/compile_errors/stage1/obj/wrong_panic_signature_generic_function.zig new file mode 100644 index 0000000000..faaa24ba60 --- /dev/null +++ b/test/compile_errors/stage1/obj/wrong_panic_signature_generic_function.zig @@ -0,0 +1,10 @@ +pub fn panic(comptime msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn { + _ = msg; _ = error_return_trace; + while (true) {} +} +const builtin = @import("std").builtin; + +// wrong panic signature, generic function +// +// error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn([]const u8,anytype) anytype' +// note: only one of the functions is generic diff --git a/test/compile_errors/stage1/obj/wrong_panic_signature_runtime_function.zig b/test/compile_errors/stage1/obj/wrong_panic_signature_runtime_function.zig new file mode 100644 index 0000000000..92553c3104 --- /dev/null +++ b/test/compile_errors/stage1/obj/wrong_panic_signature_runtime_function.zig @@ -0,0 +1,8 @@ +test "" {} + +pub fn panic() void {} + + +// wrong panic signature, runtime function +// +// error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn() void' diff --git a/test/compile_errors/stage1/obj/wrong_pointer_coerced_to_pointer_to_opaque_{}.zig b/test/compile_errors/stage1/obj/wrong_pointer_coerced_to_pointer_to_opaque_{}.zig new file mode 100644 index 0000000000..ed88e3be28 --- /dev/null +++ b/test/compile_errors/stage1/obj/wrong_pointer_coerced_to_pointer_to_opaque_{}.zig @@ -0,0 +1,10 @@ +const Derp = opaque {}; +extern fn bar(d: *Derp) void; +export fn foo() void { + var x = @as(u8, 1); + bar(@ptrCast(*anyopaque, &x)); +} + +// wrong pointer coerced to pointer to opaque {} +// +// tmp.zig:5:9: error: expected type '*Derp', found '*anyopaque' diff --git a/test/compile_errors/stage1/obj/wrong_return_type_for_main.zig b/test/compile_errors/stage1/obj/wrong_return_type_for_main.zig new file mode 100644 index 0000000000..bf335874db --- /dev/null +++ b/test/compile_errors/stage1/obj/wrong_return_type_for_main.zig @@ -0,0 +1,5 @@ +pub fn main() f32 { } + +// wrong return type for main +// +// error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8' diff --git a/test/compile_errors/stage1/obj/wrong_size_to_an_array_literal.zig b/test/compile_errors/stage1/obj/wrong_size_to_an_array_literal.zig new file mode 100644 index 0000000000..68cb263212 --- /dev/null +++ b/test/compile_errors/stage1/obj/wrong_size_to_an_array_literal.zig @@ -0,0 +1,8 @@ +comptime { + const array = [2]u8{1, 2, 3}; + _ = array; +} + +// wrong size to an array literal +// +// tmp.zig:2:31: error: index 2 outside array of size 2 diff --git a/test/compile_errors/stage1/obj/wrong_type_for_argument_tuple_to_asyncCall.zig b/test/compile_errors/stage1/obj/wrong_type_for_argument_tuple_to_asyncCall.zig new file mode 100644 index 0000000000..d9e45a69b7 --- /dev/null +++ b/test/compile_errors/stage1/obj/wrong_type_for_argument_tuple_to_asyncCall.zig @@ -0,0 +1,12 @@ +export fn entry1() void { + var frame: @Frame(foo) = undefined; + @asyncCall(&frame, {}, foo, {}); +} + +fn foo() i32 { + return 0; +} + +// wrong type for argument tuple to @asyncCall +// +// tmp.zig:3:33: error: expected tuple or struct, found 'void' diff --git a/test/compile_errors/stage1/obj/wrong_type_for_reify_type.zig b/test/compile_errors/stage1/obj/wrong_type_for_reify_type.zig new file mode 100644 index 0000000000..2d8ea02326 --- /dev/null +++ b/test/compile_errors/stage1/obj/wrong_type_for_reify_type.zig @@ -0,0 +1,7 @@ +export fn entry() void { + _ = @Type(0); +} + +// wrong type for @Type +// +// tmp.zig:2:15: error: expected type 'std.builtin.Type', found 'comptime_int' diff --git a/test/compile_errors/stage1/obj/wrong_type_for_result_ptr_to_asyncCall.zig b/test/compile_errors/stage1/obj/wrong_type_for_result_ptr_to_asyncCall.zig new file mode 100644 index 0000000000..07c5ae8a0b --- /dev/null +++ b/test/compile_errors/stage1/obj/wrong_type_for_result_ptr_to_asyncCall.zig @@ -0,0 +1,14 @@ +export fn entry() void { + _ = async amain(); +} +fn amain() i32 { + var frame: @Frame(foo) = undefined; + return await @asyncCall(&frame, false, foo, .{}); +} +fn foo() i32 { + return 1234; +} + +// wrong type for result ptr to @asyncCall +// +// tmp.zig:6:37: error: expected type '*i32', found 'bool' diff --git a/test/compile_errors/stage1/obj/wrong_type_passed_to_panic.zig b/test/compile_errors/stage1/obj/wrong_type_passed_to_panic.zig new file mode 100644 index 0000000000..b16d563571 --- /dev/null +++ b/test/compile_errors/stage1/obj/wrong_type_passed_to_panic.zig @@ -0,0 +1,8 @@ +export fn entry() void { + var e = error.Foo; + @panic(e); +} + +// wrong type passed to @panic +// +// tmp.zig:3:12: error: expected type '[]const u8', found 'error{Foo}' diff --git a/test/compile_errors/stage1/obj/wrong_type_to_hasField.zig b/test/compile_errors/stage1/obj/wrong_type_to_hasField.zig new file mode 100644 index 0000000000..a79fec2a21 --- /dev/null +++ b/test/compile_errors/stage1/obj/wrong_type_to_hasField.zig @@ -0,0 +1,7 @@ +export fn entry() bool { + return @hasField(i32, "hi"); +} + +// wrong type to @hasField +// +// tmp.zig:2:22: error: type 'i32' does not support @hasField diff --git a/test/compile_errors/stage1/obj/wrong_types_given_to_atomic_order_args_in_cmpxchg.zig b/test/compile_errors/stage1/obj/wrong_types_given_to_atomic_order_args_in_cmpxchg.zig new file mode 100644 index 0000000000..47cdaa372f --- /dev/null +++ b/test/compile_errors/stage1/obj/wrong_types_given_to_atomic_order_args_in_cmpxchg.zig @@ -0,0 +1,8 @@ +export fn entry() void { + var x: i32 = 1234; + while (!@cmpxchgWeak(i32, &x, 1234, 5678, @as(u32, 1234), @as(u32, 1234))) {} +} + +// wrong types given to atomic order args in cmpxchg +// +// tmp.zig:3:47: error: expected type 'std.builtin.AtomicOrder', found 'u32' diff --git a/test/compile_errors/stage1/obj/wrong_types_given_to_export.zig b/test/compile_errors/stage1/obj/wrong_types_given_to_export.zig new file mode 100644 index 0000000000..cdd7ab4631 --- /dev/null +++ b/test/compile_errors/stage1/obj/wrong_types_given_to_export.zig @@ -0,0 +1,8 @@ +fn entry() callconv(.C) void { } +comptime { + @export(entry, .{.name = "entry", .linkage = @as(u32, 1234) }); +} + +// wrong types given to @export +// +// tmp.zig:3:59: error: expected type 'std.builtin.GlobalLinkage', found 'comptime_int' diff --git a/test/compile_errors/stage1/test/access_invalid_typeInfo_decl.zig b/test/compile_errors/stage1/test/access_invalid_typeInfo_decl.zig new file mode 100644 index 0000000000..2fc5730af0 --- /dev/null +++ b/test/compile_errors/stage1/test/access_invalid_typeInfo_decl.zig @@ -0,0 +1,8 @@ +const A = B; +test "Crash" { + _ = @typeInfo(@This()).Struct.decls[0]; +} + +// access invalid @typeInfo decl +// +// tmp.zig:1:11: error: use of undeclared identifier 'B' diff --git a/test/compile_errors/stage1/test/alignCast_of_zero_sized_types.zig b/test/compile_errors/stage1/test/alignCast_of_zero_sized_types.zig new file mode 100644 index 0000000000..4c05571202 --- /dev/null +++ b/test/compile_errors/stage1/test/alignCast_of_zero_sized_types.zig @@ -0,0 +1,25 @@ +export fn foo() void { + const a: *void = undefined; + _ = @alignCast(2, a); +} +export fn bar() void { + const a: ?*void = undefined; + _ = @alignCast(2, a); +} +export fn baz() void { + const a: []void = undefined; + _ = @alignCast(2, a); +} +export fn qux() void { + const a = struct { + fn a(comptime b: u32) void { _ = b; } + }.a; + _ = @alignCast(2, a); +} + +// @alignCast of zero sized types +// +// tmp.zig:3:23: error: cannot adjust alignment of zero sized type '*void' +// tmp.zig:7:23: error: cannot adjust alignment of zero sized type '?*void' +// tmp.zig:11:23: error: cannot adjust alignment of zero sized type '[]void' +// tmp.zig:17:23: error: cannot adjust alignment of zero sized type 'fn(u32) anytype' diff --git a/test/compile_errors/stage1/test/bad_splat_type.zig b/test/compile_errors/stage1/test/bad_splat_type.zig new file mode 100644 index 0000000000..9a16bbc73d --- /dev/null +++ b/test/compile_errors/stage1/test/bad_splat_type.zig @@ -0,0 +1,9 @@ +export fn entry() void { + const c = 4; + var v = @splat(4, c); + _ = v; +} + +// bad @splat type +// +// tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; 'comptime_int' is invalid diff --git a/test/compile_errors/stage1/test/binary_OR_operator_on_error_sets.zig b/test/compile_errors/stage1/test/binary_OR_operator_on_error_sets.zig new file mode 100644 index 0000000000..d9894a32a0 --- /dev/null +++ b/test/compile_errors/stage1/test/binary_OR_operator_on_error_sets.zig @@ -0,0 +1,10 @@ +pub const A = error.A; +pub const AB = A | error.B; +export fn entry() void { + var x: AB = undefined; + _ = x; +} + +// binary OR operator on error sets +// +// tmp.zig:2:18: error: invalid operands to binary expression: 'error{A}' and 'error{B}' diff --git a/test/compile_errors/stage1/test/call_rejects_non_comptime-known_fn-always_inline.zig b/test/compile_errors/stage1/test/call_rejects_non_comptime-known_fn-always_inline.zig new file mode 100644 index 0000000000..ea822f8d91 --- /dev/null +++ b/test/compile_errors/stage1/test/call_rejects_non_comptime-known_fn-always_inline.zig @@ -0,0 +1,8 @@ +pub export fn entry() void { + var call_me: fn () void = undefined; + @call(.{ .modifier = .always_inline }, call_me, .{}); +} + +// @call rejects non comptime-known fn - always_inline +// +// tmp.zig:3:5: error: the specified modifier requires a comptime-known function diff --git a/test/compile_errors/stage1/test/call_rejects_non_comptime-known_fn-compile_time.zig b/test/compile_errors/stage1/test/call_rejects_non_comptime-known_fn-compile_time.zig new file mode 100644 index 0000000000..3c50830787 --- /dev/null +++ b/test/compile_errors/stage1/test/call_rejects_non_comptime-known_fn-compile_time.zig @@ -0,0 +1,8 @@ +pub export fn entry() void { + var call_me: fn () void = undefined; + @call(.{ .modifier = .compile_time }, call_me, .{}); +} + +// @call rejects non comptime-known fn - compile_time +// +// tmp.zig:3:5: error: the specified modifier requires a comptime-known function diff --git a/test/compile_errors/stage1/test/cast_between_optional_T_where_T_is_not_a_pointer.zig b/test/compile_errors/stage1/test/cast_between_optional_T_where_T_is_not_a_pointer.zig new file mode 100644 index 0000000000..8f5ca1c25d --- /dev/null +++ b/test/compile_errors/stage1/test/cast_between_optional_T_where_T_is_not_a_pointer.zig @@ -0,0 +1,12 @@ +pub const fnty1 = ?fn (i8) void; +pub const fnty2 = ?fn (u64) void; +export fn entry() void { + var a: fnty1 = undefined; + var b: fnty2 = undefined; + a = b; +} + +// cast between ?T where T is not a pointer +// +// tmp.zig:6:9: error: expected type '?fn(i8) void', found '?fn(u64) void' +// tmp.zig:6:9: note: optional type child 'fn(u64) void' cannot cast into optional type child 'fn(i8) void' diff --git a/test/compile_errors/stage1/test/combination_of_nosuspend_and_async.zig b/test/compile_errors/stage1/test/combination_of_nosuspend_and_async.zig new file mode 100644 index 0000000000..a164fb621b --- /dev/null +++ b/test/compile_errors/stage1/test/combination_of_nosuspend_and_async.zig @@ -0,0 +1,13 @@ +export fn entry() void { + nosuspend { + const bar = async foo(); + suspend {} + resume bar; + } +} +fn foo() void {} + +// combination of nosuspend and async +// +// tmp.zig:4:9: error: suspend inside nosuspend block +// tmp.zig:2:5: note: nosuspend block here diff --git a/test/compile_errors/stage1/test/comparison_of_non-tagged_union_and_enum_literal.zig b/test/compile_errors/stage1/test/comparison_of_non-tagged_union_and_enum_literal.zig new file mode 100644 index 0000000000..b3c1506705 --- /dev/null +++ b/test/compile_errors/stage1/test/comparison_of_non-tagged_union_and_enum_literal.zig @@ -0,0 +1,11 @@ +export fn entry() void { + const U = union { A: u32, B: u64 }; + var u = U{ .A = 42 }; + var ok = u == .A; + _ = ok; +} + +// comparison of non-tagged union and enum literal +// +// tmp.zig:4:16: error: comparison of union and enum literal is only valid for tagged union types +// tmp.zig:2:15: note: type U is not a tagged union diff --git a/test/compile_errors/stage1/test/comptime_vector_overflow_shows_the_index.zig b/test/compile_errors/stage1/test/comptime_vector_overflow_shows_the_index.zig new file mode 100644 index 0000000000..a638c05b3b --- /dev/null +++ b/test/compile_errors/stage1/test/comptime_vector_overflow_shows_the_index.zig @@ -0,0 +1,11 @@ +comptime { + var a: @import("std").meta.Vector(4, u8) = [_]u8{ 1, 2, 255, 4 }; + var b: @import("std").meta.Vector(4, u8) = [_]u8{ 5, 6, 1, 8 }; + var x = a + b; + _ = x; +} + +// comptime vector overflow shows the index +// +// tmp.zig:4:15: error: operation caused overflow +// tmp.zig:4:15: note: when computing vector element at index 2 diff --git a/test/compile_errors/stage1/test/duplicate-unused_labels.zig b/test/compile_errors/stage1/test/duplicate-unused_labels.zig new file mode 100644 index 0000000000..285741afc4 --- /dev/null +++ b/test/compile_errors/stage1/test/duplicate-unused_labels.zig @@ -0,0 +1,30 @@ +comptime { + blk: { blk: while (false) {} } +} +comptime { + blk: while (false) { blk: for (@as([0]void, undefined)) |_| {} } +} +comptime { + blk: for (@as([0]void, undefined)) |_| { blk: {} } +} +comptime { + blk: {} +} +comptime { + blk: while(false) {} +} +comptime { + blk: for(@as([0]void, undefined)) |_| {} +} + +// duplicate/unused labels +// +// tmp.zig:2:12: error: redefinition of label 'blk' +// tmp.zig:2:5: note: previous definition here +// tmp.zig:5:26: error: redefinition of label 'blk' +// tmp.zig:5:5: note: previous definition here +// tmp.zig:8:46: error: redefinition of label 'blk' +// tmp.zig:8:5: note: previous definition here +// tmp.zig:11:5: error: unused block label +// tmp.zig:14:5: error: unused while loop label +// tmp.zig:17:5: error: unused for loop label diff --git a/test/compile_errors/stage1/test/duplicate_field_in_anonymous_struct_literal.zig b/test/compile_errors/stage1/test/duplicate_field_in_anonymous_struct_literal.zig new file mode 100644 index 0000000000..1b671d2ad3 --- /dev/null +++ b/test/compile_errors/stage1/test/duplicate_field_in_anonymous_struct_literal.zig @@ -0,0 +1,16 @@ +export fn entry() void { + const anon = .{ + .inner = .{ + .a = .{ + .something = "text", + }, + .a = .{}, + }, + }; + _ = anon; +} + +// duplicate field in anonymous struct literal +// +// tmp.zig:7:13: error: duplicate field +// tmp.zig:4:13: note: other field here diff --git a/test/compile_errors/stage1/test/error_in_struct_initializer_doesnt_crash_the_compiler.zig b/test/compile_errors/stage1/test/error_in_struct_initializer_doesnt_crash_the_compiler.zig new file mode 100644 index 0000000000..e37b887121 --- /dev/null +++ b/test/compile_errors/stage1/test/error_in_struct_initializer_doesnt_crash_the_compiler.zig @@ -0,0 +1,12 @@ +pub export fn entry() void { + const bitfield = struct { + e: u8, + e: u8, + }; + var a = .{@sizeOf(bitfield)}; + _ = a; +} + +// error in struct initializer doesn't crash the compiler +// +// tmp.zig:4:9: error: duplicate struct field: 'e' diff --git a/test/compile_errors/stage1/test/errors_in_for_loop_bodies_are_propagated.zig b/test/compile_errors/stage1/test/errors_in_for_loop_bodies_are_propagated.zig new file mode 100644 index 0000000000..32e99cf410 --- /dev/null +++ b/test/compile_errors/stage1/test/errors_in_for_loop_bodies_are_propagated.zig @@ -0,0 +1,8 @@ +pub export fn entry() void { + var arr: [100]u8 = undefined; + for (arr) |bits| _ = @popCount(bits); +} + +// errors in for loop bodies are propagated +// +// tmp.zig:3:26: error: expected 2 arguments, found 1 diff --git a/test/compile_errors/stage1/test/export_with_empty_name_string.zig b/test/compile_errors/stage1/test/export_with_empty_name_string.zig new file mode 100644 index 0000000000..424ee6e4b5 --- /dev/null +++ b/test/compile_errors/stage1/test/export_with_empty_name_string.zig @@ -0,0 +1,8 @@ +pub export fn entry() void { } +comptime { + @export(entry, .{ .name = "" }); +} + +// @export with empty name string +// +// tmp.zig:3:5: error: exported symbol name cannot be empty diff --git a/test/compile_errors/stage1/test/helpful_return_type_error_message.zig b/test/compile_errors/stage1/test/helpful_return_type_error_message.zig new file mode 100644 index 0000000000..6f1f9639da --- /dev/null +++ b/test/compile_errors/stage1/test/helpful_return_type_error_message.zig @@ -0,0 +1,27 @@ +export fn foo() u32 { + return error.Ohno; +} +fn bar() !u32 { + return error.Ohno; +} +export fn baz() void { + try bar(); +} +export fn qux() u32 { + return bar(); +} +export fn quux() u32 { + var buf: u32 = 0; + buf = bar(); +} + +// helpful return type error message +// +// tmp.zig:2:17: error: expected type 'u32', found 'error{Ohno}' +// tmp.zig:1:17: note: function cannot return an error +// tmp.zig:8:5: error: expected type 'void', found '@typeInfo(@typeInfo(@TypeOf(bar)).Fn.return_type.?).ErrorUnion.error_set' +// tmp.zig:7:17: note: function cannot return an error +// tmp.zig:11:15: error: cannot convert error union to payload type. consider using `try`, `catch`, or `if`. expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(bar)).Fn.return_type.?).ErrorUnion.error_set!u32' +// tmp.zig:10:17: note: function cannot return an error +// tmp.zig:15:14: error: cannot convert error union to payload type. consider using `try`, `catch`, or `if`. expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(bar)).Fn.return_type.?).ErrorUnion.error_set!u32' +// tmp.zig:14:5: note: cannot store an error in type 'u32' diff --git a/test/compile_errors/stage1/test/int-float_conversion_to_comptime_int-float.zig b/test/compile_errors/stage1/test/int-float_conversion_to_comptime_int-float.zig new file mode 100644 index 0000000000..eeb2e4798e --- /dev/null +++ b/test/compile_errors/stage1/test/int-float_conversion_to_comptime_int-float.zig @@ -0,0 +1,13 @@ +export fn foo() void { + var a: f32 = 2; + _ = @floatToInt(comptime_int, a); +} +export fn bar() void { + var a: u32 = 2; + _ = @intToFloat(comptime_float, a); +} + +// int/float conversion to comptime_int/float +// +// tmp.zig:3:35: error: unable to evaluate constant expression +// tmp.zig:7:37: error: unable to evaluate constant expression diff --git a/test/compile_errors/stage1/test/invalid_assignments.zig b/test/compile_errors/stage1/test/invalid_assignments.zig new file mode 100644 index 0000000000..203784c554 --- /dev/null +++ b/test/compile_errors/stage1/test/invalid_assignments.zig @@ -0,0 +1,17 @@ +export fn entry1() void { + var a: []const u8 = "foo"; + a[0..2] = "bar"; +} +export fn entry2() void { + var a: u8 = 2; + a + 2 = 3; +} +export fn entry4() void { + 2 + 2 = 3; +} + +// invalid assignments +// +// tmp.zig:3:6: error: invalid left-hand side to assignment +// tmp.zig:7:7: error: invalid left-hand side to assignment +// tmp.zig:10:7: error: invalid left-hand side to assignment diff --git a/test/compile_errors/stage1/test/invalid_float_casts.zig b/test/compile_errors/stage1/test/invalid_float_casts.zig new file mode 100644 index 0000000000..0e2509dcaf --- /dev/null +++ b/test/compile_errors/stage1/test/invalid_float_casts.zig @@ -0,0 +1,23 @@ +export fn foo() void { + var a: f32 = 2; + _ = @floatCast(comptime_float, a); +} +export fn bar() void { + var a: f32 = 2; + _ = @floatToInt(f32, a); +} +export fn baz() void { + var a: f32 = 2; + _ = @intToFloat(f32, a); +} +export fn qux() void { + var a: u32 = 2; + _ = @floatCast(f32, a); +} + +// invalid float casts +// +// tmp.zig:3:36: error: unable to evaluate constant expression +// tmp.zig:7:21: error: expected integer type, found 'f32' +// tmp.zig:11:26: error: expected int type, found 'f32' +// tmp.zig:15:25: error: expected float type, found 'u32' diff --git a/test/compile_errors/stage1/test/invalid_int_casts.zig b/test/compile_errors/stage1/test/invalid_int_casts.zig new file mode 100644 index 0000000000..6870ecc723 --- /dev/null +++ b/test/compile_errors/stage1/test/invalid_int_casts.zig @@ -0,0 +1,23 @@ +export fn foo() void { + var a: u32 = 2; + _ = @intCast(comptime_int, a); +} +export fn bar() void { + var a: u32 = 2; + _ = @intToFloat(u32, a); +} +export fn baz() void { + var a: u32 = 2; + _ = @floatToInt(u32, a); +} +export fn qux() void { + var a: f32 = 2; + _ = @intCast(u32, a); +} + +// invalid int casts +// +// tmp.zig:3:32: error: unable to evaluate constant expression +// tmp.zig:7:21: error: expected float type, found 'u32' +// tmp.zig:11:26: error: expected float type, found 'u32' +// tmp.zig:15:23: error: expected integer type, found 'f32' diff --git a/test/compile_errors/stage1/test/invalid_non-exhaustive_enum_to_union.zig b/test/compile_errors/stage1/test/invalid_non-exhaustive_enum_to_union.zig new file mode 100644 index 0000000000..f78a9e62ff --- /dev/null +++ b/test/compile_errors/stage1/test/invalid_non-exhaustive_enum_to_union.zig @@ -0,0 +1,24 @@ +const E = enum(u8) { + a, + b, + _, +}; +const U = union(E) { + a, + b, +}; +export fn foo() void { + var e = @intToEnum(E, 15); + var u: U = e; + _ = u; +} +export fn bar() void { + const e = @intToEnum(E, 15); + var u: U = e; + _ = u; +} + +// invalid non-exhaustive enum to union +// +// tmp.zig:12:16: error: runtime cast to union 'U' from non-exhaustive enum +// tmp.zig:17:16: error: no tag by value 15 diff --git a/test/compile_errors/stage1/test/invalid_pointer_with_reify_type.zig b/test/compile_errors/stage1/test/invalid_pointer_with_reify_type.zig new file mode 100644 index 0000000000..febf9685fd --- /dev/null +++ b/test/compile_errors/stage1/test/invalid_pointer_with_reify_type.zig @@ -0,0 +1,16 @@ +export fn entry() void { + _ = @Type(.{ .Pointer = .{ + .size = .One, + .is_const = false, + .is_volatile = false, + .alignment = 1, + .address_space = .generic, + .child = u8, + .is_allowzero = false, + .sentinel = &@as(u8, 0), + }}); +} + +// invalid pointer with @Type +// +// tmp.zig:2:16: error: sentinels are only allowed on slices and unknown-length pointers diff --git a/test/compile_errors/stage1/test/nested_vectors.zig b/test/compile_errors/stage1/test/nested_vectors.zig new file mode 100644 index 0000000000..a05e9b0c5b --- /dev/null +++ b/test/compile_errors/stage1/test/nested_vectors.zig @@ -0,0 +1,10 @@ +export fn entry() void { + const V1 = @import("std").meta.Vector(4, u8); + const V2 = @Type(.{ .Vector = .{ .len = 4, .child = V1 } }); + var v: V2 = undefined; + _ = v; +} + +// nested vectors +// +// tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; '@Vector(4, u8)' is invalid diff --git a/test/compile_errors/stage1/test/non-exhaustive_enum_marker_assigned_a_value.zig b/test/compile_errors/stage1/test/non-exhaustive_enum_marker_assigned_a_value.zig new file mode 100644 index 0000000000..53037ff181 --- /dev/null +++ b/test/compile_errors/stage1/test/non-exhaustive_enum_marker_assigned_a_value.zig @@ -0,0 +1,17 @@ +const A = enum { + a, + b, + _ = 1, +}; +const B = enum { + a, + b, + _, +}; +comptime { _ = A; _ = B; } + +// non-exhaustive enum marker assigned a value +// +// tmp.zig:4:9: error: '_' is used to mark an enum as non-exhaustive and cannot be assigned a value +// tmp.zig:6:11: error: non-exhaustive enum missing integer tag type +// tmp.zig:9:5: note: marked non-exhaustive here diff --git a/test/compile_errors/stage1/test/non-exhaustive_enums.zig b/test/compile_errors/stage1/test/non-exhaustive_enums.zig new file mode 100644 index 0000000000..49ceff3178 --- /dev/null +++ b/test/compile_errors/stage1/test/non-exhaustive_enums.zig @@ -0,0 +1,19 @@ +const B = enum(u1) { + a, + _, + b, +}; +const C = enum(u1) { + a, + b, + _, +}; +pub export fn entry() void { + _ = B; + _ = C; +} + +// non-exhaustive enums +// +// tmp.zig:3:5: error: '_' field of non-exhaustive enum must be last +// tmp.zig:6:11: error: non-exhaustive enum specifies every value diff --git a/test/compile_errors/stage1/test/not_an_enum_type.zig b/test/compile_errors/stage1/test/not_an_enum_type.zig new file mode 100644 index 0000000000..f92c3d44e1 --- /dev/null +++ b/test/compile_errors/stage1/test/not_an_enum_type.zig @@ -0,0 +1,17 @@ +export fn entry() void { + var self: Error = undefined; + switch (self) { + InvalidToken => |x| return x.token, + ExpectedVarDeclOrFn => |x| return x.token, + } +} +const Error = union(enum) { + A: InvalidToken, + B: ExpectedVarDeclOrFn, +}; +const InvalidToken = struct {}; +const ExpectedVarDeclOrFn = struct {}; + +// not an enum type +// +// tmp.zig:4:9: error: expected type '@typeInfo(Error).Union.tag_type.?', found 'type' diff --git a/test/compile_errors/stage1/test/packed_struct_with_fields_of_not_allowed_types.zig b/test/compile_errors/stage1/test/packed_struct_with_fields_of_not_allowed_types.zig new file mode 100644 index 0000000000..dc156342f4 --- /dev/null +++ b/test/compile_errors/stage1/test/packed_struct_with_fields_of_not_allowed_types.zig @@ -0,0 +1,71 @@ +const A = packed struct { + x: anyerror, +}; +const B = packed struct { + x: [2]u24, +}; +const C = packed struct { + x: [1]anyerror, +}; +const D = packed struct { + x: [1]S, +}; +const E = packed struct { + x: [1]U, +}; +const F = packed struct { + x: ?anyerror, +}; +const G = packed struct { + x: Enum, +}; +export fn entry1() void { + var a: A = undefined; + _ = a; +} +export fn entry2() void { + var b: B = undefined; + _ = b; +} +export fn entry3() void { + var r: C = undefined; + _ = r; +} +export fn entry4() void { + var d: D = undefined; + _ = d; +} +export fn entry5() void { + var e: E = undefined; + _ = e; +} +export fn entry6() void { + var f: F = undefined; + _ = f; +} +export fn entry7() void { + var g: G = undefined; + _ = g; +} +const S = struct { + x: i32, +}; +const U = struct { + A: i32, + B: u32, +}; +const Enum = enum { + A, + B, +}; + +// packed struct with fields of not allowed types +// +// tmp.zig:2:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation +// tmp.zig:5:5: error: array of 'u24' not allowed in packed struct due to padding bits (must be padded from 48 to 64 bits) +// tmp.zig:8:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation +// tmp.zig:11:5: error: non-packed, non-extern struct 'S' not allowed in packed struct; no guaranteed in-memory representation +// tmp.zig:14:5: error: non-packed, non-extern struct 'U' not allowed in packed struct; no guaranteed in-memory representation +// tmp.zig:17:5: error: type '?anyerror' not allowed in packed struct; no guaranteed in-memory representation +// tmp.zig:20:5: error: type 'Enum' not allowed in packed struct; no guaranteed in-memory representation +// tmp.zig:57:14: note: enum declaration does not specify an integer tag type diff --git a/test/compile_errors/stage1/test/ptrToInt_with_pointer_to_zero-sized_type.zig b/test/compile_errors/stage1/test/ptrToInt_with_pointer_to_zero-sized_type.zig new file mode 100644 index 0000000000..63ba217247 --- /dev/null +++ b/test/compile_errors/stage1/test/ptrToInt_with_pointer_to_zero-sized_type.zig @@ -0,0 +1,9 @@ +export fn entry() void { + var pointer: ?*u0 = null; + var x = @ptrToInt(pointer); + _ = x; +} + +// @ptrToInt with pointer to zero-sized type +// +// tmp.zig:3:23: error: pointer to size 0 type has no address diff --git a/test/compile_errors/stage1/test/reassign_to_array_parameter.zig b/test/compile_errors/stage1/test/reassign_to_array_parameter.zig new file mode 100644 index 0000000000..a222150a2c --- /dev/null +++ b/test/compile_errors/stage1/test/reassign_to_array_parameter.zig @@ -0,0 +1,10 @@ +fn reassign(a: [3]f32) void { + a = [3]f32{4, 5, 6}; +} +export fn entry() void { + reassign(.{1, 2, 3}); +} + +// reassign to array parameter +// +// tmp.zig:2:15: error: cannot assign to constant diff --git a/test/compile_errors/stage1/test/reassign_to_slice_parameter.zig b/test/compile_errors/stage1/test/reassign_to_slice_parameter.zig new file mode 100644 index 0000000000..a8e555182a --- /dev/null +++ b/test/compile_errors/stage1/test/reassign_to_slice_parameter.zig @@ -0,0 +1,10 @@ +pub fn reassign(s: []const u8) void { + s = s[0..]; +} +export fn entry() void { + reassign("foo"); +} + +// reassign to slice parameter +// +// tmp.zig:2:10: error: cannot assign to constant diff --git a/test/compile_errors/stage1/test/reassign_to_struct_parameter.zig b/test/compile_errors/stage1/test/reassign_to_struct_parameter.zig new file mode 100644 index 0000000000..018548ab32 --- /dev/null +++ b/test/compile_errors/stage1/test/reassign_to_struct_parameter.zig @@ -0,0 +1,13 @@ +const S = struct { + x: u32, +}; +fn reassign(s: S) void { + s = S{.x = 2}; +} +export fn entry() void { + reassign(S{.x = 3}); +} + +// reassign to struct parameter +// +// tmp.zig:5:10: error: cannot assign to constant diff --git a/test/compile_errors/stage1/test/reference_to_const_data.zig b/test/compile_errors/stage1/test/reference_to_const_data.zig new file mode 100644 index 0000000000..d785eb648e --- /dev/null +++ b/test/compile_errors/stage1/test/reference_to_const_data.zig @@ -0,0 +1,27 @@ +export fn foo() void { + var ptr = &[_]u8{0,0,0,0}; + ptr[1] = 2; +} +export fn bar() void { + var ptr = &@as(u32, 2); + ptr.* = 2; +} +export fn baz() void { + var ptr = &true; + ptr.* = false; +} +export fn qux() void { + const S = struct{ + x: usize, + y: usize, + }; + var ptr = &S{.x=1,.y=2}; + ptr.x = 2; +} + +// reference to const data +// +// tmp.zig:3:14: error: cannot assign to constant +// tmp.zig:7:13: error: cannot assign to constant +// tmp.zig:11:13: error: cannot assign to constant +// tmp.zig:19:13: error: cannot assign to constant diff --git a/test/compile_errors/stage1/test/reify_typeOf_with_incompatible_arguments.zig b/test/compile_errors/stage1/test/reify_typeOf_with_incompatible_arguments.zig new file mode 100644 index 0000000000..97ee7aaf1b --- /dev/null +++ b/test/compile_errors/stage1/test/reify_typeOf_with_incompatible_arguments.zig @@ -0,0 +1,9 @@ +export fn entry() void { + var var_1: f32 = undefined; + var var_2: u32 = undefined; + _ = @TypeOf(var_1, var_2); +} + +// @TypeOf with incompatible arguments +// +// tmp.zig:4:9: error: incompatible types: 'f32' and 'u32' diff --git a/test/compile_errors/stage1/test/reify_typeOf_with_no_arguments.zig b/test/compile_errors/stage1/test/reify_typeOf_with_no_arguments.zig new file mode 100644 index 0000000000..e18b9e66b7 --- /dev/null +++ b/test/compile_errors/stage1/test/reify_typeOf_with_no_arguments.zig @@ -0,0 +1,7 @@ +export fn entry() void { + _ = @TypeOf(); +} + +// @TypeOf with no arguments +// +// tmp.zig:2:9: error: expected at least 1 argument, found 0 diff --git a/test/compile_errors/stage1/test/reject_extern_function_definitions_with_body.zig b/test/compile_errors/stage1/test/reject_extern_function_definitions_with_body.zig new file mode 100644 index 0000000000..024080a6bc --- /dev/null +++ b/test/compile_errors/stage1/test/reject_extern_function_definitions_with_body.zig @@ -0,0 +1,7 @@ +extern "c" fn definitelyNotInLibC(a: i32, b: i32) i32 { + return a + b; +} + +// reject extern function definitions with body +// +// tmp.zig:1:1: error: extern functions have no body diff --git a/test/compile_errors/stage1/test/reject_extern_variables_with_initializers.zig b/test/compile_errors/stage1/test/reject_extern_variables_with_initializers.zig new file mode 100644 index 0000000000..d3f65ff0cb --- /dev/null +++ b/test/compile_errors/stage1/test/reject_extern_variables_with_initializers.zig @@ -0,0 +1,5 @@ +extern var foo: int = 2; + +// reject extern variables with initializers +// +// tmp.zig:1:23: error: extern variables have no initializers diff --git a/test/compile_errors/stage1/test/repeated_invalid_field_access_to_generic_function_returning_type_crashes_compiler_2655.zig b/test/compile_errors/stage1/test/repeated_invalid_field_access_to_generic_function_returning_type_crashes_compiler_2655.zig new file mode 100644 index 0000000000..c419a6ae83 --- /dev/null +++ b/test/compile_errors/stage1/test/repeated_invalid_field_access_to_generic_function_returning_type_crashes_compiler_2655.zig @@ -0,0 +1,11 @@ +pub fn A() type { + return Q; +} +test "1" { + _ = A().a; + _ = A().a; +} + +// repeated invalid field access to generic function returning type crashes compiler. #2655 +// +// tmp.zig:2:12: error: use of undeclared identifier 'Q' diff --git a/test/compile_errors/stage1/test/return_invalid_type_from_test.zig b/test/compile_errors/stage1/test/return_invalid_type_from_test.zig new file mode 100644 index 0000000000..e7aeab3be7 --- /dev/null +++ b/test/compile_errors/stage1/test/return_invalid_type_from_test.zig @@ -0,0 +1,5 @@ +test "example" { return 1; } + +// return invalid type from test +// +// tmp.zig:1:25: error: expected type 'void', found 'comptime_int' diff --git a/test/compile_errors/stage1/test/shift_on_type_with_non-power-of-two_size.zig b/test/compile_errors/stage1/test/shift_on_type_with_non-power-of-two_size.zig new file mode 100644 index 0000000000..d76406223d --- /dev/null +++ b/test/compile_errors/stage1/test/shift_on_type_with_non-power-of-two_size.zig @@ -0,0 +1,31 @@ +export fn entry() void { + const S = struct { + fn a() void { + var x: u24 = 42; + _ = x >> 24; + } + fn b() void { + var x: u24 = 42; + _ = x << 24; + } + fn c() void { + var x: u24 = 42; + _ = @shlExact(x, 24); + } + fn d() void { + var x: u24 = 42; + _ = @shrExact(x, 24); + } + }; + S.a(); + S.b(); + S.c(); + S.d(); +} + +// shift on type with non-power-of-two size +// +// tmp.zig:5:19: error: RHS of shift is too large for LHS type +// tmp.zig:9:19: error: RHS of shift is too large for LHS type +// tmp.zig:13:17: error: RHS of shift is too large for LHS type +// tmp.zig:17:17: error: RHS of shift is too large for LHS type diff --git a/test/compile_errors/stage1/test/shuffle_with_selected_index_past_first_vector_length.zig b/test/compile_errors/stage1/test/shuffle_with_selected_index_past_first_vector_length.zig new file mode 100644 index 0000000000..c45eb4a0e2 --- /dev/null +++ b/test/compile_errors/stage1/test/shuffle_with_selected_index_past_first_vector_length.zig @@ -0,0 +1,12 @@ +export fn entry() void { + const v: @import("std").meta.Vector(4, u32) = [4]u32{ 10, 11, 12, 13 }; + const x: @import("std").meta.Vector(4, u32) = [4]u32{ 14, 15, 16, 17 }; + var z = @shuffle(u32, v, x, [8]i32{ 0, 1, 2, 3, 7, 6, 5, 4 }); + _ = z; +} + +// @shuffle with selected index past first vector length +// +// tmp.zig:4:39: error: mask index '4' has out-of-bounds selection +// tmp.zig:4:27: note: selected index '7' out of bounds of @Vector(4, u32) +// tmp.zig:4:30: note: selections from the second vector are specified with negative numbers diff --git a/test/compile_errors/stage1/test/switch_ranges_endpoints_are_validated.zig b/test/compile_errors/stage1/test/switch_ranges_endpoints_are_validated.zig new file mode 100644 index 0000000000..4c0545ea92 --- /dev/null +++ b/test/compile_errors/stage1/test/switch_ranges_endpoints_are_validated.zig @@ -0,0 +1,13 @@ +pub export fn entry() void { + var x: i32 = 0; + switch (x) { + 6...1 => {}, + -1...-5 => {}, + else => unreachable, + } +} + +// switch ranges endpoints are validated +// +// tmp.zig:4:9: error: range start value is greater than the end value +// tmp.zig:5:9: error: range start value is greater than the end value diff --git a/test/compile_errors/stage1/test/switching_with_exhaustive_enum_has___prong_.zig b/test/compile_errors/stage1/test/switching_with_exhaustive_enum_has___prong_.zig new file mode 100644 index 0000000000..b132b7834e --- /dev/null +++ b/test/compile_errors/stage1/test/switching_with_exhaustive_enum_has___prong_.zig @@ -0,0 +1,16 @@ +const E = enum{ + a, + b, +}; +pub export fn entry() void { + var e: E = .b; + switch (e) { + .a => {}, + .b => {}, + _ => {}, + } +} + +// switching with exhaustive enum has '_' prong +// +// tmp.zig:7:5: error: switch on exhaustive enum has `_` prong diff --git a/test/compile_errors/stage1/test/switching_with_non-exhaustive_enums.zig b/test/compile_errors/stage1/test/switching_with_non-exhaustive_enums.zig new file mode 100644 index 0000000000..53cd88e68c --- /dev/null +++ b/test/compile_errors/stage1/test/switching_with_non-exhaustive_enums.zig @@ -0,0 +1,32 @@ +const E = enum(u8) { + a, + b, + _, +}; +const U = union(E) { + a: i32, + b: u32, +}; +pub export fn entry() void { + var e: E = .b; + switch (e) { // error: switch not handling the tag `b` + .a => {}, + _ => {}, + } + switch (e) { // error: switch on non-exhaustive enum must include `else` or `_` prong + .a => {}, + .b => {}, + } + var u = U{.a = 2}; + switch (u) { // error: `_` prong not allowed when switching on tagged union + .a => {}, + .b => {}, + _ => {}, + } +} + +// switching with non-exhaustive enums +// +// tmp.zig:12:5: error: enumeration value 'E.b' not handled in switch +// tmp.zig:16:5: error: switch on non-exhaustive enum must include `else` or `_` prong +// tmp.zig:21:5: error: `_` prong not allowed when switching on tagged union diff --git a/test/compile_errors/stage1/test/tagName_on_invalid_value_of_non-exhaustive_enum.zig b/test/compile_errors/stage1/test/tagName_on_invalid_value_of_non-exhaustive_enum.zig new file mode 100644 index 0000000000..139c7c7a23 --- /dev/null +++ b/test/compile_errors/stage1/test/tagName_on_invalid_value_of_non-exhaustive_enum.zig @@ -0,0 +1,8 @@ +test "enum" { + const E = enum(u8) {A, B, _}; + _ = @tagName(@intToEnum(E, 5)); +} + +// @tagName on invalid value of non-exhaustive enum +// +// tmp.zig:3:18: error: no tag by value 5 diff --git a/test/compile_errors/stage1/test/type_mismatch_in_C_prototype_with_varargs.zig b/test/compile_errors/stage1/test/type_mismatch_in_C_prototype_with_varargs.zig new file mode 100644 index 0000000000..437cca8772 --- /dev/null +++ b/test/compile_errors/stage1/test/type_mismatch_in_C_prototype_with_varargs.zig @@ -0,0 +1,11 @@ +const fn_ty = ?fn ([*c]u8, ...) callconv(.C) void; +extern fn fn_decl(fmt: [*:0]u8, ...) void; + +export fn main() void { + const x: fn_ty = fn_decl; + _ = x; +} + +// type mismatch in C prototype with varargs +// +// tmp.zig:5:22: error: expected type 'fn([*c]u8, ...) callconv(.C) void', found 'fn([*:0]u8, ...) callconv(.C) void' diff --git a/test/compile_errors/stage1/test/type_mismatch_with_tuple_concatenation.zig b/test/compile_errors/stage1/test/type_mismatch_with_tuple_concatenation.zig new file mode 100644 index 0000000000..ce5e4d4629 --- /dev/null +++ b/test/compile_errors/stage1/test/type_mismatch_with_tuple_concatenation.zig @@ -0,0 +1,8 @@ +export fn entry() void { + var x = .{}; + x = x ++ .{ 1, 2, 3 }; +} + +// type mismatch with tuple concatenation +// +// tmp.zig:3:11: error: expected type 'struct:2:14', found 'struct:3:11' diff --git a/test/compile_errors/stage1/test/unused_variable_error_on_errdefer.zig b/test/compile_errors/stage1/test/unused_variable_error_on_errdefer.zig new file mode 100644 index 0000000000..eb92776938 --- /dev/null +++ b/test/compile_errors/stage1/test/unused_variable_error_on_errdefer.zig @@ -0,0 +1,11 @@ +fn foo() !void { + errdefer |a| unreachable; + return error.A; +} +export fn entry() void { + foo() catch unreachable; +} + +// unused variable error on errdefer +// +// tmp.zig:2:15: error: unused variable: 'a' diff --git a/test/compile_errors/stage2/embed_outside_package.zig b/test/compile_errors/stage2/embed_outside_package.zig new file mode 100644 index 0000000000..8df6b3d9af --- /dev/null +++ b/test/compile_errors/stage2/embed_outside_package.zig @@ -0,0 +1,7 @@ +export fn a() usize { + return @embedFile("/root/foo").len; +} + +// embed outside package +// +//:2:23: error: embed of file outside package path: '/root/foo' diff --git a/test/compile_errors/stage2/import_outside_package.zig b/test/compile_errors/stage2/import_outside_package.zig new file mode 100644 index 0000000000..f9de9202de --- /dev/null +++ b/test/compile_errors/stage2/import_outside_package.zig @@ -0,0 +1,7 @@ +export fn a() usize { + return @import("../../above.zig").len; +} + +// import outside package +// +// :2:20: error: import of file outside package path: '../../above.zig' diff --git a/test/compile_errors/stage2/out_of_bounds_index.zig b/test/compile_errors/stage2/out_of_bounds_index.zig new file mode 100644 index 0000000000..3c34bb5d0f --- /dev/null +++ b/test/compile_errors/stage2/out_of_bounds_index.zig @@ -0,0 +1,28 @@ +comptime { + var array = [_:0]u8{ 1, 2, 3, 4 }; + var src_slice: [:0]u8 = &array; + var slice = src_slice[2..6]; + _ = slice; +} +comptime { + var array = [_:0]u8{ 1, 2, 3, 4 }; + var slice = array[2..6]; + _ = slice; +} +comptime { + var array = [_]u8{ 1, 2, 3, 4 }; + var slice = array[2..5]; + _ = slice; +} +comptime { + var array = [_:0]u8{ 1, 2, 3, 4 }; + var slice = array[3..2]; + _ = slice; +} + +// out of bounds indexing +// +// :4:26: error: end index 6 out of bounds for slice of length 4 +1 (sentinel) +// :9:22: error: end index 6 out of bounds for array of length 4 +1 (sentinel) +// :14:22: error: end index 5 out of bounds for array of length 4 +// :19:22: error: start index 3 is larger than end index 2