| author | |
| committer | |
| log | 4af305b30acdefb9da380b21b446d2b31b5a6295 |
| tree | 442c7d3722c22bedbca48cafa8038fa34499818a |
| parent | 3bf97bfd460f0704542699578a1d52a078aa7a21 |
| parent | 014009a730315adf865777282c0f7aa4209afc38 |
| signature |
Organize and implement remaining stage1 compile errors166 files changed, 1450 insertions(+), 1405 deletions(-)
lib/std/zig/parse.zig+1-1| ... | ... | @@ -286,7 +286,7 @@ const Parser = struct { |
| 286 | 286 | .keyword_comptime => switch (p.token_tags[p.tok_i + 1]) { |
| 287 | 287 | .l_brace => { |
| 288 | 288 | if (doc_comment) |some| { |
| 289 | try p.warnMsg(.{ .tag = .test_doc_comment, .token = some }); | |
| 289 | try p.warnMsg(.{ .tag = .comptime_doc_comment, .token = some }); | |
| 290 | 290 | } |
| 291 | 291 | const comptime_token = p.nextToken(); |
| 292 | 292 | const block = p.parseBlock() catch |err| switch (err) { |
lib/std/zig/parser_test.zig+12| ... | ... | @@ -4210,6 +4210,18 @@ test "zig fmt: remove newlines surrounding doc comment within container decl" { |
| 4210 | 4210 | ); |
| 4211 | 4211 | } |
| 4212 | 4212 | |
| 4213 | test "zig fmt: invalid else branch statement" { | |
| 4214 | try testError( | |
| 4215 | \\/// This is a doc comment for a comptime block. | |
| 4216 | \\comptime {} | |
| 4217 | \\/// This is a doc comment for a test | |
| 4218 | \\test "This is my test" {} | |
| 4219 | , &[_]Error{ | |
| 4220 | .comptime_doc_comment, | |
| 4221 | .test_doc_comment, | |
| 4222 | }); | |
| 4223 | } | |
| 4224 | ||
| 4213 | 4225 | test "zig fmt: invalid else branch statement" { |
| 4214 | 4226 | try testError( |
| 4215 | 4227 | \\comptime { |
src/Compilation.zig+24-3| ... | ... | @@ -31,6 +31,7 @@ const clangMain = @import("main.zig").clangMain; |
| 31 | 31 | const Module = @import("Module.zig"); |
| 32 | 32 | const Cache = @import("Cache.zig"); |
| 33 | 33 | const translate_c = @import("translate_c.zig"); |
| 34 | const clang = @import("clang.zig"); | |
| 34 | 35 | const c_codegen = @import("codegen/c.zig"); |
| 35 | 36 | const ThreadPool = @import("ThreadPool.zig"); |
| 36 | 37 | const WaitGroup = @import("WaitGroup.zig"); |
| ... | ... | @@ -2749,6 +2750,9 @@ pub fn totalErrorCount(self: *Compilation) usize { |
| 2749 | 2750 | const decl = module.declPtr(key); |
| 2750 | 2751 | if (decl.getFileScope().okToReportErrors()) { |
| 2751 | 2752 | total += 1; |
| 2753 | if (module.cimport_errors.get(key)) |errors| { | |
| 2754 | total += errors.len; | |
| 2755 | } | |
| 2752 | 2756 | } |
| 2753 | 2757 | } |
| 2754 | 2758 | if (module.emit_h) |emit_h| { |
| ... | ... | @@ -2858,6 +2862,23 @@ pub fn getAllErrorsAlloc(self: *Compilation) !AllErrors { |
| 2858 | 2862 | // We'll try again once parsing succeeds. |
| 2859 | 2863 | if (decl.getFileScope().okToReportErrors()) { |
| 2860 | 2864 | try AllErrors.add(module, &arena, &errors, entry.value_ptr.*.*); |
| 2865 | if (module.cimport_errors.get(entry.key_ptr.*)) |cimport_errors| for (cimport_errors) |c_error| { | |
| 2866 | if (c_error.path) |some| | |
| 2867 | try errors.append(.{ | |
| 2868 | .src = .{ | |
| 2869 | .src_path = try arena_allocator.dupe(u8, std.mem.span(some)), | |
| 2870 | .span = .{ .start = c_error.offset, .end = c_error.offset + 1, .main = c_error.offset }, | |
| 2871 | .msg = try arena_allocator.dupe(u8, std.mem.span(c_error.msg)), | |
| 2872 | .line = c_error.line, | |
| 2873 | .column = c_error.column, | |
| 2874 | .source_line = if (c_error.source_line) |line| try arena_allocator.dupe(u8, std.mem.span(line)) else null, | |
| 2875 | }, | |
| 2876 | }) | |
| 2877 | else | |
| 2878 | try errors.append(.{ | |
| 2879 | .plain = .{ .msg = try arena_allocator.dupe(u8, std.mem.span(c_error.msg)) }, | |
| 2880 | }); | |
| 2881 | }; | |
| 2861 | 2882 | } |
| 2862 | 2883 | } |
| 2863 | 2884 | } |
| ... | ... | @@ -3524,7 +3545,7 @@ test "cImport" { |
| 3524 | 3545 | |
| 3525 | 3546 | const CImportResult = struct { |
| 3526 | 3547 | out_zig_path: []u8, |
| 3527 | errors: []translate_c.ClangErrMsg, | |
| 3548 | errors: []clang.ErrorMsg, | |
| 3528 | 3549 | }; |
| 3529 | 3550 | |
| 3530 | 3551 | /// Caller owns returned memory. |
| ... | ... | @@ -3599,7 +3620,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult { |
| 3599 | 3620 | |
| 3600 | 3621 | const c_headers_dir_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{"include"}); |
| 3601 | 3622 | const c_headers_dir_path_z = try arena.dupeZ(u8, c_headers_dir_path); |
| 3602 | var clang_errors: []translate_c.ClangErrMsg = &[0]translate_c.ClangErrMsg{}; | |
| 3623 | var clang_errors: []clang.ErrorMsg = &[0]clang.ErrorMsg{}; | |
| 3603 | 3624 | var tree = translate_c.translate( |
| 3604 | 3625 | comp.gpa, |
| 3605 | 3626 | new_argv.ptr, |
| ... | ... | @@ -3665,7 +3686,7 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult { |
| 3665 | 3686 | } |
| 3666 | 3687 | return CImportResult{ |
| 3667 | 3688 | .out_zig_path = out_zig_path, |
| 3668 | .errors = &[0]translate_c.ClangErrMsg{}, | |
| 3689 | .errors = &[0]clang.ErrorMsg{}, | |
| 3669 | 3690 | }; |
| 3670 | 3691 | } |
| 3671 | 3692 |
src/Module.zig+30| ... | ... | @@ -31,6 +31,7 @@ const target_util = @import("target.zig"); |
| 31 | 31 | const build_options = @import("build_options"); |
| 32 | 32 | const Liveness = @import("Liveness.zig"); |
| 33 | 33 | const isUpDir = @import("introspect.zig").isUpDir; |
| 34 | const clang = @import("clang.zig"); | |
| 34 | 35 | |
| 35 | 36 | /// General-purpose allocator. Used for both temporary and long-term storage. |
| 36 | 37 | gpa: Allocator, |
| ... | ... | @@ -111,6 +112,9 @@ failed_embed_files: std.AutoArrayHashMapUnmanaged(*EmbedFile, *ErrorMsg) = .{}, |
| 111 | 112 | /// Using a map here for consistency with the other fields here. |
| 112 | 113 | /// The ErrorMsg memory is owned by the `Export`, using Module's general purpose allocator. |
| 113 | 114 | failed_exports: std.AutoArrayHashMapUnmanaged(*Export, *ErrorMsg) = .{}, |
| 115 | /// If a decl failed due to a cimport error, the corresponding Clang errors | |
| 116 | /// are stored here. | |
| 117 | cimport_errors: std.AutoArrayHashMapUnmanaged(Decl.Index, []CImportError) = .{}, | |
| 114 | 118 | |
| 115 | 119 | /// Candidates for deletion. After a semantic analysis update completes, this list |
| 116 | 120 | /// contains Decls that need to be deleted if they end up having no references to them. |
| ... | ... | @@ -172,6 +176,21 @@ reference_table: std.AutoHashMapUnmanaged(Decl.Index, struct { |
| 172 | 176 | src: LazySrcLoc, |
| 173 | 177 | }) = .{}, |
| 174 | 178 | |
| 179 | pub const CImportError = struct { | |
| 180 | offset: u32, | |
| 181 | line: u32, | |
| 182 | column: u32, | |
| 183 | path: ?[*:0]u8, | |
| 184 | source_line: ?[*:0]u8, | |
| 185 | msg: [*:0]u8, | |
| 186 | ||
| 187 | pub fn deinit(err: CImportError, gpa: Allocator) void { | |
| 188 | if (err.path) |some| gpa.free(std.mem.span(some)); | |
| 189 | if (err.source_line) |some| gpa.free(std.mem.span(some)); | |
| 190 | gpa.free(std.mem.span(err.msg)); | |
| 191 | } | |
| 192 | }; | |
| 193 | ||
| 175 | 194 | pub const StringLiteralContext = struct { |
| 176 | 195 | bytes: *ArrayListUnmanaged(u8), |
| 177 | 196 | |
| ... | ... | @@ -3449,6 +3468,11 @@ pub fn deinit(mod: *Module) void { |
| 3449 | 3468 | } |
| 3450 | 3469 | mod.failed_exports.deinit(gpa); |
| 3451 | 3470 | |
| 3471 | for (mod.cimport_errors.values()) |errs| { | |
| 3472 | for (errs) |err| err.deinit(gpa); | |
| 3473 | } | |
| 3474 | mod.cimport_errors.deinit(gpa); | |
| 3475 | ||
| 3452 | 3476 | mod.compile_log_decls.deinit(gpa); |
| 3453 | 3477 | |
| 3454 | 3478 | for (mod.decl_exports.values()) |*export_list| { |
| ... | ... | @@ -5381,6 +5405,9 @@ pub fn clearDecl( |
| 5381 | 5405 | if (mod.failed_decls.fetchSwapRemove(decl_index)) |kv| { |
| 5382 | 5406 | kv.value.destroy(gpa); |
| 5383 | 5407 | } |
| 5408 | if (mod.cimport_errors.fetchSwapRemove(decl_index)) |kv| { | |
| 5409 | for (kv.value) |err| err.deinit(gpa); | |
| 5410 | } | |
| 5384 | 5411 | if (mod.emit_h) |emit_h| { |
| 5385 | 5412 | if (emit_h.failed_decls.fetchSwapRemove(decl_index)) |kv| { |
| 5386 | 5413 | kv.value.destroy(gpa); |
| ... | ... | @@ -5768,6 +5795,9 @@ fn markOutdatedDecl(mod: *Module, decl_index: Decl.Index) !void { |
| 5768 | 5795 | if (mod.failed_decls.fetchSwapRemove(decl_index)) |kv| { |
| 5769 | 5796 | kv.value.destroy(mod.gpa); |
| 5770 | 5797 | } |
| 5798 | if (mod.cimport_errors.fetchSwapRemove(decl_index)) |kv| { | |
| 5799 | for (kv.value) |err| err.deinit(mod.gpa); | |
| 5800 | } | |
| 5771 | 5801 | if (decl.has_tv and decl.owns_tv) { |
| 5772 | 5802 | if (decl.val.castTag(.function)) |payload| { |
| 5773 | 5803 | const func = payload.data; |
src/Sema.zig+285-59| ... | ... | @@ -2257,6 +2257,9 @@ fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError { |
| 2257 | 2257 | sema.owner_decl.analysis = .sema_failure; |
| 2258 | 2258 | sema.owner_decl.generation = mod.generation; |
| 2259 | 2259 | } |
| 2260 | if (sema.func) |func| { | |
| 2261 | func.state = .sema_failure; | |
| 2262 | } | |
| 2260 | 2263 | const gop = mod.failed_decls.getOrPutAssumeCapacity(sema.owner_decl_index); |
| 2261 | 2264 | if (gop.found_existing) { |
| 2262 | 2265 | // If there are multiple errors for the same Decl, prefer the first one added. |
| ... | ... | @@ -4109,6 +4112,8 @@ fn validateUnionInit( |
| 4109 | 4112 | const union_init = try sema.addConstant(union_ty, union_val); |
| 4110 | 4113 | try sema.storePtr2(block, init_src, union_ptr, init_src, union_init, init_src, .store); |
| 4111 | 4114 | return; |
| 4115 | } else if (try sema.typeRequiresComptime(union_ty)) { | |
| 4116 | return sema.failWithNeededComptime(block, field_ptr_data.src(), "initializer of comptime only union must be comptime-known"); | |
| 4112 | 4117 | } |
| 4113 | 4118 | |
| 4114 | 4119 | const new_tag = try sema.addConstant(tag_ty, tag_val); |
| ... | ... | @@ -4226,6 +4231,7 @@ fn validateStructInit( |
| 4226 | 4231 | var first_block_index = block.instructions.items.len; |
| 4227 | 4232 | var make_runtime = false; |
| 4228 | 4233 | |
| 4234 | const require_comptime = try sema.typeRequiresComptime(struct_ty); | |
| 4229 | 4235 | const air_tags = sema.air_instructions.items(.tag); |
| 4230 | 4236 | const air_datas = sema.air_instructions.items(.data); |
| 4231 | 4237 | |
| ... | ... | @@ -4301,6 +4307,9 @@ fn validateStructInit( |
| 4301 | 4307 | } |
| 4302 | 4308 | if (try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(bin_op.rhs, &make_runtime)) |val| { |
| 4303 | 4309 | field_values[i] = val; |
| 4310 | } else if (require_comptime) { | |
| 4311 | const field_ptr_data = sema.code.instructions.items(.data)[field_ptr].pl_node; | |
| 4312 | return sema.failWithNeededComptime(block, field_ptr_data.src(), "initializer of comptime only struct must be comptime-known"); | |
| 4304 | 4313 | } else { |
| 4305 | 4314 | struct_is_comptime = false; |
| 4306 | 4315 | } |
| ... | ... | @@ -5121,20 +5130,58 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr |
| 5121 | 5130 | |
| 5122 | 5131 | if (c_import_res.errors.len != 0) { |
| 5123 | 5132 | const msg = msg: { |
| 5133 | defer @import("clang.zig").ErrorMsg.delete(c_import_res.errors.ptr, c_import_res.errors.len); | |
| 5134 | ||
| 5124 | 5135 | const msg = try sema.errMsg(&child_block, src, "C import failed", .{}); |
| 5125 | 5136 | errdefer msg.destroy(sema.gpa); |
| 5126 | 5137 | |
| 5127 | 5138 | if (!mod.comp.bin_file.options.link_libc) |
| 5128 | 5139 | try sema.errNote(&child_block, src, msg, "libc headers not available; compilation does not link against libc", .{}); |
| 5129 | 5140 | |
| 5130 | for (c_import_res.errors) |_| { | |
| 5131 | // TODO integrate with LazySrcLoc | |
| 5132 | // try mod.errNoteNonLazy(.{}, msg, "{s}", .{clang_err.msg_ptr[0..clang_err.msg_len]}); | |
| 5133 | // if (clang_err.filename_ptr) |p| p[0..clang_err.filename_len] else "(no file)", | |
| 5134 | // clang_err.line + 1, | |
| 5135 | // clang_err.column + 1, | |
| 5141 | const gop = try sema.mod.cimport_errors.getOrPut(sema.gpa, sema.owner_decl_index); | |
| 5142 | if (!gop.found_existing) { | |
| 5143 | var errs = try std.ArrayListUnmanaged(Module.CImportError).initCapacity(sema.gpa, c_import_res.errors.len); | |
| 5144 | errdefer { | |
| 5145 | for (errs.items) |err| err.deinit(sema.gpa); | |
| 5146 | errs.deinit(sema.gpa); | |
| 5147 | } | |
| 5148 | ||
| 5149 | for (c_import_res.errors) |c_error| { | |
| 5150 | const path = if (c_error.filename_ptr) |some| | |
| 5151 | try sema.gpa.dupeZ(u8, some[0..c_error.filename_len]) | |
| 5152 | else | |
| 5153 | null; | |
| 5154 | errdefer if (path) |some| sema.gpa.free(some); | |
| 5155 | ||
| 5156 | const c_msg = try sema.gpa.dupeZ(u8, c_error.msg_ptr[0..c_error.msg_len]); | |
| 5157 | errdefer sema.gpa.free(c_msg); | |
| 5158 | ||
| 5159 | const line = line: { | |
| 5160 | const source = c_error.source orelse break :line null; | |
| 5161 | var start = c_error.offset; | |
| 5162 | while (start > 0) : (start -= 1) { | |
| 5163 | if (source[start - 1] == '\n') break; | |
| 5164 | } | |
| 5165 | var end = c_error.offset; | |
| 5166 | while (true) : (end += 1) { | |
| 5167 | if (source[end] == 0) break; | |
| 5168 | if (source[end] == '\n') break; | |
| 5169 | } | |
| 5170 | break :line try sema.gpa.dupeZ(u8, source[start..end]); | |
| 5171 | }; | |
| 5172 | errdefer if (line) |some| sema.gpa.free(some); | |
| 5173 | ||
| 5174 | errs.appendAssumeCapacity(.{ | |
| 5175 | .path = path orelse null, | |
| 5176 | .source_line = line orelse null, | |
| 5177 | .line = c_error.line, | |
| 5178 | .column = c_error.column, | |
| 5179 | .offset = c_error.offset, | |
| 5180 | .msg = c_msg, | |
| 5181 | }); | |
| 5182 | } | |
| 5183 | gop.value_ptr.* = errs.items; | |
| 5136 | 5184 | } |
| 5137 | @import("clang.zig").Stage2ErrorMsg.delete(c_import_res.errors.ptr, c_import_res.errors.len); | |
| 5138 | 5185 | break :msg msg; |
| 5139 | 5186 | }; |
| 5140 | 5187 | return sema.failWithOwnedErrorMsg(msg); |
| ... | ... | @@ -5402,7 +5449,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 5402 | 5449 | const options = sema.resolveExportOptions(block, .unneeded, extra.options) catch |err| switch (err) { |
| 5403 | 5450 | error.NeededSourceLocation => { |
| 5404 | 5451 | _ = try sema.resolveExportOptions(block, options_src, extra.options); |
| 5405 | return error.AnalysisFail; | |
| 5452 | unreachable; | |
| 5406 | 5453 | }, |
| 5407 | 5454 | else => |e| return e, |
| 5408 | 5455 | }; |
| ... | ... | @@ -5429,7 +5476,7 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 5429 | 5476 | const options = sema.resolveExportOptions(block, .unneeded, extra.options) catch |err| switch (err) { |
| 5430 | 5477 | error.NeededSourceLocation => { |
| 5431 | 5478 | _ = try sema.resolveExportOptions(block, options_src, extra.options); |
| 5432 | return error.AnalysisFail; | |
| 5479 | unreachable; | |
| 5433 | 5480 | }, |
| 5434 | 5481 | else => |e| return e, |
| 5435 | 5482 | }; |
| ... | ... | @@ -6379,6 +6426,7 @@ fn analyzeCall( |
| 6379 | 6426 | }), |
| 6380 | 6427 | else => unreachable, |
| 6381 | 6428 | }; |
| 6429 | if (!is_comptime_call and module_fn.state == .sema_failure) return error.AnalysisFail; | |
| 6382 | 6430 | |
| 6383 | 6431 | // Analyze the ZIR. The same ZIR gets analyzed into a runtime function |
| 6384 | 6432 | // or an inlined call depending on what union tag the `label` field is |
| ... | ... | @@ -6512,7 +6560,7 @@ fn analyzeCall( |
| 6512 | 6560 | func_ty_info.param_types, |
| 6513 | 6561 | func, |
| 6514 | 6562 | ); |
| 6515 | return error.AnalysisFail; | |
| 6563 | unreachable; | |
| 6516 | 6564 | }, |
| 6517 | 6565 | else => |e| return e, |
| 6518 | 6566 | }; |
| ... | ... | @@ -6674,7 +6722,7 @@ fn analyzeCall( |
| 6674 | 6722 | uncasted_arg, |
| 6675 | 6723 | opts, |
| 6676 | 6724 | ); |
| 6677 | return error.AnalysisFail; | |
| 6725 | unreachable; | |
| 6678 | 6726 | }, |
| 6679 | 6727 | else => |e| return e, |
| 6680 | 6728 | }; |
| ... | ... | @@ -6687,7 +6735,7 @@ fn analyzeCall( |
| 6687 | 6735 | uncasted_arg, |
| 6688 | 6736 | Module.argSrc(call_src.node_offset.x, sema.gpa, decl, i, bound_arg_src), |
| 6689 | 6737 | ); |
| 6690 | return error.AnalysisFail; | |
| 6738 | unreachable; | |
| 6691 | 6739 | }, |
| 6692 | 6740 | else => |e| return e, |
| 6693 | 6741 | }; |
| ... | ... | @@ -6991,7 +7039,7 @@ fn instantiateGenericCall( |
| 6991 | 7039 | const decl = sema.mod.declPtr(block.src_decl); |
| 6992 | 7040 | const arg_src = Module.argSrc(call_src.node_offset.x, sema.gpa, decl, i, bound_arg_src); |
| 6993 | 7041 | _ = try sema.analyzeGenericCallArgVal(block, arg_src, uncasted_args[i]); |
| 6994 | return error.AnalysisFail; | |
| 7042 | unreachable; | |
| 6995 | 7043 | }, |
| 6996 | 7044 | else => |e| return e, |
| 6997 | 7045 | }; |
| ... | ... | @@ -7174,7 +7222,7 @@ fn instantiateGenericCall( |
| 7174 | 7222 | const decl = sema.mod.declPtr(block.src_decl); |
| 7175 | 7223 | const arg_src = Module.argSrc(call_src.node_offset.x, sema.gpa, decl, arg_i, bound_arg_src); |
| 7176 | 7224 | _ = try sema.resolveConstValue(block, arg_src, arg, "argument to parameter with comptime-only type must be comptime-known"); |
| 7177 | return error.AnalysisFail; | |
| 7225 | unreachable; | |
| 7178 | 7226 | }, |
| 7179 | 7227 | else => |e| return e, |
| 7180 | 7228 | }; |
| ... | ... | @@ -7330,7 +7378,7 @@ fn instantiateGenericCall( |
| 7330 | 7378 | new_fn_info, |
| 7331 | 7379 | &runtime_i, |
| 7332 | 7380 | ); |
| 7333 | return error.AnalysisFail; | |
| 7381 | unreachable; | |
| 7334 | 7382 | }, |
| 7335 | 7383 | else => |e| return e, |
| 7336 | 7384 | }; |
| ... | ... | @@ -8417,6 +8465,10 @@ fn funcCommon( |
| 8417 | 8465 | const param_types = try sema.arena.alloc(Type, block.params.items.len); |
| 8418 | 8466 | const comptime_params = try sema.arena.alloc(bool, block.params.items.len); |
| 8419 | 8467 | for (block.params.items) |param, i| { |
| 8468 | const is_noalias = blk: { | |
| 8469 | const index = std.math.cast(u5, i) orelse break :blk false; | |
| 8470 | break :blk @truncate(u1, noalias_bits >> index) != 0; | |
| 8471 | }; | |
| 8420 | 8472 | param_types[i] = param.ty; |
| 8421 | 8473 | sema.analyzeParameter( |
| 8422 | 8474 | block, |
| ... | ... | @@ -8427,6 +8479,7 @@ fn funcCommon( |
| 8427 | 8479 | &is_generic, |
| 8428 | 8480 | cc_resolved, |
| 8429 | 8481 | has_body, |
| 8482 | is_noalias, | |
| 8430 | 8483 | ) catch |err| switch (err) { |
| 8431 | 8484 | error.NeededSourceLocation => { |
| 8432 | 8485 | const decl = sema.mod.declPtr(block.src_decl); |
| ... | ... | @@ -8439,8 +8492,9 @@ fn funcCommon( |
| 8439 | 8492 | &is_generic, |
| 8440 | 8493 | cc_resolved, |
| 8441 | 8494 | has_body, |
| 8495 | is_noalias, | |
| 8442 | 8496 | ); |
| 8443 | return error.AnalysisFail; | |
| 8497 | unreachable; | |
| 8444 | 8498 | }, |
| 8445 | 8499 | else => |e| return e, |
| 8446 | 8500 | }; |
| ... | ... | @@ -8689,6 +8743,7 @@ fn analyzeParameter( |
| 8689 | 8743 | is_generic: *bool, |
| 8690 | 8744 | cc: std.builtin.CallingConvention, |
| 8691 | 8745 | has_body: bool, |
| 8746 | is_noalias: bool, | |
| 8692 | 8747 | ) !void { |
| 8693 | 8748 | const requires_comptime = try sema.typeRequiresComptime(param.ty); |
| 8694 | 8749 | comptime_params[i] = param.is_comptime or requires_comptime; |
| ... | ... | @@ -8743,6 +8798,9 @@ fn analyzeParameter( |
| 8743 | 8798 | }; |
| 8744 | 8799 | return sema.failWithOwnedErrorMsg(msg); |
| 8745 | 8800 | } |
| 8801 | if (!this_generic and is_noalias and !param.ty.isPtrAtRuntime()) { | |
| 8802 | return sema.fail(block, param_src, "non-pointer parameter declared noalias", .{}); | |
| 8803 | } | |
| 8746 | 8804 | } |
| 8747 | 8805 | |
| 8748 | 8806 | fn zirParam( |
| ... | ... | @@ -10633,7 +10691,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10633 | 10691 | const case_src = Module.SwitchProngSrc{ .range = .{ .prong = multi_i, .item = range_i } }; |
| 10634 | 10692 | const decl = sema.mod.declPtr(case_block.src_decl); |
| 10635 | 10693 | try sema.emitBackwardBranch(block, case_src.resolve(sema.gpa, decl, src_node_offset, .none)); |
| 10636 | return error.AnalysisFail; | |
| 10694 | unreachable; | |
| 10637 | 10695 | }, |
| 10638 | 10696 | else => return err, |
| 10639 | 10697 | }; |
| ... | ... | @@ -10669,7 +10727,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10669 | 10727 | const case_src = Module.SwitchProngSrc{ .multi = .{ .prong = multi_i, .item = @intCast(u32, item_i) } }; |
| 10670 | 10728 | const decl = sema.mod.declPtr(case_block.src_decl); |
| 10671 | 10729 | try sema.emitBackwardBranch(block, case_src.resolve(sema.gpa, decl, src_node_offset, .none)); |
| 10672 | return error.AnalysisFail; | |
| 10730 | unreachable; | |
| 10673 | 10731 | }, |
| 10674 | 10732 | else => return err, |
| 10675 | 10733 | }; |
| ... | ... | @@ -11101,10 +11159,8 @@ fn resolveSwitchItemVal( |
| 11101 | 11159 | } else |err| switch (err) { |
| 11102 | 11160 | error.NeededSourceLocation => { |
| 11103 | 11161 | const src = switch_prong_src.resolve(sema.gpa, sema.mod.declPtr(block.src_decl), switch_node_offset, range_expand); |
| 11104 | return TypedValue{ | |
| 11105 | .ty = item_ty, | |
| 11106 | .val = try sema.resolveConstValue(block, src, item, "switch prong values must be comptime-known"), | |
| 11107 | }; | |
| 11162 | _ = try sema.resolveConstValue(block, src, item, "switch prong values must be comptime-known"); | |
| 11163 | unreachable; | |
| 11108 | 11164 | }, |
| 11109 | 11165 | else => |e| return e, |
| 11110 | 11166 | } |
| ... | ... | @@ -11618,6 +11674,21 @@ fn zirShl( |
| 11618 | 11674 | }); |
| 11619 | 11675 | } |
| 11620 | 11676 | } |
| 11677 | if (rhs_ty.zigTypeTag() == .Vector) { | |
| 11678 | var i: usize = 0; | |
| 11679 | while (i < rhs_ty.vectorLen()) : (i += 1) { | |
| 11680 | if (rhs_val.indexVectorlike(i).compareHetero(.lt, Value.zero, target)) { | |
| 11681 | return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{ | |
| 11682 | rhs_val.indexVectorlike(i).fmtValue(scalar_ty, sema.mod), | |
| 11683 | i, | |
| 11684 | }); | |
| 11685 | } | |
| 11686 | } | |
| 11687 | } else if (rhs_val.compareHetero(.lt, Value.zero, target)) { | |
| 11688 | return sema.fail(block, rhs_src, "shift by negative amount '{}'", .{ | |
| 11689 | rhs_val.fmtValue(scalar_ty, sema.mod), | |
| 11690 | }); | |
| 11691 | } | |
| 11621 | 11692 | } |
| 11622 | 11693 | |
| 11623 | 11694 | const runtime_src = if (maybe_lhs_val) |lhs_val| rs: { |
| ... | ... | @@ -11787,6 +11858,21 @@ fn zirShr( |
| 11787 | 11858 | }); |
| 11788 | 11859 | } |
| 11789 | 11860 | } |
| 11861 | if (rhs_ty.zigTypeTag() == .Vector) { | |
| 11862 | var i: usize = 0; | |
| 11863 | while (i < rhs_ty.vectorLen()) : (i += 1) { | |
| 11864 | if (rhs_val.indexVectorlike(i).compareHetero(.lt, Value.zero, target)) { | |
| 11865 | return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{ | |
| 11866 | rhs_val.indexVectorlike(i).fmtValue(scalar_ty, sema.mod), | |
| 11867 | i, | |
| 11868 | }); | |
| 11869 | } | |
| 11870 | } | |
| 11871 | } else if (rhs_val.compareHetero(.lt, Value.zero, target)) { | |
| 11872 | return sema.fail(block, rhs_src, "shift by negative amount '{}'", .{ | |
| 11873 | rhs_val.fmtValue(scalar_ty, sema.mod), | |
| 11874 | }); | |
| 11875 | } | |
| 11790 | 11876 | if (maybe_lhs_val) |lhs_val| { |
| 11791 | 11877 | if (lhs_val.isUndef()) { |
| 11792 | 11878 | return sema.addConstUndef(lhs_ty); |
| ... | ... | @@ -14721,7 +14807,9 @@ fn analyzeCmp( |
| 14721 | 14807 | ) CompileError!Air.Inst.Ref { |
| 14722 | 14808 | const lhs_ty = sema.typeOf(lhs); |
| 14723 | 14809 | const rhs_ty = sema.typeOf(rhs); |
| 14724 | try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src); | |
| 14810 | if (lhs_ty.zigTypeTag() != .Optional and rhs_ty.zigTypeTag() != .Optional) { | |
| 14811 | try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src); | |
| 14812 | } | |
| 14725 | 14813 | |
| 14726 | 14814 | if (lhs_ty.zigTypeTag() == .Vector and rhs_ty.zigTypeTag() == .Vector) { |
| 14727 | 14815 | return sema.cmpVector(block, src, lhs, rhs, op, lhs_src, rhs_src); |
| ... | ... | @@ -15217,12 +15305,17 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15217 | 15305 | try Value.Tag.ty.create(params_anon_decl.arena(), try param_ty.copy(params_anon_decl.arena())), |
| 15218 | 15306 | ); |
| 15219 | 15307 | |
| 15308 | const is_noalias = blk: { | |
| 15309 | const index = std.math.cast(u5, i) orelse break :blk false; | |
| 15310 | break :blk @truncate(u1, info.noalias_bits >> index) != 0; | |
| 15311 | }; | |
| 15312 | ||
| 15220 | 15313 | const param_fields = try params_anon_decl.arena().create([3]Value); |
| 15221 | 15314 | param_fields.* = .{ |
| 15222 | 15315 | // is_generic: bool, |
| 15223 | 15316 | Value.makeBool(is_generic), |
| 15224 | 15317 | // is_noalias: bool, |
| 15225 | Value.false, // TODO | |
| 15318 | Value.makeBool(is_noalias), | |
| 15226 | 15319 | // arg_type: ?type, |
| 15227 | 15320 | param_ty_val, |
| 15228 | 15321 | }; |
| ... | ... | @@ -17409,7 +17502,7 @@ fn zirStructInitAnon( |
| 17409 | 17502 | const decl = sema.mod.declPtr(block.src_decl); |
| 17410 | 17503 | const field_src = Module.initSrc(src.node_offset.x, sema.gpa, decl, runtime_index); |
| 17411 | 17504 | try sema.requireRuntimeBlock(block, src, field_src); |
| 17412 | return error.AnalysisFail; | |
| 17505 | unreachable; | |
| 17413 | 17506 | }, |
| 17414 | 17507 | else => |e| return e, |
| 17415 | 17508 | }; |
| ... | ... | @@ -17474,25 +17567,31 @@ fn zirArrayInit( |
| 17474 | 17567 | defer gpa.free(resolved_args); |
| 17475 | 17568 | for (args[1..]) |arg, i| { |
| 17476 | 17569 | const resolved_arg = try sema.resolveInst(arg); |
| 17477 | const arg_src = src; // TODO better source location | |
| 17478 | 17570 | const elem_ty = if (array_ty.zigTypeTag() == .Struct) |
| 17479 | 17571 | array_ty.structFieldType(i) |
| 17480 | 17572 | else |
| 17481 | 17573 | array_ty.elemType2(); |
| 17482 | resolved_args[i] = try sema.coerce(block, elem_ty, resolved_arg, arg_src); | |
| 17574 | resolved_args[i] = sema.coerce(block, elem_ty, resolved_arg, .unneeded) catch |err| switch (err) { | |
| 17575 | error.NeededSourceLocation => { | |
| 17576 | const decl = sema.mod.declPtr(block.src_decl); | |
| 17577 | const elem_src = Module.initSrc(src.node_offset.x, sema.gpa, decl, i); | |
| 17578 | _ = try sema.coerce(block, elem_ty, resolved_arg, elem_src); | |
| 17579 | unreachable; | |
| 17580 | }, | |
| 17581 | else => return err, | |
| 17582 | }; | |
| 17483 | 17583 | } |
| 17484 | 17584 | |
| 17485 | 17585 | if (sentinel_val) |some| { |
| 17486 | 17586 | resolved_args[resolved_args.len - 1] = try sema.addConstant(array_ty.elemType2(), some); |
| 17487 | 17587 | } |
| 17488 | 17588 | |
| 17489 | const opt_runtime_src: ?LazySrcLoc = for (resolved_args) |arg| { | |
| 17490 | const arg_src = src; // TODO better source location | |
| 17589 | const opt_runtime_index: ?u32 = for (resolved_args) |arg, i| { | |
| 17491 | 17590 | const comptime_known = try sema.isComptimeKnown(arg); |
| 17492 | if (!comptime_known) break arg_src; | |
| 17591 | if (!comptime_known) break @intCast(u32, i); | |
| 17493 | 17592 | } else null; |
| 17494 | 17593 | |
| 17495 | const runtime_src = opt_runtime_src orelse { | |
| 17594 | const runtime_index = opt_runtime_index orelse { | |
| 17496 | 17595 | const elem_vals = try sema.arena.alloc(Value, resolved_args.len); |
| 17497 | 17596 | |
| 17498 | 17597 | for (resolved_args) |arg, i| { |
| ... | ... | @@ -17504,7 +17603,15 @@ fn zirArrayInit( |
| 17504 | 17603 | return sema.addConstantMaybeRef(block, array_ty, array_val, is_ref); |
| 17505 | 17604 | }; |
| 17506 | 17605 | |
| 17507 | try sema.requireRuntimeBlock(block, src, runtime_src); | |
| 17606 | sema.requireRuntimeBlock(block, src, .unneeded) catch |err| switch (err) { | |
| 17607 | error.NeededSourceLocation => { | |
| 17608 | const decl = sema.mod.declPtr(block.src_decl); | |
| 17609 | const elem_src = Module.initSrc(src.node_offset.x, sema.gpa, decl, runtime_index); | |
| 17610 | try sema.requireRuntimeBlock(block, src, elem_src); | |
| 17611 | unreachable; | |
| 17612 | }, | |
| 17613 | else => return err, | |
| 17614 | }; | |
| 17508 | 17615 | try sema.queueFullTypeResolution(array_ty); |
| 17509 | 17616 | |
| 17510 | 17617 | if (is_ref) { |
| ... | ... | @@ -18502,10 +18609,47 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in |
| 18502 | 18609 | } |
| 18503 | 18610 | |
| 18504 | 18611 | var buffer: Value.ToTypeBuffer = undefined; |
| 18612 | const field_ty = try field_type_val.toType(&buffer).copy(new_decl_arena_allocator); | |
| 18505 | 18613 | gop.value_ptr.* = .{ |
| 18506 | .ty = try field_type_val.toType(&buffer).copy(new_decl_arena_allocator), | |
| 18614 | .ty = field_ty, | |
| 18507 | 18615 | .abi_align = @intCast(u32, (try alignment_val.getUnsignedIntAdvanced(target, sema)).?), |
| 18508 | 18616 | }; |
| 18617 | ||
| 18618 | if (field_ty.zigTypeTag() == .Opaque) { | |
| 18619 | const msg = msg: { | |
| 18620 | const msg = try sema.errMsg(block, src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{}); | |
| 18621 | errdefer msg.destroy(sema.gpa); | |
| 18622 | ||
| 18623 | try sema.addDeclaredHereNote(msg, field_ty); | |
| 18624 | break :msg msg; | |
| 18625 | }; | |
| 18626 | return sema.failWithOwnedErrorMsg(msg); | |
| 18627 | } | |
| 18628 | if (union_obj.layout == .Extern and !try sema.validateExternType(field_ty, .union_field)) { | |
| 18629 | const msg = msg: { | |
| 18630 | const msg = try sema.errMsg(block, src, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)}); | |
| 18631 | errdefer msg.destroy(sema.gpa); | |
| 18632 | ||
| 18633 | const src_decl = sema.mod.declPtr(block.src_decl); | |
| 18634 | try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl), field_ty, .union_field); | |
| 18635 | ||
| 18636 | try sema.addDeclaredHereNote(msg, field_ty); | |
| 18637 | break :msg msg; | |
| 18638 | }; | |
| 18639 | return sema.failWithOwnedErrorMsg(msg); | |
| 18640 | } else if (union_obj.layout == .Packed and !(validatePackedType(field_ty))) { | |
| 18641 | const msg = msg: { | |
| 18642 | const msg = try sema.errMsg(block, src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)}); | |
| 18643 | errdefer msg.destroy(sema.gpa); | |
| 18644 | ||
| 18645 | const src_decl = sema.mod.declPtr(block.src_decl); | |
| 18646 | try sema.explainWhyTypeIsNotPacked(msg, src.toSrcLoc(src_decl), field_ty); | |
| 18647 | ||
| 18648 | try sema.addDeclaredHereNote(msg, field_ty); | |
| 18649 | break :msg msg; | |
| 18650 | }; | |
| 18651 | return sema.failWithOwnedErrorMsg(msg); | |
| 18652 | } | |
| 18509 | 18653 | } |
| 18510 | 18654 | |
| 18511 | 18655 | if (tag_ty_field_names) |names| { |
| ... | ... | @@ -18587,21 +18731,25 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in |
| 18587 | 18731 | // is_noalias: bool, |
| 18588 | 18732 | const arg_is_noalias = arg_val[1].toBool(); |
| 18589 | 18733 | // arg_type: ?type, |
| 18590 | const param_type_val = arg_val[2]; | |
| 18734 | const param_type_opt_val = arg_val[2]; | |
| 18591 | 18735 | |
| 18592 | 18736 | if (arg_is_generic) { |
| 18593 | 18737 | return sema.fail(block, src, "Type.Fn.Param.is_generic must be false for @Type", .{}); |
| 18594 | 18738 | } |
| 18595 | 18739 | |
| 18740 | const param_type_val = param_type_opt_val.optionalValue() orelse | |
| 18741 | return sema.fail(block, src, "Type.Fn.Param.arg_type must be non-null for @Type", .{}); | |
| 18742 | const param_type = try param_type_val.toType(&buf).copy(sema.arena); | |
| 18743 | ||
| 18596 | 18744 | if (arg_is_noalias) { |
| 18597 | noalias_bits = @as(u32, 1) << (std.math.cast(u5, i) orelse | |
| 18745 | if (!param_type.isPtrAtRuntime()) { | |
| 18746 | return sema.fail(block, src, "non-pointer parameter declared noalias", .{}); | |
| 18747 | } | |
| 18748 | noalias_bits |= @as(u32, 1) << (std.math.cast(u5, i) orelse | |
| 18598 | 18749 | return sema.fail(block, src, "this compiler implementation only supports 'noalias' on the first 32 parameters", .{})); |
| 18599 | 18750 | } |
| 18600 | 18751 | |
| 18601 | const param_type = param_type_val.optionalValue() orelse | |
| 18602 | return sema.fail(block, src, "Type.Fn.Param.arg_type must be non-null for @Type", .{}); | |
| 18603 | ||
| 18604 | param_types[i] = try param_type.toType(&buf).copy(sema.arena); | |
| 18752 | param_types[i] = param_type; | |
| 18605 | 18753 | comptime_params[i] = false; |
| 18606 | 18754 | } |
| 18607 | 18755 | |
| ... | ... | @@ -18745,13 +18893,60 @@ fn reifyStruct( |
| 18745 | 18893 | } |
| 18746 | 18894 | |
| 18747 | 18895 | var buffer: Value.ToTypeBuffer = undefined; |
| 18896 | const field_ty = try field_type_val.toType(&buffer).copy(new_decl_arena_allocator); | |
| 18748 | 18897 | gop.value_ptr.* = .{ |
| 18749 | .ty = try field_type_val.toType(&buffer).copy(new_decl_arena_allocator), | |
| 18898 | .ty = field_ty, | |
| 18750 | 18899 | .abi_align = abi_align, |
| 18751 | 18900 | .default_val = default_val, |
| 18752 | 18901 | .is_comptime = is_comptime_val.toBool(), |
| 18753 | 18902 | .offset = undefined, |
| 18754 | 18903 | }; |
| 18904 | ||
| 18905 | if (field_ty.zigTypeTag() == .Opaque) { | |
| 18906 | const msg = msg: { | |
| 18907 | const msg = try sema.errMsg(block, src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{}); | |
| 18908 | errdefer msg.destroy(sema.gpa); | |
| 18909 | ||
| 18910 | try sema.addDeclaredHereNote(msg, field_ty); | |
| 18911 | break :msg msg; | |
| 18912 | }; | |
| 18913 | return sema.failWithOwnedErrorMsg(msg); | |
| 18914 | } | |
| 18915 | if (field_ty.zigTypeTag() == .NoReturn) { | |
| 18916 | const msg = msg: { | |
| 18917 | const msg = try sema.errMsg(block, src, "struct fields cannot be 'noreturn'", .{}); | |
| 18918 | errdefer msg.destroy(sema.gpa); | |
| 18919 | ||
| 18920 | try sema.addDeclaredHereNote(msg, field_ty); | |
| 18921 | break :msg msg; | |
| 18922 | }; | |
| 18923 | return sema.failWithOwnedErrorMsg(msg); | |
| 18924 | } | |
| 18925 | if (struct_obj.layout == .Extern and !try sema.validateExternType(field_ty, .struct_field)) { | |
| 18926 | const msg = msg: { | |
| 18927 | const msg = try sema.errMsg(block, src, "extern structs cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)}); | |
| 18928 | errdefer msg.destroy(sema.gpa); | |
| 18929 | ||
| 18930 | const src_decl = sema.mod.declPtr(block.src_decl); | |
| 18931 | try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl), field_ty, .struct_field); | |
| 18932 | ||
| 18933 | try sema.addDeclaredHereNote(msg, field_ty); | |
| 18934 | break :msg msg; | |
| 18935 | }; | |
| 18936 | return sema.failWithOwnedErrorMsg(msg); | |
| 18937 | } else if (struct_obj.layout == .Packed and !(validatePackedType(field_ty))) { | |
| 18938 | const msg = msg: { | |
| 18939 | const msg = try sema.errMsg(block, src, "packed structs cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)}); | |
| 18940 | errdefer msg.destroy(sema.gpa); | |
| 18941 | ||
| 18942 | const src_decl = sema.mod.declPtr(block.src_decl); | |
| 18943 | try sema.explainWhyTypeIsNotPacked(msg, src.toSrcLoc(src_decl), field_ty); | |
| 18944 | ||
| 18945 | try sema.addDeclaredHereNote(msg, field_ty); | |
| 18946 | break :msg msg; | |
| 18947 | }; | |
| 18948 | return sema.failWithOwnedErrorMsg(msg); | |
| 18949 | } | |
| 18755 | 18950 | } |
| 18756 | 18951 | |
| 18757 | 18952 | if (layout == .Packed) { |
| ... | ... | @@ -21544,7 +21739,7 @@ fn zirPrefetch( |
| 21544 | 21739 | const options = sema.resolvePrefetchOptions(block, .unneeded, extra.rhs) catch |err| switch (err) { |
| 21545 | 21740 | error.NeededSourceLocation => { |
| 21546 | 21741 | _ = try sema.resolvePrefetchOptions(block, opts_src, extra.rhs); |
| 21547 | return error.AnalysisFail; | |
| 21742 | unreachable; | |
| 21548 | 21743 | }, |
| 21549 | 21744 | else => |e| return e, |
| 21550 | 21745 | }; |
| ... | ... | @@ -21637,7 +21832,7 @@ fn zirBuiltinExtern( |
| 21637 | 21832 | const options = sema.resolveExternOptions(block, .unneeded, extra.rhs) catch |err| switch (err) { |
| 21638 | 21833 | error.NeededSourceLocation => { |
| 21639 | 21834 | _ = try sema.resolveExternOptions(block, options_src, extra.rhs); |
| 21640 | return error.AnalysisFail; | |
| 21835 | unreachable; | |
| 21641 | 21836 | }, |
| 21642 | 21837 | else => |e| return e, |
| 21643 | 21838 | }; |
| ... | ... | @@ -24493,7 +24688,7 @@ fn coerceExtra( |
| 24493 | 24688 | } |
| 24494 | 24689 | if (try sema.resolveMaybeUndefVal(inst)) |val| { |
| 24495 | 24690 | const result_val = try val.floatCast(sema.arena, dest_ty, target); |
| 24496 | if (!val.eql(result_val, dest_ty, sema.mod)) { | |
| 24691 | if (!val.eql(result_val, inst_ty, sema.mod)) { | |
| 24497 | 24692 | return sema.fail( |
| 24498 | 24693 | block, |
| 24499 | 24694 | inst_src, |
| ... | ... | @@ -24987,7 +25182,7 @@ const InMemoryCoercionResult = union(enum) { |
| 24987 | 25182 | cur = param.child; |
| 24988 | 25183 | }, |
| 24989 | 25184 | .fn_cc => |cc| { |
| 24990 | try sema.errNote(block, src, msg, "calling convention {s} cannot cast into calling convention {s}", .{ @tagName(cc.actual), @tagName(cc.wanted) }); | |
| 25185 | try sema.errNote(block, src, msg, "calling convention '{s}' cannot cast into calling convention '{s}'", .{ @tagName(cc.actual), @tagName(cc.wanted) }); | |
| 24991 | 25186 | break; |
| 24992 | 25187 | }, |
| 24993 | 25188 | .fn_return_type => |pair| { |
| ... | ... | @@ -26842,6 +27037,9 @@ fn coerceCompatiblePtrs( |
| 26842 | 27037 | ) !Air.Inst.Ref { |
| 26843 | 27038 | const inst_ty = sema.typeOf(inst); |
| 26844 | 27039 | if (try sema.resolveMaybeUndefVal(inst)) |val| { |
| 27040 | if (!val.isUndef() and val.isNull() and !dest_ty.isAllowzeroPtr()) { | |
| 27041 | return sema.fail(block, inst_src, "null pointer casted to type '{}'", .{dest_ty.fmt(sema.mod)}); | |
| 27042 | } | |
| 26845 | 27043 | // The comptime Value representation is compatible with both types. |
| 26846 | 27044 | return sema.addConstant(dest_ty, val); |
| 26847 | 27045 | } |
| ... | ... | @@ -30177,7 +30375,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 30177 | 30375 | const tree = try sema.getAstTree(&block_scope); |
| 30178 | 30376 | const init_src = containerFieldInitSrcLoc(decl, tree.*, 0, i); |
| 30179 | 30377 | _ = try sema.coerce(&block_scope, field.ty, init, init_src); |
| 30180 | return error.AnalysisFail; | |
| 30378 | unreachable; | |
| 30181 | 30379 | }, |
| 30182 | 30380 | else => |e| return e, |
| 30183 | 30381 | }; |
| ... | ... | @@ -30304,6 +30502,25 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 30304 | 30502 | if (int_tag_ty.zigTypeTag() != .Int and int_tag_ty.zigTypeTag() != .ComptimeInt) { |
| 30305 | 30503 | return sema.fail(&block_scope, tag_ty_src, "expected integer tag type, found '{}'", .{int_tag_ty.fmt(sema.mod)}); |
| 30306 | 30504 | } |
| 30505 | ||
| 30506 | if (fields_len > 0) { | |
| 30507 | var field_count_val: Value.Payload.U64 = .{ | |
| 30508 | .base = .{ .tag = .int_u64 }, | |
| 30509 | .data = fields_len - 1, | |
| 30510 | }; | |
| 30511 | if (!(try sema.intFitsInType(Value.initPayload(&field_count_val.base), int_tag_ty, null))) { | |
| 30512 | const msg = msg: { | |
| 30513 | const msg = try sema.errMsg(&block_scope, tag_ty_src, "specified integer tag type cannot represent every field", .{}); | |
| 30514 | errdefer msg.destroy(sema.gpa); | |
| 30515 | try sema.errNote(&block_scope, tag_ty_src, msg, "type '{}' cannot fit values in range 0...{d}", .{ | |
| 30516 | int_tag_ty.fmt(sema.mod), | |
| 30517 | fields_len - 1, | |
| 30518 | }); | |
| 30519 | break :msg msg; | |
| 30520 | }; | |
| 30521 | return sema.failWithOwnedErrorMsg(msg); | |
| 30522 | } | |
| 30523 | } | |
| 30307 | 30524 | union_obj.tag_ty = try sema.generateUnionTagTypeNumbered(&block_scope, fields_len, provided_ty, union_obj); |
| 30308 | 30525 | const enum_obj = union_obj.tag_ty.castTag(.enum_numbered).?.data; |
| 30309 | 30526 | enum_field_names = &enum_obj.fields; |
| ... | ... | @@ -30379,7 +30596,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 30379 | 30596 | } else .none; |
| 30380 | 30597 | |
| 30381 | 30598 | if (enum_value_map) |map| { |
| 30382 | if (tag_ref != .none) { | |
| 30599 | const copied_val = if (tag_ref != .none) blk: { | |
| 30383 | 30600 | const tag_src = src; // TODO better source location |
| 30384 | 30601 | const coerced = try sema.coerce(&block_scope, int_tag_ty, tag_ref, tag_src); |
| 30385 | 30602 | const val = try sema.resolveConstValue(&block_scope, tag_src, coerced, "enum tag value must be comptime-known"); |
| ... | ... | @@ -30387,23 +30604,31 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 30387 | 30604 | |
| 30388 | 30605 | // This puts the memory into the union arena, not the enum arena, but |
| 30389 | 30606 | // it is OK since they share the same lifetime. |
| 30390 | const copied_val = try val.copy(decl_arena_allocator); | |
| 30391 | map.putAssumeCapacityContext(copied_val, {}, .{ | |
| 30392 | .ty = int_tag_ty, | |
| 30393 | .mod = mod, | |
| 30394 | }); | |
| 30395 | } else { | |
| 30607 | break :blk try val.copy(decl_arena_allocator); | |
| 30608 | } else blk: { | |
| 30396 | 30609 | const val = if (last_tag_val) |val| |
| 30397 | 30610 | try sema.intAdd(val, Value.one, int_tag_ty) |
| 30398 | 30611 | else |
| 30399 | 30612 | Value.zero; |
| 30400 | 30613 | last_tag_val = val; |
| 30401 | 30614 | |
| 30402 | const copied_val = try val.copy(decl_arena_allocator); | |
| 30403 | map.putAssumeCapacityContext(copied_val, {}, .{ | |
| 30404 | .ty = int_tag_ty, | |
| 30405 | .mod = mod, | |
| 30406 | }); | |
| 30615 | break :blk try val.copy(decl_arena_allocator); | |
| 30616 | }; | |
| 30617 | const gop = map.getOrPutAssumeCapacityContext(copied_val, .{ | |
| 30618 | .ty = int_tag_ty, | |
| 30619 | .mod = mod, | |
| 30620 | }); | |
| 30621 | if (gop.found_existing) { | |
| 30622 | const tree = try sema.getAstTree(&block_scope); | |
| 30623 | const field_src = enumFieldSrcLoc(sema.mod.declPtr(block_scope.src_decl), tree.*, src.node_offset.x, field_i); | |
| 30624 | const other_field_src = enumFieldSrcLoc(sema.mod.declPtr(block_scope.src_decl), tree.*, src.node_offset.x, gop.index); | |
| 30625 | const msg = msg: { | |
| 30626 | const msg = try sema.errMsg(&block_scope, field_src, "enum tag value {} already taken", .{copied_val.fmtValue(int_tag_ty, sema.mod)}); | |
| 30627 | errdefer msg.destroy(gpa); | |
| 30628 | try sema.errNote(&block_scope, other_field_src, msg, "other occurrence here", .{}); | |
| 30629 | break :msg msg; | |
| 30630 | }; | |
| 30631 | return sema.failWithOwnedErrorMsg(msg); | |
| 30407 | 30632 | } |
| 30408 | 30633 | } |
| 30409 | 30634 | |
| ... | ... | @@ -30574,16 +30799,17 @@ fn generateUnionTagTypeNumbered( |
| 30574 | 30799 | new_decl.name_fully_qualified = true; |
| 30575 | 30800 | errdefer mod.abortAnonDecl(new_decl_index); |
| 30576 | 30801 | |
| 30802 | const copied_int_ty = try int_ty.copy(new_decl_arena_allocator); | |
| 30577 | 30803 | enum_obj.* = .{ |
| 30578 | 30804 | .owner_decl = new_decl_index, |
| 30579 | .tag_ty = int_ty, | |
| 30805 | .tag_ty = copied_int_ty, | |
| 30580 | 30806 | .fields = .{}, |
| 30581 | 30807 | .values = .{}, |
| 30582 | 30808 | }; |
| 30583 | 30809 | // Here we pre-allocate the maps using the decl arena. |
| 30584 | 30810 | try enum_obj.fields.ensureTotalCapacity(new_decl_arena_allocator, fields_len); |
| 30585 | 30811 | try enum_obj.values.ensureTotalCapacityContext(new_decl_arena_allocator, fields_len, .{ |
| 30586 | .ty = int_ty, | |
| 30812 | .ty = copied_int_ty, | |
| 30587 | 30813 | .mod = mod, |
| 30588 | 30814 | }); |
| 30589 | 30815 | try new_decl.finalizeNewArena(&new_decl_arena); |
src/clang.zig+4-4| ... | ... | @@ -1897,13 +1897,13 @@ pub const OffsetOfNode_Kind = enum(c_int) { |
| 1897 | 1897 | Base, |
| 1898 | 1898 | }; |
| 1899 | 1899 | |
| 1900 | pub const Stage2ErrorMsg = extern struct { | |
| 1900 | pub const ErrorMsg = extern struct { | |
| 1901 | 1901 | filename_ptr: ?[*]const u8, |
| 1902 | 1902 | filename_len: usize, |
| 1903 | 1903 | msg_ptr: [*]const u8, |
| 1904 | 1904 | msg_len: usize, |
| 1905 | 1905 | // valid until the ASTUnit is freed |
| 1906 | source: ?[*]const u8, | |
| 1906 | source: ?[*:0]const u8, | |
| 1907 | 1907 | // 0 based |
| 1908 | 1908 | line: c_uint, |
| 1909 | 1909 | // 0 based |
| ... | ... | @@ -1912,14 +1912,14 @@ pub const Stage2ErrorMsg = extern struct { |
| 1912 | 1912 | offset: c_uint, |
| 1913 | 1913 | |
| 1914 | 1914 | pub const delete = ZigClangErrorMsg_delete; |
| 1915 | extern fn ZigClangErrorMsg_delete(ptr: [*]Stage2ErrorMsg, len: usize) void; | |
| 1915 | extern fn ZigClangErrorMsg_delete(ptr: [*]ErrorMsg, len: usize) void; | |
| 1916 | 1916 | }; |
| 1917 | 1917 | |
| 1918 | 1918 | pub const LoadFromCommandLine = ZigClangLoadFromCommandLine; |
| 1919 | 1919 | extern fn ZigClangLoadFromCommandLine( |
| 1920 | 1920 | args_begin: [*]?[*]const u8, |
| 1921 | 1921 | args_end: [*]?[*]const u8, |
| 1922 | errors_ptr: *[*]Stage2ErrorMsg, | |
| 1922 | errors_ptr: *[*]ErrorMsg, | |
| 1923 | 1923 | errors_len: *usize, |
| 1924 | 1924 | resources_path: [*:0]const u8, |
| 1925 | 1925 | ) ?*ASTUnit; |
src/main.zig+2-1| ... | ... | @@ -19,6 +19,7 @@ const introspect = @import("introspect.zig"); |
| 19 | 19 | const LibCInstallation = @import("libc_installation.zig").LibCInstallation; |
| 20 | 20 | const wasi_libc = @import("wasi_libc.zig"); |
| 21 | 21 | const translate_c = @import("translate_c.zig"); |
| 22 | const clang = @import("clang.zig"); | |
| 22 | 23 | const Cache = @import("Cache.zig"); |
| 23 | 24 | const target_util = @import("target.zig"); |
| 24 | 25 | const ThreadPool = @import("ThreadPool.zig"); |
| ... | ... | @@ -3552,7 +3553,7 @@ fn cmdTranslateC(comp: *Compilation, arena: Allocator, enable_cache: bool) !void |
| 3552 | 3553 | |
| 3553 | 3554 | const c_headers_dir_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{"include"}); |
| 3554 | 3555 | const c_headers_dir_path_z = try arena.dupeZ(u8, c_headers_dir_path); |
| 3555 | var clang_errors: []translate_c.ClangErrMsg = &[0]translate_c.ClangErrMsg{}; | |
| 3556 | var clang_errors: []clang.ErrorMsg = &[0]clang.ErrorMsg{}; | |
| 3556 | 3557 | var tree = translate_c.translate( |
| 3557 | 3558 | comp.gpa, |
| 3558 | 3559 | new_argv.ptr, |
src/translate_c.zig+1-7| ... | ... | @@ -13,8 +13,6 @@ const Tag = Node.Tag; |
| 13 | 13 | |
| 14 | 14 | const CallingConvention = std.builtin.CallingConvention; |
| 15 | 15 | |
| 16 | pub const ClangErrMsg = clang.Stage2ErrorMsg; | |
| 17 | ||
| 18 | 16 | pub const Error = std.mem.Allocator.Error; |
| 19 | 17 | const MacroProcessingError = Error || error{UnexpectedMacroToken}; |
| 20 | 18 | const TypeError = Error || error{UnsupportedType}; |
| ... | ... | @@ -350,7 +348,7 @@ pub fn translate( |
| 350 | 348 | gpa: mem.Allocator, |
| 351 | 349 | args_begin: [*]?[*]const u8, |
| 352 | 350 | args_end: [*]?[*]const u8, |
| 353 | errors: *[]ClangErrMsg, | |
| 351 | errors: *[]clang.ErrorMsg, | |
| 354 | 352 | resources_path: [*:0]const u8, |
| 355 | 353 | ) !std.zig.Ast { |
| 356 | 354 | // TODO stage2 bug |
| ... | ... | @@ -5115,10 +5113,6 @@ pub fn failDecl(c: *Context, loc: clang.SourceLocation, name: []const u8, compti |
| 5115 | 5113 | try c.global_scope.nodes.append(try Tag.warning.create(c.arena, location_comment)); |
| 5116 | 5114 | } |
| 5117 | 5115 | |
| 5118 | pub fn freeErrors(errors: []ClangErrMsg) void { | |
| 5119 | errors.ptr.delete(errors.len); | |
| 5120 | } | |
| 5121 | ||
| 5122 | 5116 | const PatternList = struct { |
| 5123 | 5117 | patterns: []Pattern, |
| 5124 | 5118 |
src/type.zig+2-1| ... | ... | @@ -177,9 +177,10 @@ pub const Type = extern union { |
| 177 | 177 | .Float, |
| 178 | 178 | .ComptimeFloat, |
| 179 | 179 | .ComptimeInt, |
| 180 | .Vector, // TODO some vectors require is_equality_cmp==true | |
| 181 | 180 | => true, |
| 182 | 181 | |
| 182 | .Vector => ty.elemType2().isSelfComparable(is_equality_cmp), | |
| 183 | ||
| 183 | 184 | .Bool, |
| 184 | 185 | .Type, |
| 185 | 186 | .Void, |
test/behavior/union.zig+9| ... | ... | @@ -1465,3 +1465,12 @@ test "Namespace-like union" { |
| 1465 | 1465 | var a: DepType.Version.Git = .tag; |
| 1466 | 1466 | try expect(a.frozen()); |
| 1467 | 1467 | } |
| 1468 | ||
| 1469 | test "union int tag type is properly managed" { | |
| 1470 | const Bar = union(enum(u2)) { | |
| 1471 | x: bool, | |
| 1472 | y: u8, | |
| 1473 | z: u8, | |
| 1474 | }; | |
| 1475 | try expect(@sizeOf(Bar) + 1 == 3); | |
| 1476 | } |
test/cases/compile_errors/async/Frame_of_generic_function.zig created+14| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | export fn entry() void { | |
| 2 | var frame: @Frame(func) = undefined; | |
| 3 | _ = frame; | |
| 4 | } | |
| 5 | fn func(comptime T: type) void { | |
| 6 | var x: T = undefined; | |
| 7 | _ = x; | |
| 8 | } | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=stage1 | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // tmp.zig:2:16: error: @Frame() of generic function |
test/cases/compile_errors/async/async_function_depends_on_its_own_frame.zig created+13| ... | ... | @@ -0,0 +1,13 @@ |
| 1 | export fn entry() void { | |
| 2 | _ = async amain(); | |
| 3 | } | |
| 4 | fn amain() callconv(.Async) void { | |
| 5 | var x: [@sizeOf(@Frame(amain))]u8 = undefined; | |
| 6 | _ = x; | |
| 7 | } | |
| 8 | ||
| 9 | // error | |
| 10 | // backend=stage1 | |
| 11 | // target=native | |
| 12 | // | |
| 13 | // tmp.zig:4:1: error: cannot resolve '@Frame(amain)': function not fully analyzed yet |
test/cases/compile_errors/async/async_function_indirectly_depends_on_its_own_frame.zig created+17| ... | ... | @@ -0,0 +1,17 @@ |
| 1 | export fn entry() void { | |
| 2 | _ = async amain(); | |
| 3 | } | |
| 4 | fn amain() callconv(.Async) void { | |
| 5 | other(); | |
| 6 | } | |
| 7 | fn other() void { | |
| 8 | var x: [@sizeOf(@Frame(amain))]u8 = undefined; | |
| 9 | _ = x; | |
| 10 | } | |
| 11 | ||
| 12 | // error | |
| 13 | // backend=stage1 | |
| 14 | // target=native | |
| 15 | // | |
| 16 | // tmp.zig:4:1: error: unable to determine async function frame of 'amain' | |
| 17 | // tmp.zig:5:10: note: analysis of function 'other' depends on the frame |
test/cases/compile_errors/async/bad_alignment_in_asynccall.zig created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | export fn entry() void { | |
| 2 | var ptr: fn () callconv(.Async) void = func; | |
| 3 | var bytes: [64]u8 = undefined; | |
| 4 | _ = @asyncCall(&bytes, {}, ptr, .{}); | |
| 5 | } | |
| 6 | fn func() callconv(.Async) void {} | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage1 | |
| 10 | // target=aarch64-linux-none | |
| 11 | // | |
| 12 | // tmp.zig:4:21: error: expected type '[]align(8) u8', found '*[64]u8' |
test/cases/compile_errors/async/const_frame_cast_to_anyframe.zig created+19| ... | ... | @@ -0,0 +1,19 @@ |
| 1 | export fn a() void { | |
| 2 | const f = async func(); | |
| 3 | resume f; | |
| 4 | } | |
| 5 | export fn b() void { | |
| 6 | const f = async func(); | |
| 7 | var x: anyframe = &f; | |
| 8 | _ = x; | |
| 9 | } | |
| 10 | fn func() void { | |
| 11 | suspend {} | |
| 12 | } | |
| 13 | ||
| 14 | // error | |
| 15 | // backend=stage1 | |
| 16 | // target=native | |
| 17 | // | |
| 18 | // tmp.zig:3:12: error: expected type 'anyframe', found '*const @Frame(func)' | |
| 19 | // tmp.zig:7:24: error: expected type 'anyframe', found '*const @Frame(func)' |
test/cases/compile_errors/async/exported_async_function.zig created+7| ... | ... | @@ -0,0 +1,7 @@ |
| 1 | export fn foo() callconv(.Async) void {} | |
| 2 | ||
| 3 | // error | |
| 4 | // backend=stage1 | |
| 5 | // target=native | |
| 6 | // | |
| 7 | // tmp.zig:1:1: error: exported function cannot be async |
test/cases/compile_errors/async/frame_called_outside_of_function_definition.zig created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | var handle_undef: anyframe = undefined; | |
| 2 | var handle_dummy: anyframe = @frame(); | |
| 3 | export fn entry() bool { | |
| 4 | return handle_undef == handle_dummy; | |
| 5 | } | |
| 6 | ||
| 7 | // error | |
| 8 | // backend=stage1 | |
| 9 | // target=native | |
| 10 | // | |
| 11 | // tmp.zig:2:30: error: @frame() called outside of function definition |
test/cases/compile_errors/async/frame_causes_function_to_be_async.zig created+13| ... | ... | @@ -0,0 +1,13 @@ |
| 1 | export fn entry() void { | |
| 2 | func(); | |
| 3 | } | |
| 4 | fn func() void { | |
| 5 | _ = @frame(); | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage1 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // tmp.zig:1:1: error: function with calling convention 'C' cannot be async | |
| 13 | // tmp.zig:5:9: note: @frame() causes function to be async |
test/cases/compile_errors/async/function_with_ccc_indirectly_calling_async_function.zig created+18| ... | ... | @@ -0,0 +1,18 @@ |
| 1 | export fn entry() void { | |
| 2 | foo(); | |
| 3 | } | |
| 4 | fn foo() void { | |
| 5 | bar(); | |
| 6 | } | |
| 7 | fn bar() void { | |
| 8 | suspend {} | |
| 9 | } | |
| 10 | ||
| 11 | // error | |
| 12 | // backend=stage1 | |
| 13 | // target=native | |
| 14 | // | |
| 15 | // tmp.zig:1:1: error: function with calling convention 'C' cannot be async | |
| 16 | // tmp.zig:2:8: note: async function call here | |
| 17 | // tmp.zig:5:8: note: async function call here | |
| 18 | // tmp.zig:8:5: note: suspends here |
test/cases/compile_errors/async/indirect_recursion_of_async_functions_detected.zig created+36| ... | ... | @@ -0,0 +1,36 @@ |
| 1 | var frame: ?anyframe = null; | |
| 2 | ||
| 3 | export fn a() void { | |
| 4 | _ = async rangeSum(10); | |
| 5 | while (frame) |f| resume f; | |
| 6 | } | |
| 7 | ||
| 8 | fn rangeSum(x: i32) i32 { | |
| 9 | suspend { | |
| 10 | frame = @frame(); | |
| 11 | } | |
| 12 | frame = null; | |
| 13 | ||
| 14 | if (x == 0) return 0; | |
| 15 | var child = rangeSumIndirect(x - 1); | |
| 16 | return child + 1; | |
| 17 | } | |
| 18 | ||
| 19 | fn rangeSumIndirect(x: i32) i32 { | |
| 20 | suspend { | |
| 21 | frame = @frame(); | |
| 22 | } | |
| 23 | frame = null; | |
| 24 | ||
| 25 | if (x == 0) return 0; | |
| 26 | var child = rangeSum(x - 1); | |
| 27 | return child + 1; | |
| 28 | } | |
| 29 | ||
| 30 | // error | |
| 31 | // backend=stage1 | |
| 32 | // target=native | |
| 33 | // | |
| 34 | // tmp.zig:8:1: error: '@Frame(rangeSum)' depends on itself | |
| 35 | // tmp.zig:15:33: note: when analyzing type '@Frame(rangeSum)' here | |
| 36 | // tmp.zig:26:25: note: when analyzing type '@Frame(rangeSumIndirect)' here |
test/cases/compile_errors/async/invalid_suspend_in_exported_function.zig created+15| ... | ... | @@ -0,0 +1,15 @@ |
| 1 | export fn entry() void { | |
| 2 | var frame = async func(); | |
| 3 | var result = await frame; | |
| 4 | _ = result; | |
| 5 | } | |
| 6 | fn func() void { | |
| 7 | suspend {} | |
| 8 | } | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=stage1 | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // tmp.zig:1:1: error: function with calling convention 'C' cannot be async | |
| 15 | // tmp.zig:3:18: note: await here is a suspend point |
test/cases/compile_errors/async/non-async_function_pointer_eventually_is_inferred_to_become_async.zig created+15| ... | ... | @@ -0,0 +1,15 @@ |
| 1 | export fn a() void { | |
| 2 | var non_async_fn: fn () void = undefined; | |
| 3 | non_async_fn = func; | |
| 4 | } | |
| 5 | fn func() void { | |
| 6 | suspend {} | |
| 7 | } | |
| 8 | ||
| 9 | // error | |
| 10 | // backend=stage1 | |
| 11 | // target=native | |
| 12 | // | |
| 13 | // tmp.zig:5:1: error: 'func' cannot be async | |
| 14 | // tmp.zig:3:20: note: required to be non-async here | |
| 15 | // tmp.zig:6:5: note: suspends here |
test/cases/compile_errors/async/non_async_function_pointer_passed_to_asyncCall.zig created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | export fn entry() void { | |
| 2 | var ptr = afunc; | |
| 3 | var bytes: [100]u8 align(16) = undefined; | |
| 4 | _ = @asyncCall(&bytes, {}, ptr, .{}); | |
| 5 | } | |
| 6 | fn afunc() void { } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage1 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // tmp.zig:4:32: error: expected async function, found 'fn() void' |
test/cases/compile_errors/async/prevent_bad_implicit_casting_of_anyframe_types.zig created+24| ... | ... | @@ -0,0 +1,24 @@ |
| 1 | export fn a() void { | |
| 2 | var x: anyframe = undefined; | |
| 3 | var y: anyframe->i32 = x; | |
| 4 | _ = y; | |
| 5 | } | |
| 6 | export fn b() void { | |
| 7 | var x: i32 = undefined; | |
| 8 | var y: anyframe->i32 = x; | |
| 9 | _ = y; | |
| 10 | } | |
| 11 | export fn c() void { | |
| 12 | var x: @Frame(func) = undefined; | |
| 13 | var y: anyframe->i32 = &x; | |
| 14 | _ = y; | |
| 15 | } | |
| 16 | fn func() void {} | |
| 17 | ||
| 18 | // error | |
| 19 | // backend=stage1 | |
| 20 | // target=native | |
| 21 | // | |
| 22 | // :3:28: error: expected type 'anyframe->i32', found 'anyframe' | |
| 23 | // :8:28: error: expected type 'anyframe->i32', found 'i32' | |
| 24 | // tmp.zig:13:29: error: expected type 'anyframe->i32', found '*@Frame(func)' | |
| \ No newline at end of file |
test/cases/compile_errors/async/returning_error_from_void_async_function.zig created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | export fn entry() void { | |
| 2 | _ = async amain(); | |
| 3 | } | |
| 4 | fn amain() callconv(.Async) void { | |
| 5 | return error.ShouldBeCompileError; | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage1 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // tmp.zig:5:17: error: expected type 'void', found 'error{ShouldBeCompileError}' |
test/cases/compile_errors/async/runtime-known_async_function_called.zig created+14| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | export fn entry() void { | |
| 2 | _ = async amain(); | |
| 3 | } | |
| 4 | fn amain() void { | |
| 5 | var ptr = afunc; | |
| 6 | _ = ptr(); | |
| 7 | } | |
| 8 | fn afunc() callconv(.Async) void {} | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=stage1 | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // tmp.zig:6:12: error: function is not comptime-known; @asyncCall required |
test/cases/compile_errors/async/runtime-known_function_called_with_async_keyword.zig created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | export fn entry() void { | |
| 2 | var ptr = afunc; | |
| 3 | _ = async ptr(); | |
| 4 | } | |
| 5 | ||
| 6 | fn afunc() callconv(.Async) void { } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage1 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // tmp.zig:3:15: error: function is not comptime-known; @asyncCall required |
test/cases/compile_errors/async/wrong_frame_type_used_for_async_call.zig created+16| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | export fn entry() void { | |
| 2 | var frame: @Frame(foo) = undefined; | |
| 3 | frame = async bar(); | |
| 4 | } | |
| 5 | fn foo() void { | |
| 6 | suspend {} | |
| 7 | } | |
| 8 | fn bar() void { | |
| 9 | suspend {} | |
| 10 | } | |
| 11 | ||
| 12 | // error | |
| 13 | // backend=stage1 | |
| 14 | // target=native | |
| 15 | // | |
| 16 | // tmp.zig:3:13: error: expected type '*@Frame(bar)', found '*@Frame(foo)' |
test/cases/compile_errors/async/wrong_type_for_argument_tuple_to_asyncCall.zig created+14| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | export fn entry1() void { | |
| 2 | var frame: @Frame(foo) = undefined; | |
| 3 | @asyncCall(&frame, {}, foo, {}); | |
| 4 | } | |
| 5 | ||
| 6 | fn foo() i32 { | |
| 7 | return 0; | |
| 8 | } | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=stage1 | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // tmp.zig:3:33: error: expected tuple or struct, found 'void' |
test/cases/compile_errors/async/wrong_type_for_result_ptr_to_asyncCall.zig created+16| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | export fn entry() void { | |
| 2 | _ = async amain(); | |
| 3 | } | |
| 4 | fn amain() i32 { | |
| 5 | var frame: @Frame(foo) = undefined; | |
| 6 | return await @asyncCall(&frame, false, foo, .{}); | |
| 7 | } | |
| 8 | fn foo() i32 { | |
| 9 | return 1234; | |
| 10 | } | |
| 11 | ||
| 12 | // error | |
| 13 | // backend=stage1 | |
| 14 | // target=native | |
| 15 | // | |
| 16 | // tmp.zig:6:37: error: expected type '*i32', found 'bool' |
test/cases/compile_errors/bad_alignment_in_implicit_cast_from_array_pointer_to_slice.zig created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | export fn a() void { | |
| 2 | var x: [10]u8 = undefined; | |
| 3 | var y: []align(16) u8 = &x; | |
| 4 | _ = y; | |
| 5 | } | |
| 6 | ||
| 7 | // error | |
| 8 | // backend=stage2 | |
| 9 | // target=native | |
| 10 | // | |
| 11 | // :3:29: error: expected type '[]align(16) u8', found '*[10]u8' | |
| 12 | // :3:29: note: pointer alignment '1' cannot cast into pointer alignment '16' |
test/cases/compile_errors/bad_alignment_type.zig created+15| ... | ... | @@ -0,0 +1,15 @@ |
| 1 | export fn entry1() void { | |
| 2 | var x: []align(true) i32 = undefined; | |
| 3 | _ = x; | |
| 4 | } | |
| 5 | export fn entry2() void { | |
| 6 | var x: *align(@as(f64, 12.34)) i32 = undefined; | |
| 7 | _ = x; | |
| 8 | } | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=stage2 | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // :2:20: error: expected type 'u32', found 'bool' | |
| 15 | // :6:19: error: fractional component prevents float value '12.34' from coercion to type 'u32' |
test/cases/compile_errors/cImport_with_bogus_include.zig created+9| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | const c = @cImport(@cInclude("bogus.h")); | |
| 2 | export fn entry() usize { return @sizeOf(@TypeOf(c.bogo)); } | |
| 3 | ||
| 4 | // error | |
| 5 | // backend=llvm | |
| 6 | // target=native | |
| 7 | // | |
| 8 | // :1:11: error: C import failed | |
| 9 | // :1:10: error: 'bogus.h' file not found |
test/cases/compile_errors/compare_optional_to_non-optional_with_invalid_types.zig created+37| ... | ... | @@ -0,0 +1,37 @@ |
| 1 | export fn inconsistentChildType() void { | |
| 2 | var x: ?i32 = undefined; | |
| 3 | const y: comptime_int = 10; | |
| 4 | _ = (x == y); | |
| 5 | } | |
| 6 | export fn optionalToOptional() void { | |
| 7 | var x: ?i32 = undefined; | |
| 8 | var y: ?i32 = undefined; | |
| 9 | _ = (x == y); | |
| 10 | } | |
| 11 | export fn optionalVector() void { | |
| 12 | var x: ?@Vector(10, i32) = undefined; | |
| 13 | var y: @Vector(10, i32) = undefined; | |
| 14 | _ = (x == y); | |
| 15 | } | |
| 16 | export fn optionalVector2() void { | |
| 17 | var x: ?@Vector(10, i32) = undefined; | |
| 18 | var y: @Vector(11, i32) = undefined; | |
| 19 | _ = (x == y); | |
| 20 | } | |
| 21 | export fn invalidChildType() void { | |
| 22 | var x: ?[3]i32 = undefined; | |
| 23 | var y: [3]i32 = undefined; | |
| 24 | _ = (x == y); | |
| 25 | } | |
| 26 | ||
| 27 | // error | |
| 28 | // backend=llvm | |
| 29 | // target=native | |
| 30 | // | |
| 31 | // :4:12: error: incompatible types: '?i32' and 'comptime_int' | |
| 32 | // :4:10: note: type '?i32' here | |
| 33 | // :4:15: note: type 'comptime_int' here | |
| 34 | // :19:12: error: incompatible types: '?@Vector(10, i32)' and '@Vector(11, i32)' | |
| 35 | // :19:10: note: type '?@Vector(10, i32)' here | |
| 36 | // :19:15: note: type '@Vector(11, i32)' here | |
| 37 | // :24:12: error: operator == not allowed for type '?[3]i32' |
test/cases/compile_errors/comptime_implicit_cast_f64_to_f32.zig created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | export fn entry() void { | |
| 2 | const x: f64 = 16777217; | |
| 3 | const y: f32 = x; | |
| 4 | _ = y; | |
| 5 | } | |
| 6 | ||
| 7 | // error | |
| 8 | // backend=stage2 | |
| 9 | // target=native | |
| 10 | // | |
| 11 | // :3:20: error: type 'f32' cannot represent float value '16777217' |
test/cases/compile_errors/comptime_unreachable.zig created+9| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | pub export fn entry() void { | |
| 2 | comptime unreachable; | |
| 3 | } | |
| 4 | ||
| 5 | // error | |
| 6 | // target=native | |
| 7 | // backend=stage2 | |
| 8 | // | |
| 9 | // :2:14: error: reached unreachable code |
test/cases/compile_errors/constant_inside_comptime_function_has_compile_error.zig created+21| ... | ... | @@ -0,0 +1,21 @@ |
| 1 | const ContextAllocator = MemoryPool(usize); | |
| 2 | ||
| 3 | pub fn MemoryPool(comptime T: type) type { | |
| 4 | const free_list_t = @compileError("aoeu",); | |
| 5 | _ = T; | |
| 6 | ||
| 7 | return struct { | |
| 8 | free_list: free_list_t, | |
| 9 | }; | |
| 10 | } | |
| 11 | ||
| 12 | export fn entry() void { | |
| 13 | var allocator: ContextAllocator = undefined; | |
| 14 | _ = allocator; | |
| 15 | } | |
| 16 | ||
| 17 | // error | |
| 18 | // target=native | |
| 19 | // | |
| 20 | // :4:5: error: unreachable code | |
| 21 | // :4:25: note: control flow is diverted here |
test/cases/compile_errors/duplicate-unused_labels.zig created+31| ... | ... | @@ -0,0 +1,31 @@ |
| 1 | comptime { | |
| 2 | blk: { blk: while (false) {} } | |
| 3 | } | |
| 4 | comptime { | |
| 5 | blk: while (false) { blk: for (@as([0]void, undefined)) |_| {} } | |
| 6 | } | |
| 7 | comptime { | |
| 8 | blk: for (@as([0]void, undefined)) |_| { blk: {} } | |
| 9 | } | |
| 10 | comptime { | |
| 11 | blk: {} | |
| 12 | } | |
| 13 | comptime { | |
| 14 | blk: while(false) {} | |
| 15 | } | |
| 16 | comptime { | |
| 17 | blk: for(@as([0]void, undefined)) |_| {} | |
| 18 | } | |
| 19 | ||
| 20 | // error | |
| 21 | // target=native | |
| 22 | // | |
| 23 | // :2:12: error: redefinition of label 'blk' | |
| 24 | // :2:5: note: previous definition here | |
| 25 | // :5:26: error: redefinition of label 'blk' | |
| 26 | // :5:5: note: previous definition here | |
| 27 | // :8:46: error: redefinition of label 'blk' | |
| 28 | // :8:5: note: previous definition here | |
| 29 | // :11:5: error: unused block label | |
| 30 | // :14:5: error: unused while loop label | |
| 31 | // :17:5: error: unused for loop label |
test/cases/compile_errors/embed_outside_package.zig created+8| ... | ... | @@ -0,0 +1,8 @@ |
| 1 | export fn a() usize { | |
| 2 | return @embedFile("/root/foo").len; | |
| 3 | } | |
| 4 | ||
| 5 | // error | |
| 6 | // target=native | |
| 7 | // | |
| 8 | //:2:23: error: embed of file outside package path: '/root/foo' |
test/cases/compile_errors/error_when_evaluating_return_type.zig created+17| ... | ... | @@ -0,0 +1,17 @@ |
| 1 | const Foo = struct { | |
| 2 | map: @as(i32, i32), | |
| 3 | ||
| 4 | fn init() Foo { | |
| 5 | return undefined; | |
| 6 | } | |
| 7 | }; | |
| 8 | export fn entry() void { | |
| 9 | var rule_set = try Foo.init(); | |
| 10 | _ = rule_set; | |
| 11 | } | |
| 12 | ||
| 13 | // error | |
| 14 | // backend=stage2 | |
| 15 | // target=native | |
| 16 | // | |
| 17 | // :2:19: error: expected type 'i32', found 'type' |
test/cases/compile_errors/extern_function_pointer_mismatch.zig created+13| ... | ... | @@ -0,0 +1,13 @@ |
| 1 | const fns = [_](fn(i32)i32) { a, b, c }; | |
| 2 | pub fn a(x: i32) i32 {return x + 0;} | |
| 3 | pub fn b(x: i32) i32 {return x + 1;} | |
| 4 | export fn c(x: i32) i32 {return x + 2;} | |
| 5 | ||
| 6 | export fn entry() usize { return @sizeOf(@TypeOf(fns)); } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage2 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // :1:37: error: expected type 'fn(i32) i32', found 'fn(i32) callconv(.C) i32' | |
| 13 | // :1:37: note: calling convention 'C' cannot cast into calling convention 'Unspecified' |
test/cases/compile_errors/floatToInt_comptime_safety.zig created+17| ... | ... | @@ -0,0 +1,17 @@ |
| 1 | comptime { | |
| 2 | _ = @floatToInt(i8, @as(f32, -129.1)); | |
| 3 | } | |
| 4 | comptime { | |
| 5 | _ = @floatToInt(u8, @as(f32, -1.1)); | |
| 6 | } | |
| 7 | comptime { | |
| 8 | _ = @floatToInt(u8, @as(f32, 256.1)); | |
| 9 | } | |
| 10 | ||
| 11 | // error | |
| 12 | // backend=stage2 | |
| 13 | // target=native | |
| 14 | // | |
| 15 | // :2:25: error: float value '-129.10000610351562' cannot be stored in integer type 'i8' | |
| 16 | // :5:25: error: float value '-1.100000023841858' cannot be stored in integer type 'u8' | |
| 17 | // :8:25: error: float value '256.1000061035156' cannot be stored in integer type 'u8' |
test/cases/compile_errors/implicit_casting_null_c_pointer_to_zig_pointer.zig created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | comptime { | |
| 2 | var c_ptr: [*c]u8 = 0; | |
| 3 | var zig_ptr: *u8 = c_ptr; | |
| 4 | _ = zig_ptr; | |
| 5 | } | |
| 6 | ||
| 7 | // error | |
| 8 | // backend=stage2 | |
| 9 | // target=native | |
| 10 | // | |
| 11 | // :3:24: error: null pointer casted to type '*u8' |
test/cases/compile_errors/implicit_dependency_on_libc.zig created+10| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | extern "c" fn exit(u8) void; | |
| 2 | export fn entry() void { | |
| 3 | exit(0); | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage2 | |
| 8 | // target=native-linux | |
| 9 | // | |
| 10 | // :1:8: error: dependency on libc must be explicitly specified in the build command |
test/cases/compile_errors/import_outside_package.zig created+8| ... | ... | @@ -0,0 +1,8 @@ |
| 1 | export fn a() usize { | |
| 2 | return @import("../../above.zig").len; | |
| 3 | } | |
| 4 | ||
| 5 | // error | |
| 6 | // target=native | |
| 7 | // | |
| 8 | // :2:20: error: import of file outside package path: '../../above.zig' |
test/cases/compile_errors/indexing_a_undefined_slice_at_comptime.zig created+10| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | comptime { | |
| 2 | var slice: []u8 = undefined; | |
| 3 | slice[0] = 2; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage2 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // :3:10: error: use of undefined value here causes undefined behavior |
test/cases/compile_errors/integer_cast_truncates_bits.zig created+31| ... | ... | @@ -0,0 +1,31 @@ |
| 1 | export fn entry1() void { | |
| 2 | const spartan_count: u16 = 300; | |
| 3 | const byte = @intCast(u8, spartan_count); | |
| 4 | _ = byte; | |
| 5 | } | |
| 6 | export fn entry2() void { | |
| 7 | const spartan_count: u16 = 300; | |
| 8 | const byte: u8 = spartan_count; | |
| 9 | _ = byte; | |
| 10 | } | |
| 11 | export fn entry3() void { | |
| 12 | var spartan_count: u16 = 300; | |
| 13 | var byte: u8 = spartan_count; | |
| 14 | _ = byte; | |
| 15 | } | |
| 16 | export fn entry4() void { | |
| 17 | var signed: i8 = -1; | |
| 18 | var unsigned: u64 = signed; | |
| 19 | _ = unsigned; | |
| 20 | } | |
| 21 | ||
| 22 | // error | |
| 23 | // backend=stage2 | |
| 24 | // target=native | |
| 25 | // | |
| 26 | // :3:31: error: type 'u8' cannot represent integer value '300' | |
| 27 | // :8:22: error: type 'u8' cannot represent integer value '300' | |
| 28 | // :13:20: error: expected type 'u8', found 'u16' | |
| 29 | // :13:20: note: unsigned 8-bit int cannot represent all possible unsigned 16-bit values | |
| 30 | // :18:25: error: expected type 'u64', found 'i8' | |
| 31 | // :18:25: note: unsigned 64-bit int cannot represent all possible signed 8-bit values |
test/cases/compile_errors/issue_4207_coerce_from_non-terminated-slice_to_terminated-pointer.zig created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | export fn foo() [*:0]const u8 { | |
| 2 | var buffer: [64]u8 = undefined; | |
| 3 | return buffer[0..]; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage2 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // :3:18: error: expected type '[*:0]const u8', found '*[64]u8' | |
| 11 | // :3:18: note: destination pointer requires '0' sentinel | |
| 12 | // :1:18: note: function return type declared here |
test/cases/compile_errors/issue_7810-comptime_slice-len_increment_beyond_bounds.zig created+14| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | export fn foo_slice_len_increment_beyond_bounds() void { | |
| 2 | comptime { | |
| 3 | var buf_storage: [8]u8 = undefined; | |
| 4 | var buf: []u8 = buf_storage[0..]; | |
| 5 | buf.len += 1; | |
| 6 | buf[8] = 42; | |
| 7 | } | |
| 8 | } | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=stage2 | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // :6:16: error: comptime store of index 8 out of bounds of array length 8 |
test/cases/compile_errors/lazy_pointer_with_undefined_element_type.zig created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | export fn foo() void { | |
| 2 | comptime var T: type = undefined; | |
| 3 | const S = struct { x: *T }; | |
| 4 | const I = @typeInfo(S); | |
| 5 | _ = I; | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage2 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // :3:28: error: use of undefined value here causes undefined behavior |
test/cases/compile_errors/missing_main_fn_in_executable.zig created+9| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | ||
| 2 | ||
| 3 | // error | |
| 4 | // backend=llvm | |
| 5 | // target=x86_64-linux | |
| 6 | // output_mode=Exe | |
| 7 | // | |
| 8 | // :?:?: error: root struct of file 'tmp' has no member named 'main' | |
| 9 | // :?:?: note: called from here |
test/cases/compile_errors/missing_result_type_for_phi_node.zig created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | fn foo() !void { | |
| 2 | return anyerror.Foo; | |
| 3 | } | |
| 4 | export fn entry() void { | |
| 5 | foo() catch 0; | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage2 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // :5:11: error: incompatible types: 'void' and 'comptime_int' |
test/cases/compile_errors/noalias_on_non_pointer_param.zig created+8| ... | ... | @@ -0,0 +1,8 @@ |
| 1 | fn f(noalias x: i32) void { _ = x; } | |
| 2 | export fn entry() void { f(1234); } | |
| 3 | ||
| 4 | // error | |
| 5 | // backend=stage2 | |
| 6 | // target=native | |
| 7 | // | |
| 8 | // :1:6: error: non-pointer parameter declared noalias |
test/cases/compile_errors/out_of_bounds_index.zig created+29| ... | ... | @@ -0,0 +1,29 @@ |
| 1 | comptime { | |
| 2 | var array = [_:0]u8{ 1, 2, 3, 4 }; | |
| 3 | var src_slice: [:0]u8 = &array; | |
| 4 | var slice = src_slice[2..6]; | |
| 5 | _ = slice; | |
| 6 | } | |
| 7 | comptime { | |
| 8 | var array = [_:0]u8{ 1, 2, 3, 4 }; | |
| 9 | var slice = array[2..6]; | |
| 10 | _ = slice; | |
| 11 | } | |
| 12 | comptime { | |
| 13 | var array = [_]u8{ 1, 2, 3, 4 }; | |
| 14 | var slice = array[2..5]; | |
| 15 | _ = slice; | |
| 16 | } | |
| 17 | comptime { | |
| 18 | var array = [_:0]u8{ 1, 2, 3, 4 }; | |
| 19 | var slice = array[3..2]; | |
| 20 | _ = slice; | |
| 21 | } | |
| 22 | ||
| 23 | // error | |
| 24 | // target=native | |
| 25 | // | |
| 26 | // :4:30: error: end index 6 out of bounds for slice of length 4 +1 (sentinel) | |
| 27 | // :9:26: error: end index 6 out of bounds for array of length 4 +1 (sentinel) | |
| 28 | // :14:26: error: end index 5 out of bounds for array of length 4 | |
| 29 | // :19:23: error: start index 3 is larger than end index 2 |
test/cases/compile_errors/passing_an_under-aligned_function_pointer.zig created+14| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | export fn entry() void { | |
| 2 | testImplicitlyDecreaseFnAlign(alignedSmall, 1234); | |
| 3 | } | |
| 4 | fn testImplicitlyDecreaseFnAlign(ptr: *const fn () align(8) i32, answer: i32) void { | |
| 5 | if (ptr() != answer) unreachable; | |
| 6 | } | |
| 7 | fn alignedSmall() align(4) i32 { return 1234; } | |
| 8 | ||
| 9 | // error | |
| 10 | // backend=stage2 | |
| 11 | // target=x86_64-linux | |
| 12 | // | |
| 13 | // :2:35: error: expected type '*const fn() align(8) i32', found '*const fn() align(4) i32' | |
| 14 | // :2:35: note: pointer alignment '4' cannot cast into pointer alignment '8' |
test/cases/compile_errors/private_main_fn.zig created+10| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | fn main() void {} | |
| 2 | ||
| 3 | // error | |
| 4 | // backend=llvm | |
| 5 | // target=x86_64-linux | |
| 6 | // output_mode=Exe | |
| 7 | // | |
| 8 | // :?:?: error: 'main' is not marked 'pub' | |
| 9 | // :1:1: note: declared here | |
| 10 | // :?:?: note: called from here |
test/cases/compile_errors/reified_enum_field_value_overflow.zig created+20| ... | ... | @@ -0,0 +1,20 @@ |
| 1 | comptime { | |
| 2 | const E = @Type(.{ .Enum = .{ | |
| 3 | .layout = .Auto, | |
| 4 | .tag_type = u1, | |
| 5 | .fields = &.{ | |
| 6 | .{ .name = "f0", .value = 0 }, | |
| 7 | .{ .name = "f1", .value = 1 }, | |
| 8 | .{ .name = "f2", .value = 2 }, | |
| 9 | }, | |
| 10 | .decls = &.{}, | |
| 11 | .is_exhaustive = true, | |
| 12 | } }); | |
| 13 | _ = E; | |
| 14 | } | |
| 15 | ||
| 16 | // error | |
| 17 | // target=native | |
| 18 | // backend=stage2 | |
| 19 | // | |
| 20 | // :2:15: error: field 'f2' with enumeration value '2' is too large for backing int type 'u1' |
test/cases/compile_errors/reify_type_for_union_with_opaque_field.zig created+20| ... | ... | @@ -0,0 +1,20 @@ |
| 1 | const Untagged = @Type(.{ | |
| 2 | .Union = .{ | |
| 3 | .layout = .Auto, | |
| 4 | .tag_type = null, | |
| 5 | .fields = &.{ | |
| 6 | .{ .name = "foo", .field_type = opaque {}, .alignment = 1 }, | |
| 7 | }, | |
| 8 | .decls = &.{}, | |
| 9 | }, | |
| 10 | }); | |
| 11 | export fn entry() usize { | |
| 12 | return @sizeOf(Untagged); | |
| 13 | } | |
| 14 | ||
| 15 | // error | |
| 16 | // backend=stage2 | |
| 17 | // target=native | |
| 18 | // | |
| 19 | // :1:18: error: opaque types have unknown size and therefore cannot be directly embedded in unions | |
| 20 | // :6:45: note: opaque declared here |
test/cases/compile_errors/runtime_assignment_to_comptime_struct_type.zig created+16| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | const Foo = struct { | |
| 2 | Bar: u8, | |
| 3 | Baz: type, | |
| 4 | }; | |
| 5 | export fn f() void { | |
| 6 | var x: u8 = 0; | |
| 7 | const foo = Foo { .Bar = x, .Baz = u8 }; | |
| 8 | _ = foo; | |
| 9 | } | |
| 10 | ||
| 11 | // error | |
| 12 | // backend=stage2 | |
| 13 | // target=native | |
| 14 | // | |
| 15 | // :7:30: error: unable to resolve comptime value | |
| 16 | // :7:30: note: initializer of comptime only struct must be comptime-known |
test/cases/compile_errors/runtime_assignment_to_comptime_union_type.zig created+16| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | const Foo = union { | |
| 2 | Bar: u8, | |
| 3 | Baz: type, | |
| 4 | }; | |
| 5 | export fn f() void { | |
| 6 | var x: u8 = 0; | |
| 7 | const foo = Foo { .Bar = x }; | |
| 8 | _ = foo; | |
| 9 | } | |
| 10 | ||
| 11 | // error | |
| 12 | // backend=stage2 | |
| 13 | // target=native | |
| 14 | // | |
| 15 | // :7:30: error: unable to resolve comptime value | |
| 16 | // :7:30: note: initializer of comptime only union must be comptime-known |
test/cases/compile_errors/saturating_shl_assign_does_not_allow_negative_rhs_at_comptime.zig created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | export fn a() void { | |
| 2 | comptime { | |
| 3 | var x = @as(i32, 1); | |
| 4 | x <<|= @as(i32, -2); | |
| 5 | } | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage2 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // :4:14: error: shift by negative amount '-2' |
test/cases/compile_errors/saturating_shl_does_not_allow_negative_rhs_at_comptime.zig created+9| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | export fn a() void { | |
| 2 | _ = @as(i32, 1) <<| @as(i32, -2); | |
| 3 | } | |
| 4 | ||
| 5 | // error | |
| 6 | // backend=stage2 | |
| 7 | // target=native | |
| 8 | // | |
| 9 | // :2:25: error: shift by negative amount '-2' |
test/cases/compile_errors/shift_amount_has_to_be_an_integer_type.zig created+10| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | export fn entry() void { | |
| 2 | const x = 1 << &@as(u8, 10); | |
| 3 | _ = x; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage2 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // :2:20: error: expected type 'comptime_int', found '*const u8' |
test/cases/compile_errors/shift_by_negative_comptime_integer.zig created+10| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | comptime { | |
| 2 | var a = 1 >> -1; | |
| 3 | _ = a; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage2 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // :2:18: error: shift by negative amount '-1' |
test/cases/compile_errors/slice_of_null_pointer.zig created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | comptime { | |
| 2 | var x: [*c]u8 = null; | |
| 3 | var runtime_len: usize = 0; | |
| 4 | var y = x[0..runtime_len]; | |
| 5 | _ = y; | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // target=native | |
| 10 | // | |
| 11 | // :4:14: error: slice of null pointer |
test/cases/compile_errors/slice_sentinel_mismatch-1.zig created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | export fn entry() void { | |
| 2 | const y: [:1]const u8 = &[_:2]u8{ 1, 2 }; | |
| 3 | _ = y; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage2 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // :2:29: error: expected type '[:1]const u8', found '*const [2:2]u8' | |
| 11 | // :2:29: note: pointer sentinel '2' cannot cast into pointer sentinel '1' |
test/cases/compile_errors/stage1/exe/missing_main_fn_in_executable.zig deleted-8| ... | ... | @@ -1,8 +0,0 @@ |
| 1 | ||
| 2 | ||
| 3 | // error | |
| 4 | // backend=stage1 | |
| 5 | // target=native | |
| 6 | // output_mode=Exe | |
| 7 | // | |
| 8 | // error: root source file has no member called 'main' |
test/cases/compile_errors/stage1/exe/private_main_fn.zig deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | fn main() void {} | |
| 2 | ||
| 3 | // error | |
| 4 | // backend=stage1 | |
| 5 | // target=native | |
| 6 | // output_mode=Exe | |
| 7 | // | |
| 8 | // error: 'main' is private | |
| 9 | // tmp.zig:1:1: note: declared here |
test/cases/compile_errors/stage1/obj/Frame_of_generic_function.zig deleted-14| ... | ... | @@ -1,14 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | var frame: @Frame(func) = undefined; | |
| 3 | _ = frame; | |
| 4 | } | |
| 5 | fn func(comptime T: type) void { | |
| 6 | var x: T = undefined; | |
| 7 | _ = x; | |
| 8 | } | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=stage1 | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // tmp.zig:2:16: error: @Frame() of generic function |
test/cases/compile_errors/stage1/obj/Issue_9165_windows_tcp_server_compilation_error.zig deleted-16| ... | ... | @@ -1,16 +0,0 @@ |
| 1 | const std = @import("std"); | |
| 2 | const builtin = @import("builtin"); | |
| 3 | pub const io_mode = .evented; | |
| 4 | pub fn main() !void { | |
| 5 | if (builtin.os.tag == .windows) { | |
| 6 | _ = try (std.net.StreamServer.init(.{})).accept(); | |
| 7 | } else { | |
| 8 | @compileError("Unsupported OS"); | |
| 9 | } | |
| 10 | } | |
| 11 | ||
| 12 | // error | |
| 13 | // backend=stage1 | |
| 14 | // target=native | |
| 15 | // | |
| 16 | // error: Unsupported OS |
test/cases/compile_errors/stage1/obj/async_function_depends_on_its_own_frame.zig deleted-13| ... | ... | @@ -1,13 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | _ = async amain(); | |
| 3 | } | |
| 4 | fn amain() callconv(.Async) void { | |
| 5 | var x: [@sizeOf(@Frame(amain))]u8 = undefined; | |
| 6 | _ = x; | |
| 7 | } | |
| 8 | ||
| 9 | // error | |
| 10 | // backend=stage1 | |
| 11 | // target=native | |
| 12 | // | |
| 13 | // tmp.zig:4:1: error: cannot resolve '@Frame(amain)': function not fully analyzed yet |
test/cases/compile_errors/stage1/obj/async_function_indirectly_depends_on_its_own_frame.zig deleted-17| ... | ... | @@ -1,17 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | _ = async amain(); | |
| 3 | } | |
| 4 | fn amain() callconv(.Async) void { | |
| 5 | other(); | |
| 6 | } | |
| 7 | fn other() void { | |
| 8 | var x: [@sizeOf(@Frame(amain))]u8 = undefined; | |
| 9 | _ = x; | |
| 10 | } | |
| 11 | ||
| 12 | // error | |
| 13 | // backend=stage1 | |
| 14 | // target=native | |
| 15 | // | |
| 16 | // tmp.zig:4:1: error: unable to determine async function frame of 'amain' | |
| 17 | // tmp.zig:5:10: note: analysis of function 'other' depends on the frame |
test/cases/compile_errors/stage1/obj/bad_alignment_in_asynccall.zig deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | var ptr: fn () callconv(.Async) void = func; | |
| 3 | var bytes: [64]u8 = undefined; | |
| 4 | _ = @asyncCall(&bytes, {}, ptr, .{}); | |
| 5 | } | |
| 6 | fn func() callconv(.Async) void {} | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage1 | |
| 10 | // target=aarch64-linux-none | |
| 11 | // | |
| 12 | // tmp.zig:4:21: error: expected type '[]align(8) u8', found '*[64]u8' |
test/cases/compile_errors/stage1/obj/bad_alignment_in_implicit_cast_from_array_pointer_to_slice.zig deleted-11| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | export fn a() void { | |
| 2 | var x: [10]u8 = undefined; | |
| 3 | var y: []align(16) u8 = &x; | |
| 4 | _ = y; | |
| 5 | } | |
| 6 | ||
| 7 | // error | |
| 8 | // backend=stage1 | |
| 9 | // target=native | |
| 10 | // | |
| 11 | // tmp.zig:3:30: error: expected type '[]align(16) u8', found '*[10]u8' |
test/cases/compile_errors/stage1/obj/bad_alignment_type.zig deleted-15| ... | ... | @@ -1,15 +0,0 @@ |
| 1 | export fn entry1() void { | |
| 2 | var x: []align(true) i32 = undefined; | |
| 3 | _ = x; | |
| 4 | } | |
| 5 | export fn entry2() void { | |
| 6 | var x: *align(@as(f64, 12.34)) i32 = undefined; | |
| 7 | _ = x; | |
| 8 | } | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=stage1 | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // tmp.zig:2:20: error: expected type 'u29', found 'bool' | |
| 15 | // tmp.zig:6:19: error: fractional component prevents float value 12.340000 from being casted to type 'u29' |
test/cases/compile_errors/stage1/obj/cImport_with_bogus_include.zig deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | const c = @cImport(@cInclude("bogus.h")); | |
| 2 | export fn entry() usize { return @sizeOf(@TypeOf(c.bogo)); } | |
| 3 | ||
| 4 | // error | |
| 5 | // backend=stage1 | |
| 6 | // target=native | |
| 7 | // | |
| 8 | // tmp.zig:1:11: error: C import failed | |
| 9 | // .h:1:10: note: 'bogus.h' file not found |
test/cases/compile_errors/stage1/obj/calling_a_generic_function_only_known_at_runtime.zig deleted-14| ... | ... | @@ -1,14 +0,0 @@ |
| 1 | var foos = [_]fn(anytype) void { foo1, foo2 }; | |
| 2 | ||
| 3 | fn foo1(arg: anytype) void {_ = arg;} | |
| 4 | fn foo2(arg: anytype) void {_ = arg;} | |
| 5 | ||
| 6 | pub fn main() !void { | |
| 7 | foos[0](true); | |
| 8 | } | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=stage1 | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // tmp.zig:7:9: error: calling a generic function requires compile-time known function value |
test/cases/compile_errors/stage1/obj/compare_optional_to_non-optional_with_invalid_types.zig deleted-35| ... | ... | @@ -1,35 +0,0 @@ |
| 1 | export fn inconsistentChildType() void { | |
| 2 | var x: ?i32 = undefined; | |
| 3 | const y: comptime_int = 10; | |
| 4 | _ = (x == y); | |
| 5 | } | |
| 6 | ||
| 7 | export fn optionalToOptional() void { | |
| 8 | var x: ?i32 = undefined; | |
| 9 | var y: ?i32 = undefined; | |
| 10 | _ = (x == y); | |
| 11 | } | |
| 12 | ||
| 13 | export fn optionalVector() void { | |
| 14 | var x: ?@Vector(10, i32) = undefined; | |
| 15 | var y: @Vector(10, i32) = undefined; | |
| 16 | _ = (x == y); | |
| 17 | } | |
| 18 | ||
| 19 | export fn invalidChildType() void { | |
| 20 | var x: ?[3]i32 = undefined; | |
| 21 | var y: [3]i32 = undefined; | |
| 22 | _ = (x == y); | |
| 23 | } | |
| 24 | ||
| 25 | // error | |
| 26 | // backend=stage1 | |
| 27 | // target=native | |
| 28 | // | |
| 29 | // :4:12: error: cannot compare types '?i32' and 'comptime_int' | |
| 30 | // :4:12: note: optional child type 'i32' must be the same as non-optional type 'comptime_int' | |
| 31 | // :10:12: error: cannot compare types '?i32' and '?i32' | |
| 32 | // :10:12: note: optional to optional comparison is only supported for optional pointer types | |
| 33 | // :16:12: error: TODO add comparison of optional vector | |
| 34 | // :22:12: error: cannot compare types '?[3]i32' and '[3]i32' | |
| 35 | // :22:12: note: operator not supported for type '[3]i32' |
test/cases/compile_errors/stage1/obj/comptime_float_in_asm_input.zig deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | export fn foo() void { | |
| 2 | asm volatile ("" : : [bar]"r"(3.17) : ""); | |
| 3 | } | |
| 4 | ||
| 5 | // error | |
| 6 | // backend=stage1 | |
| 7 | // target=native | |
| 8 | // | |
| 9 | // tmp.zig:2:35: error: expected sized integer or sized float, found comptime_float |
test/cases/compile_errors/stage1/obj/comptime_implicit_cast_f64_to_f32.zig deleted-11| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | const x: f64 = 16777217; | |
| 3 | const y: f32 = x; | |
| 4 | _ = y; | |
| 5 | } | |
| 6 | ||
| 7 | // error | |
| 8 | // backend=stage1 | |
| 9 | // target=native | |
| 10 | // | |
| 11 | // tmp.zig:3:20: error: cast of value 16777217.000000 to type 'f32' loses information |
test/cases/compile_errors/stage1/obj/comptime_int_in_asm_input.zig deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | export fn foo() void { | |
| 2 | asm volatile ("" : : [bar]"r"(3) : ""); | |
| 3 | } | |
| 4 | ||
| 5 | // error | |
| 6 | // backend=stage1 | |
| 7 | // target=native | |
| 8 | // | |
| 9 | // tmp.zig:2:35: error: expected sized integer or sized float, found comptime_int |
test/cases/compile_errors/stage1/obj/const_frame_cast_to_anyframe.zig deleted-19| ... | ... | @@ -1,19 +0,0 @@ |
| 1 | export fn a() void { | |
| 2 | const f = async func(); | |
| 3 | resume f; | |
| 4 | } | |
| 5 | export fn b() void { | |
| 6 | const f = async func(); | |
| 7 | var x: anyframe = &f; | |
| 8 | _ = x; | |
| 9 | } | |
| 10 | fn func() void { | |
| 11 | suspend {} | |
| 12 | } | |
| 13 | ||
| 14 | // error | |
| 15 | // backend=stage1 | |
| 16 | // target=native | |
| 17 | // | |
| 18 | // tmp.zig:3:12: error: expected type 'anyframe', found '*const @Frame(func)' | |
| 19 | // tmp.zig:7:24: error: expected type 'anyframe', found '*const @Frame(func)' |
test/cases/compile_errors/stage1/obj/double_optional_on_main_return_value.zig deleted-8| ... | ... | @@ -1,8 +0,0 @@ |
| 1 | pub fn main() ??void { | |
| 2 | } | |
| 3 | ||
| 4 | // error | |
| 5 | // backend=stage1 | |
| 6 | // target=native | |
| 7 | // | |
| 8 | // error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8' |
test/cases/compile_errors/stage1/obj/error_when_evaluating_return_type.zig deleted-17| ... | ... | @@ -1,17 +0,0 @@ |
| 1 | const Foo = struct { | |
| 2 | map: @as(i32, i32), | |
| 3 | ||
| 4 | fn init() Foo { | |
| 5 | return undefined; | |
| 6 | } | |
| 7 | }; | |
| 8 | export fn entry() void { | |
| 9 | var rule_set = try Foo.init(); | |
| 10 | _ = rule_set; | |
| 11 | } | |
| 12 | ||
| 13 | // error | |
| 14 | // backend=stage1 | |
| 15 | // target=native | |
| 16 | // | |
| 17 | // tmp.zig:2:19: error: expected type 'i32', found 'type' |
test/cases/compile_errors/stage1/obj/exported_async_function.zig deleted-7| ... | ... | @@ -1,7 +0,0 @@ |
| 1 | export fn foo() callconv(.Async) void {} | |
| 2 | ||
| 3 | // error | |
| 4 | // backend=stage1 | |
| 5 | // target=native | |
| 6 | // | |
| 7 | // tmp.zig:1:1: error: exported function cannot be async |
test/cases/compile_errors/stage1/obj/extern_function_pointer_mismatch.zig deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | const fns = [_](fn(i32)i32) { a, b, c }; | |
| 2 | pub fn a(x: i32) i32 {return x + 0;} | |
| 3 | pub fn b(x: i32) i32 {return x + 1;} | |
| 4 | export fn c(x: i32) i32 {return x + 2;} | |
| 5 | ||
| 6 | export fn entry() usize { return @sizeOf(@TypeOf(fns)); } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage1 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // tmp.zig:1:37: error: expected type 'fn(i32) i32', found 'fn(i32) callconv(.C) i32' |
test/cases/compile_errors/stage1/obj/floatToInt_comptime_safety.zig deleted-17| ... | ... | @@ -1,17 +0,0 @@ |
| 1 | comptime { | |
| 2 | _ = @floatToInt(i8, @as(f32, -129.1)); | |
| 3 | } | |
| 4 | comptime { | |
| 5 | _ = @floatToInt(u8, @as(f32, -1.1)); | |
| 6 | } | |
| 7 | comptime { | |
| 8 | _ = @floatToInt(u8, @as(f32, 256.1)); | |
| 9 | } | |
| 10 | ||
| 11 | // error | |
| 12 | // backend=stage1 | |
| 13 | // target=native | |
| 14 | // | |
| 15 | // tmp.zig:2:9: error: integer value '-129' cannot be stored in type 'i8' | |
| 16 | // tmp.zig:5:9: error: integer value '-1' cannot be stored in type 'u8' | |
| 17 | // tmp.zig:8:9: error: integer value '256' cannot be stored in type 'u8' |
test/cases/compile_errors/stage1/obj/float_literal_too_large_error.zig deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | comptime { | |
| 2 | const a = 0x1.0p18495; | |
| 3 | _ = a; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage1 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // tmp.zig:2:15: error: float literal out of range of any type |
test/cases/compile_errors/stage1/obj/float_literal_too_small_error_denormal.zig deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | comptime { | |
| 2 | const a = 0x1.0p-19000; | |
| 3 | _ = a; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage1 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // tmp.zig:2:15: error: float literal out of range of any type |
test/cases/compile_errors/stage1/obj/frame_called_outside_of_function_definition.zig deleted-11| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | var handle_undef: anyframe = undefined; | |
| 2 | var handle_dummy: anyframe = @frame(); | |
| 3 | export fn entry() bool { | |
| 4 | return handle_undef == handle_dummy; | |
| 5 | } | |
| 6 | ||
| 7 | // error | |
| 8 | // backend=stage1 | |
| 9 | // target=native | |
| 10 | // | |
| 11 | // tmp.zig:2:30: error: @frame() called outside of function definition |
test/cases/compile_errors/stage1/obj/frame_causes_function_to_be_async.zig deleted-13| ... | ... | @@ -1,13 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | func(); | |
| 3 | } | |
| 4 | fn func() void { | |
| 5 | _ = @frame(); | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage1 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // tmp.zig:1:1: error: function with calling convention 'C' cannot be async | |
| 13 | // tmp.zig:5:9: note: @frame() causes function to be async |
test/cases/compile_errors/stage1/obj/function_with_ccc_indirectly_calling_async_function.zig deleted-18| ... | ... | @@ -1,18 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | foo(); | |
| 3 | } | |
| 4 | fn foo() void { | |
| 5 | bar(); | |
| 6 | } | |
| 7 | fn bar() void { | |
| 8 | suspend {} | |
| 9 | } | |
| 10 | ||
| 11 | // error | |
| 12 | // backend=stage1 | |
| 13 | // target=native | |
| 14 | // | |
| 15 | // tmp.zig:1:1: error: function with calling convention 'C' cannot be async | |
| 16 | // tmp.zig:2:8: note: async function call here | |
| 17 | // tmp.zig:5:8: note: async function call here | |
| 18 | // tmp.zig:8:5: note: suspends here |
test/cases/compile_errors/stage1/obj/implicit_casting_null_c_pointer_to_zig_pointer.zig deleted-11| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | comptime { | |
| 2 | var c_ptr: [*c]u8 = 0; | |
| 3 | var zig_ptr: *u8 = c_ptr; | |
| 4 | _ = zig_ptr; | |
| 5 | } | |
| 6 | ||
| 7 | // error | |
| 8 | // backend=stage1 | |
| 9 | // target=native | |
| 10 | // | |
| 11 | // tmp.zig:3:24: error: null pointer casted to type '*u8' |
test/cases/compile_errors/stage1/obj/implicit_casting_too_big_integers_to_C_pointers.zig deleted-16| ... | ... | @@ -1,16 +0,0 @@ |
| 1 | export fn a() void { | |
| 2 | var ptr: [*c]u8 = (1 << 64) + 1; | |
| 3 | _ = ptr; | |
| 4 | } | |
| 5 | export fn b() void { | |
| 6 | var x: u65 = 0x1234; | |
| 7 | var ptr: [*c]u8 = x; | |
| 8 | _ = ptr; | |
| 9 | } | |
| 10 | ||
| 11 | // error | |
| 12 | // backend=stage1 | |
| 13 | // target=native | |
| 14 | // | |
| 15 | // tmp.zig:2:33: error: integer value 18446744073709551617 cannot be coerced to type 'usize' | |
| 16 | // tmp.zig:7:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8' |
test/cases/compile_errors/stage1/obj/implicit_dependency_on_libc.zig deleted-11| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | extern "c" fn exit(u8) void; | |
| 2 | export fn entry() void { | |
| 3 | exit(0); | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage1 | |
| 8 | // target=native-linux | |
| 9 | // is_test=1 | |
| 10 | // | |
| 11 | // tmp.zig:3:5: error: dependency on libc must be explicitly specified in the build command |
test/cases/compile_errors/stage1/obj/indexing_a_undefined_slice_at_comptime.zig deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | comptime { | |
| 2 | var slice: []u8 = undefined; | |
| 3 | slice[0] = 2; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage1 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // tmp.zig:3:10: error: index 0 outside slice of size 0 |
test/cases/compile_errors/stage1/obj/indirect_recursion_of_async_functions_detected.zig deleted-36| ... | ... | @@ -1,36 +0,0 @@ |
| 1 | var frame: ?anyframe = null; | |
| 2 | ||
| 3 | export fn a() void { | |
| 4 | _ = async rangeSum(10); | |
| 5 | while (frame) |f| resume f; | |
| 6 | } | |
| 7 | ||
| 8 | fn rangeSum(x: i32) i32 { | |
| 9 | suspend { | |
| 10 | frame = @frame(); | |
| 11 | } | |
| 12 | frame = null; | |
| 13 | ||
| 14 | if (x == 0) return 0; | |
| 15 | var child = rangeSumIndirect(x - 1); | |
| 16 | return child + 1; | |
| 17 | } | |
| 18 | ||
| 19 | fn rangeSumIndirect(x: i32) i32 { | |
| 20 | suspend { | |
| 21 | frame = @frame(); | |
| 22 | } | |
| 23 | frame = null; | |
| 24 | ||
| 25 | if (x == 0) return 0; | |
| 26 | var child = rangeSum(x - 1); | |
| 27 | return child + 1; | |
| 28 | } | |
| 29 | ||
| 30 | // error | |
| 31 | // backend=stage1 | |
| 32 | // target=native | |
| 33 | // | |
| 34 | // tmp.zig:8:1: error: '@Frame(rangeSum)' depends on itself | |
| 35 | // tmp.zig:15:33: note: when analyzing type '@Frame(rangeSum)' here | |
| 36 | // tmp.zig:26:25: note: when analyzing type '@Frame(rangeSumIndirect)' here |
test/cases/compile_errors/stage1/obj/integer_cast_truncates_bits.zig deleted-31| ... | ... | @@ -1,31 +0,0 @@ |
| 1 | export fn entry1() void { | |
| 2 | const spartan_count: u16 = 300; | |
| 3 | const byte = @intCast(u8, spartan_count); | |
| 4 | _ = byte; | |
| 5 | } | |
| 6 | export fn entry2() void { | |
| 7 | const spartan_count: u16 = 300; | |
| 8 | const byte: u8 = spartan_count; | |
| 9 | _ = byte; | |
| 10 | } | |
| 11 | export fn entry3() void { | |
| 12 | var spartan_count: u16 = 300; | |
| 13 | var byte: u8 = spartan_count; | |
| 14 | _ = byte; | |
| 15 | } | |
| 16 | export fn entry4() void { | |
| 17 | var signed: i8 = -1; | |
| 18 | var unsigned: u64 = signed; | |
| 19 | _ = unsigned; | |
| 20 | } | |
| 21 | ||
| 22 | // error | |
| 23 | // backend=stage1 | |
| 24 | // target=native | |
| 25 | // | |
| 26 | // tmp.zig:3:18: error: cast from 'u16' to 'u8' truncates bits | |
| 27 | // tmp.zig:8:22: error: integer value 300 cannot be coerced to type 'u8' | |
| 28 | // tmp.zig:13:20: error: expected type 'u8', found 'u16' | |
| 29 | // tmp.zig:13:20: note: unsigned 8-bit int cannot represent all possible unsigned 16-bit values | |
| 30 | // tmp.zig:18:25: error: expected type 'u64', found 'i8' | |
| 31 | // tmp.zig:18:25: note: unsigned 64-bit int cannot represent all possible signed 8-bit values |
test/cases/compile_errors/stage1/obj/invalid_suspend_in_exported_function.zig deleted-15| ... | ... | @@ -1,15 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | var frame = async func(); | |
| 3 | var result = await frame; | |
| 4 | _ = result; | |
| 5 | } | |
| 6 | fn func() void { | |
| 7 | suspend {} | |
| 8 | } | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=stage1 | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // tmp.zig:1:1: error: function with calling convention 'C' cannot be async | |
| 15 | // tmp.zig:3:18: note: await here is a suspend point |
test/cases/compile_errors/stage1/obj/issue_4207_coerce_from_non-terminated-slice_to_terminated-pointer.zig deleted-11| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | export fn foo() [*:0]const u8 { | |
| 2 | var buffer: [64]u8 = undefined; | |
| 3 | return buffer[0..]; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage1 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // :3:18: error: expected type '[*:0]const u8', found '*[64]u8' | |
| 11 | // :3:18: note: destination pointer requires a terminating '0' sentinel |
test/cases/compile_errors/stage1/obj/issue_7810-comptime_slice-len_increment_beyond_bounds.zig deleted-14| ... | ... | @@ -1,14 +0,0 @@ |
| 1 | export fn foo_slice_len_increment_beyond_bounds() void { | |
| 2 | comptime { | |
| 3 | var buf_storage: [8]u8 = undefined; | |
| 4 | var buf: []const u8 = buf_storage[0..]; | |
| 5 | buf.len += 1; | |
| 6 | buf[8] = 42; | |
| 7 | } | |
| 8 | } | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=stage1 | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // :6:12: error: out of bounds slice |
test/cases/compile_errors/stage1/obj/lazy_pointer_with_undefined_element_type.zig deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | export fn foo() void { | |
| 2 | comptime var T: type = undefined; | |
| 3 | const S = struct { x: *T }; | |
| 4 | const I = @typeInfo(S); | |
| 5 | _ = I; | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage1 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // :3:28: error: use of undefined value here causes undefined behavior |
test/cases/compile_errors/stage1/obj/libc_headers_note.zig deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | const c = @cImport(@cInclude("stdio.h")); | |
| 2 | export fn entry() void { | |
| 3 | _ = c.printf("hello, world!\n"); | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage1 | |
| 8 | // is_test=1 | |
| 9 | // target=native-linux | |
| 10 | // | |
| 11 | // tmp.zig:1:11: error: C import failed | |
| 12 | // tmp.zig:1:11: note: libc headers not available; compilation does not link against libc |
test/cases/compile_errors/stage1/obj/missing_function_call_param.zig deleted-31| ... | ... | @@ -1,31 +0,0 @@ |
| 1 | const Foo = struct { | |
| 2 | a: i32, | |
| 3 | b: i32, | |
| 4 | ||
| 5 | fn member_a(foo: *const Foo) i32 { | |
| 6 | return foo.a; | |
| 7 | } | |
| 8 | fn member_b(foo: *const Foo) i32 { | |
| 9 | return foo.b; | |
| 10 | } | |
| 11 | }; | |
| 12 | ||
| 13 | const member_fn_type = @TypeOf(Foo.member_a); | |
| 14 | const members = [_]member_fn_type { | |
| 15 | Foo.member_a, | |
| 16 | Foo.member_b, | |
| 17 | }; | |
| 18 | ||
| 19 | fn f(foo: *const Foo, index: usize) void { | |
| 20 | const result = members[index](); | |
| 21 | _ = foo; | |
| 22 | _ = result; | |
| 23 | } | |
| 24 | ||
| 25 | export fn entry() usize { return @sizeOf(@TypeOf(f)); } | |
| 26 | ||
| 27 | // error | |
| 28 | // backend=stage1 | |
| 29 | // target=native | |
| 30 | // | |
| 31 | // tmp.zig:20:34: error: expected 1 argument(s), found 0 |
test/cases/compile_errors/stage1/obj/missing_result_type_for_phi_node.zig deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | fn foo() !void { | |
| 2 | return anyerror.Foo; | |
| 3 | } | |
| 4 | export fn entry() void { | |
| 5 | foo() catch 0; | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage1 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // tmp.zig:5:17: error: integer value 0 cannot be coerced to type 'void' |
test/cases/compile_errors/stage1/obj/noalias_on_non_pointer_param.zig deleted-8| ... | ... | @@ -1,8 +0,0 @@ |
| 1 | fn f(noalias x: i32) void { _ = x; } | |
| 2 | export fn entry() void { f(1234); } | |
| 3 | ||
| 4 | // error | |
| 5 | // backend=stage1 | |
| 6 | // target=native | |
| 7 | // | |
| 8 | // tmp.zig:1:6: error: noalias on non-pointer parameter |
test/cases/compile_errors/stage1/obj/non-async_function_pointer_eventually_is_inferred_to_become_async.zig deleted-15| ... | ... | @@ -1,15 +0,0 @@ |
| 1 | export fn a() void { | |
| 2 | var non_async_fn: fn () void = undefined; | |
| 3 | non_async_fn = func; | |
| 4 | } | |
| 5 | fn func() void { | |
| 6 | suspend {} | |
| 7 | } | |
| 8 | ||
| 9 | // error | |
| 10 | // backend=stage1 | |
| 11 | // target=native | |
| 12 | // | |
| 13 | // tmp.zig:5:1: error: 'func' cannot be async | |
| 14 | // tmp.zig:3:20: note: required to be non-async here | |
| 15 | // tmp.zig:6:5: note: suspends here |
test/cases/compile_errors/stage1/obj/non_async_function_pointer_passed_to_asyncCall.zig deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | var ptr = afunc; | |
| 3 | var bytes: [100]u8 align(16) = undefined; | |
| 4 | _ = @asyncCall(&bytes, {}, ptr, .{}); | |
| 5 | } | |
| 6 | fn afunc() void { } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage1 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // tmp.zig:4:32: error: expected async function, found 'fn() void' |
test/cases/compile_errors/stage1/obj/passing_an_under-aligned_function_pointer.zig deleted-13| ... | ... | @@ -1,13 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | testImplicitlyDecreaseFnAlign(alignedSmall, 1234); | |
| 3 | } | |
| 4 | fn testImplicitlyDecreaseFnAlign(ptr: fn () align(8) i32, answer: i32) void { | |
| 5 | if (ptr() != answer) unreachable; | |
| 6 | } | |
| 7 | fn alignedSmall() align(4) i32 { return 1234; } | |
| 8 | ||
| 9 | // error | |
| 10 | // backend=stage1 | |
| 11 | // target=native | |
| 12 | // | |
| 13 | // tmp.zig:2:35: error: expected type 'fn() align(8) i32', found 'fn() align(4) i32' |
test/cases/compile_errors/stage1/obj/prevent_bad_implicit_casting_of_anyframe_types.zig deleted-24| ... | ... | @@ -1,24 +0,0 @@ |
| 1 | export fn a() void { | |
| 2 | var x: anyframe = undefined; | |
| 3 | var y: anyframe->i32 = x; | |
| 4 | _ = y; | |
| 5 | } | |
| 6 | export fn b() void { | |
| 7 | var x: i32 = undefined; | |
| 8 | var y: anyframe->i32 = x; | |
| 9 | _ = y; | |
| 10 | } | |
| 11 | export fn c() void { | |
| 12 | var x: @Frame(func) = undefined; | |
| 13 | var y: anyframe->i32 = &x; | |
| 14 | _ = y; | |
| 15 | } | |
| 16 | fn func() void {} | |
| 17 | ||
| 18 | // error | |
| 19 | // backend=stage1 | |
| 20 | // target=native | |
| 21 | // | |
| 22 | // :3:28: error: expected type 'anyframe->i32', found 'anyframe' | |
| 23 | // :8:28: error: expected type 'anyframe->i32', found 'i32' | |
| 24 | // tmp.zig:13:29: error: expected type 'anyframe->i32', found '*@Frame(func)' | |
| \ No newline at end of file |
test/cases/compile_errors/stage1/obj/reify_type_for_union_with_opaque_field.zig deleted-19| ... | ... | @@ -1,19 +0,0 @@ |
| 1 | const Untagged = @Type(.{ | |
| 2 | .Union = .{ | |
| 3 | .layout = .Auto, | |
| 4 | .tag_type = null, | |
| 5 | .fields = &.{ | |
| 6 | .{ .name = "foo", .field_type = opaque {}, .alignment = 1 }, | |
| 7 | }, | |
| 8 | .decls = &.{}, | |
| 9 | }, | |
| 10 | }); | |
| 11 | export fn entry() usize { | |
| 12 | return @sizeOf(Untagged); | |
| 13 | } | |
| 14 | ||
| 15 | // error | |
| 16 | // backend=stage1 | |
| 17 | // target=native | |
| 18 | // | |
| 19 | // tmp.zig:1:25: error: opaque types have unknown size and therefore cannot be directly embedded in unions |
test/cases/compile_errors/stage1/obj/returning_error_from_void_async_function.zig deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | _ = async amain(); | |
| 3 | } | |
| 4 | fn amain() callconv(.Async) void { | |
| 5 | return error.ShouldBeCompileError; | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage1 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // tmp.zig:5:17: error: expected type 'void', found 'error{ShouldBeCompileError}' |
test/cases/compile_errors/stage1/obj/runtime-known_async_function_called.zig deleted-14| ... | ... | @@ -1,14 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | _ = async amain(); | |
| 3 | } | |
| 4 | fn amain() void { | |
| 5 | var ptr = afunc; | |
| 6 | _ = ptr(); | |
| 7 | } | |
| 8 | fn afunc() callconv(.Async) void {} | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=stage1 | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // tmp.zig:6:12: error: function is not comptime-known; @asyncCall required |
test/cases/compile_errors/stage1/obj/runtime-known_function_called_with_async_keyword.zig deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | var ptr = afunc; | |
| 3 | _ = async ptr(); | |
| 4 | } | |
| 5 | ||
| 6 | fn afunc() callconv(.Async) void { } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage1 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // tmp.zig:3:15: error: function is not comptime-known; @asyncCall required |
test/cases/compile_errors/stage1/obj/runtime_assignment_to_comptime_struct_type.zig deleted-15| ... | ... | @@ -1,15 +0,0 @@ |
| 1 | const Foo = struct { | |
| 2 | Bar: u8, | |
| 3 | Baz: type, | |
| 4 | }; | |
| 5 | export fn f() void { | |
| 6 | var x: u8 = 0; | |
| 7 | const foo = Foo { .Bar = x, .Baz = u8 }; | |
| 8 | _ = foo; | |
| 9 | } | |
| 10 | ||
| 11 | // error | |
| 12 | // backend=stage1 | |
| 13 | // target=native | |
| 14 | // | |
| 15 | // tmp.zig:7:23: error: unable to evaluate constant expression |
test/cases/compile_errors/stage1/obj/runtime_assignment_to_comptime_union_type.zig deleted-15| ... | ... | @@ -1,15 +0,0 @@ |
| 1 | const Foo = union { | |
| 2 | Bar: u8, | |
| 3 | Baz: type, | |
| 4 | }; | |
| 5 | export fn f() void { | |
| 6 | var x: u8 = 0; | |
| 7 | const foo = Foo { .Bar = x }; | |
| 8 | _ = foo; | |
| 9 | } | |
| 10 | ||
| 11 | // error | |
| 12 | // backend=stage1 | |
| 13 | // target=native | |
| 14 | // | |
| 15 | // tmp.zig:7:23: error: unable to evaluate constant expression |
test/cases/compile_errors/stage1/obj/saturating_shl_assign_does_not_allow_negative_rhs_at_comptime.zig deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | export fn a() void { | |
| 2 | comptime { | |
| 3 | var x = @as(i32, 1); | |
| 4 | x <<|= @as(i32, -2); | |
| 5 | } | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage1 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // error: shift by negative value -2 |
test/cases/compile_errors/stage1/obj/saturating_shl_does_not_allow_negative_rhs_at_comptime.zig deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | export fn a() void { | |
| 2 | _ = @as(i32, 1) <<| @as(i32, -2); | |
| 3 | } | |
| 4 | ||
| 5 | // error | |
| 6 | // backend=stage1 | |
| 7 | // target=native | |
| 8 | // | |
| 9 | // error: shift by negative value -2 |
test/cases/compile_errors/stage1/obj/setFloatMode_twice_for_same_scope.zig deleted-11| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | export fn foo() void { | |
| 2 | @setFloatMode(@import("std").builtin.FloatMode.Optimized); | |
| 3 | @setFloatMode(@import("std").builtin.FloatMode.Optimized); | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage1 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // tmp.zig:3:5: error: float mode set twice for same scope | |
| 11 | // tmp.zig:2:5: note: first set here |
test/cases/compile_errors/stage1/obj/setRuntimeSafety_twice_for_same_scope.zig deleted-11| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | export fn foo() void { | |
| 2 | @setRuntimeSafety(false); | |
| 3 | @setRuntimeSafety(false); | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage1 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // tmp.zig:3:5: error: runtime safety set twice for same scope | |
| 11 | // tmp.zig:2:5: note: first set here |
test/cases/compile_errors/stage1/obj/shift_amount_has_to_be_an_integer_type.zig deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | const x = 1 << &@as(u8, 10); | |
| 3 | _ = x; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage1 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // tmp.zig:2:21: error: shift amount has to be an integer type, but found '*const u8' |
test/cases/compile_errors/stage1/obj/shift_by_negative_comptime_integer.zig deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | comptime { | |
| 2 | var a = 1 >> -1; | |
| 3 | _ = a; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage1 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // tmp.zig:2:18: error: shift by negative value -1 |
test/cases/compile_errors/stage1/obj/slice_sentinel_mismatch-1.zig deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | const y: [:1]const u8 = &[_:2]u8{ 1, 2 }; | |
| 3 | _ = y; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage1 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // tmp.zig:2:37: error: expected type '[:1]const u8', found '*const [2:2]u8' |
test/cases/compile_errors/stage1/obj/storing_runtime_value_in_compile_time_variable_then_using_it.zig deleted-49| ... | ... | @@ -1,49 +0,0 @@ |
| 1 | const Mode = @import("std").builtin.Mode; | |
| 2 | ||
| 3 | fn Free(comptime filename: []const u8) TestCase { | |
| 4 | return TestCase { | |
| 5 | .filename = filename, | |
| 6 | .problem_type = ProblemType.Free, | |
| 7 | }; | |
| 8 | } | |
| 9 | ||
| 10 | fn LibC(comptime filename: []const u8) TestCase { | |
| 11 | return TestCase { | |
| 12 | .filename = filename, | |
| 13 | .problem_type = ProblemType.LinkLibC, | |
| 14 | }; | |
| 15 | } | |
| 16 | ||
| 17 | const TestCase = struct { | |
| 18 | filename: []const u8, | |
| 19 | problem_type: ProblemType, | |
| 20 | }; | |
| 21 | ||
| 22 | const ProblemType = enum { | |
| 23 | Free, | |
| 24 | LinkLibC, | |
| 25 | }; | |
| 26 | ||
| 27 | export fn entry() void { | |
| 28 | const tests = [_]TestCase { | |
| 29 | Free("001"), | |
| 30 | Free("002"), | |
| 31 | LibC("078"), | |
| 32 | Free("116"), | |
| 33 | Free("117"), | |
| 34 | }; | |
| 35 | ||
| 36 | for ([_]Mode { Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast }) |mode| { | |
| 37 | _ = mode; | |
| 38 | inline for (tests) |test_case| { | |
| 39 | const foo = test_case.filename ++ ".zig"; | |
| 40 | _ = foo; | |
| 41 | } | |
| 42 | } | |
| 43 | } | |
| 44 | ||
| 45 | // error | |
| 46 | // backend=stage1 | |
| 47 | // target=native | |
| 48 | // | |
| 49 | // tmp.zig:38:29: error: cannot store runtime value in compile time variable |
test/cases/compile_errors/stage1/obj/taking_bit_offset_of_void_field_in_struct.zig deleted-13| ... | ... | @@ -1,13 +0,0 @@ |
| 1 | const Empty = struct { | |
| 2 | val: void, | |
| 3 | }; | |
| 4 | export fn foo() void { | |
| 5 | const fieldOffset = @bitOffsetOf(Empty, "val",); | |
| 6 | _ = fieldOffset; | |
| 7 | } | |
| 8 | ||
| 9 | // error | |
| 10 | // backend=stage1 | |
| 11 | // target=native | |
| 12 | // | |
| 13 | // tmp.zig:5:45: error: zero-bit field 'val' in struct 'Empty' has no offset |
test/cases/compile_errors/stage1/obj/taking_byte_offset_of_void_field_in_struct.zig deleted-13| ... | ... | @@ -1,13 +0,0 @@ |
| 1 | const Empty = struct { | |
| 2 | val: void, | |
| 3 | }; | |
| 4 | export fn foo() void { | |
| 5 | const fieldOffset = @offsetOf(Empty, "val",); | |
| 6 | _ = fieldOffset; | |
| 7 | } | |
| 8 | ||
| 9 | // error | |
| 10 | // backend=stage1 | |
| 11 | // target=native | |
| 12 | // | |
| 13 | // tmp.zig:5:42: error: zero-bit field 'val' in struct 'Empty' has no offset |
test/cases/compile_errors/stage1/obj/union_auto-enum_value_already_taken.zig deleted-18| ... | ... | @@ -1,18 +0,0 @@ |
| 1 | const MultipleChoice = union(enum(u32)) { | |
| 2 | A = 20, | |
| 3 | B = 40, | |
| 4 | C = 60, | |
| 5 | D = 1000, | |
| 6 | E = 60, | |
| 7 | }; | |
| 8 | export fn entry() void { | |
| 9 | var x = MultipleChoice { .C = {} }; | |
| 10 | _ = x; | |
| 11 | } | |
| 12 | ||
| 13 | // error | |
| 14 | // backend=stage1 | |
| 15 | // target=native | |
| 16 | // | |
| 17 | // tmp.zig:6:9: error: enum tag value 60 already taken | |
| 18 | // tmp.zig:4:9: note: other occurrence here |
test/cases/compile_errors/stage1/obj/union_enum_field_does_not_match_enum.zig deleted-22| ... | ... | @@ -1,22 +0,0 @@ |
| 1 | const Letter = enum { | |
| 2 | A, | |
| 3 | B, | |
| 4 | C, | |
| 5 | }; | |
| 6 | const Payload = union(Letter) { | |
| 7 | A: i32, | |
| 8 | B: f64, | |
| 9 | C: bool, | |
| 10 | D: bool, | |
| 11 | }; | |
| 12 | export fn entry() void { | |
| 13 | var a = Payload {.A = 1234}; | |
| 14 | _ = a; | |
| 15 | } | |
| 16 | ||
| 17 | // error | |
| 18 | // backend=stage1 | |
| 19 | // target=native | |
| 20 | // | |
| 21 | // tmp.zig:10:5: error: enum field not found: 'D' | |
| 22 | // tmp.zig:1:16: note: enum declared here |
test/cases/compile_errors/stage1/obj/union_with_too_small_explicit_signed_tag_type.zig deleted-16| ... | ... | @@ -1,16 +0,0 @@ |
| 1 | const U = union(enum(i2)) { | |
| 2 | A: u8, | |
| 3 | B: u8, | |
| 4 | C: u8, | |
| 5 | D: u8, | |
| 6 | }; | |
| 7 | export fn entry() void { | |
| 8 | _ = U{ .D = 1 }; | |
| 9 | } | |
| 10 | ||
| 11 | // error | |
| 12 | // backend=stage1 | |
| 13 | // target=native | |
| 14 | // | |
| 15 | // tmp.zig:1:22: error: specified integer tag type cannot represent every field | |
| 16 | // tmp.zig:1:22: note: type i2 cannot fit values in range 0...3 |
test/cases/compile_errors/stage1/obj/union_with_too_small_explicit_unsigned_tag_type.zig deleted-17| ... | ... | @@ -1,17 +0,0 @@ |
| 1 | const U = union(enum(u2)) { | |
| 2 | A: u8, | |
| 3 | B: u8, | |
| 4 | C: u8, | |
| 5 | D: u8, | |
| 6 | E: u8, | |
| 7 | }; | |
| 8 | export fn entry() void { | |
| 9 | _ = U{ .E = 1 }; | |
| 10 | } | |
| 11 | ||
| 12 | // error | |
| 13 | // backend=stage1 | |
| 14 | // target=native | |
| 15 | // | |
| 16 | // tmp.zig:1:22: error: specified integer tag type cannot represent every field | |
| 17 | // tmp.zig:1:22: note: type u2 cannot fit values in range 0...4 |
test/cases/compile_errors/stage1/obj/wrong_frame_type_used_for_async_call.zig deleted-16| ... | ... | @@ -1,16 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | var frame: @Frame(foo) = undefined; | |
| 3 | frame = async bar(); | |
| 4 | } | |
| 5 | fn foo() void { | |
| 6 | suspend {} | |
| 7 | } | |
| 8 | fn bar() void { | |
| 9 | suspend {} | |
| 10 | } | |
| 11 | ||
| 12 | // error | |
| 13 | // backend=stage1 | |
| 14 | // target=native | |
| 15 | // | |
| 16 | // tmp.zig:3:13: error: expected type '*@Frame(bar)', found '*@Frame(foo)' |
test/cases/compile_errors/stage1/obj/wrong_function_type.zig deleted-11| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | const fns = [_]fn() void { a, b, c }; | |
| 2 | fn a() i32 {return 0;} | |
| 3 | fn b() i32 {return 1;} | |
| 4 | fn c() i32 {return 2;} | |
| 5 | export fn entry() usize { return @sizeOf(@TypeOf(fns)); } | |
| 6 | ||
| 7 | // error | |
| 8 | // backend=stage1 | |
| 9 | // target=native | |
| 10 | // | |
| 11 | // tmp.zig:1:28: error: expected type 'fn() void', found 'fn() i32' |
test/cases/compile_errors/stage1/obj/wrong_panic_signature_generic_function.zig deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | pub fn panic(comptime msg: []const u8, error_return_trace: ?*builtin.StackTrace, _: ?usize) noreturn { | |
| 2 | _ = msg; _ = error_return_trace; | |
| 3 | while (true) {} | |
| 4 | } | |
| 5 | const builtin = @import("std").builtin; | |
| 6 | ||
| 7 | // error | |
| 8 | // backend=stage1 | |
| 9 | // target=native | |
| 10 | // | |
| 11 | // error: expected type 'fn([]const u8, ?*std.builtin.StackTrace, ?usize) noreturn', found 'fn([]const u8,anytype,anytype) anytype' | |
| 12 | // note: only one of the functions is generic |
test/cases/compile_errors/stage1/obj/wrong_panic_signature_runtime_function.zig deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | test {} | |
| 2 | ||
| 3 | pub fn panic() void {} | |
| 4 | ||
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage1 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // error: expected type 'fn([]const u8, ?*std.builtin.StackTrace, ?usize) noreturn', found 'fn() void' |
test/cases/compile_errors/stage1/obj/wrong_return_type_for_main.zig deleted-7| ... | ... | @@ -1,7 +0,0 @@ |
| 1 | pub fn main() f32 { } | |
| 2 | ||
| 3 | // error | |
| 4 | // backend=stage1 | |
| 5 | // target=native | |
| 6 | // | |
| 7 | // error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8' |
test/cases/compile_errors/stage1/obj/wrong_type_for_argument_tuple_to_asyncCall.zig deleted-14| ... | ... | @@ -1,14 +0,0 @@ |
| 1 | export fn entry1() void { | |
| 2 | var frame: @Frame(foo) = undefined; | |
| 3 | @asyncCall(&frame, {}, foo, {}); | |
| 4 | } | |
| 5 | ||
| 6 | fn foo() i32 { | |
| 7 | return 0; | |
| 8 | } | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=stage1 | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // tmp.zig:3:33: error: expected tuple or struct, found 'void' |
test/cases/compile_errors/stage1/obj/wrong_type_for_result_ptr_to_asyncCall.zig deleted-16| ... | ... | @@ -1,16 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | _ = async amain(); | |
| 3 | } | |
| 4 | fn amain() i32 { | |
| 5 | var frame: @Frame(foo) = undefined; | |
| 6 | return await @asyncCall(&frame, false, foo, .{}); | |
| 7 | } | |
| 8 | fn foo() i32 { | |
| 9 | return 1234; | |
| 10 | } | |
| 11 | ||
| 12 | // error | |
| 13 | // backend=stage1 | |
| 14 | // target=native | |
| 15 | // | |
| 16 | // tmp.zig:6:37: error: expected type '*i32', found 'bool' |
test/cases/compile_errors/stage2/comptime_unreachable.zig deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | pub export fn entry() void { | |
| 2 | comptime unreachable; | |
| 3 | } | |
| 4 | ||
| 5 | // error | |
| 6 | // target=native | |
| 7 | // backend=stage2 | |
| 8 | // | |
| 9 | // :2:14: error: reached unreachable code |
test/cases/compile_errors/stage2/constant_inside_comptime_function_has_compile_error.zig deleted-21| ... | ... | @@ -1,21 +0,0 @@ |
| 1 | const ContextAllocator = MemoryPool(usize); | |
| 2 | ||
| 3 | pub fn MemoryPool(comptime T: type) type { | |
| 4 | const free_list_t = @compileError("aoeu",); | |
| 5 | _ = T; | |
| 6 | ||
| 7 | return struct { | |
| 8 | free_list: free_list_t, | |
| 9 | }; | |
| 10 | } | |
| 11 | ||
| 12 | export fn entry() void { | |
| 13 | var allocator: ContextAllocator = undefined; | |
| 14 | _ = allocator; | |
| 15 | } | |
| 16 | ||
| 17 | // error | |
| 18 | // target=native | |
| 19 | // | |
| 20 | // :4:5: error: unreachable code | |
| 21 | // :4:25: note: control flow is diverted here |
test/cases/compile_errors/stage2/duplicate-unused_labels.zig deleted-31| ... | ... | @@ -1,31 +0,0 @@ |
| 1 | comptime { | |
| 2 | blk: { blk: while (false) {} } | |
| 3 | } | |
| 4 | comptime { | |
| 5 | blk: while (false) { blk: for (@as([0]void, undefined)) |_| {} } | |
| 6 | } | |
| 7 | comptime { | |
| 8 | blk: for (@as([0]void, undefined)) |_| { blk: {} } | |
| 9 | } | |
| 10 | comptime { | |
| 11 | blk: {} | |
| 12 | } | |
| 13 | comptime { | |
| 14 | blk: while(false) {} | |
| 15 | } | |
| 16 | comptime { | |
| 17 | blk: for(@as([0]void, undefined)) |_| {} | |
| 18 | } | |
| 19 | ||
| 20 | // error | |
| 21 | // target=native | |
| 22 | // | |
| 23 | // :2:12: error: redefinition of label 'blk' | |
| 24 | // :2:5: note: previous definition here | |
| 25 | // :5:26: error: redefinition of label 'blk' | |
| 26 | // :5:5: note: previous definition here | |
| 27 | // :8:46: error: redefinition of label 'blk' | |
| 28 | // :8:5: note: previous definition here | |
| 29 | // :11:5: error: unused block label | |
| 30 | // :14:5: error: unused while loop label | |
| 31 | // :17:5: error: unused for loop label |
test/cases/compile_errors/stage2/embed_outside_package.zig deleted-8| ... | ... | @@ -1,8 +0,0 @@ |
| 1 | export fn a() usize { | |
| 2 | return @embedFile("/root/foo").len; | |
| 3 | } | |
| 4 | ||
| 5 | // error | |
| 6 | // target=native | |
| 7 | // | |
| 8 | //:2:23: error: embed of file outside package path: '/root/foo' |
test/cases/compile_errors/stage2/import_outside_package.zig deleted-8| ... | ... | @@ -1,8 +0,0 @@ |
| 1 | export fn a() usize { | |
| 2 | return @import("../../above.zig").len; | |
| 3 | } | |
| 4 | ||
| 5 | // error | |
| 6 | // target=native | |
| 7 | // | |
| 8 | // :2:20: error: import of file outside package path: '../../above.zig' |
test/cases/compile_errors/stage2/out_of_bounds_index.zig deleted-29| ... | ... | @@ -1,29 +0,0 @@ |
| 1 | comptime { | |
| 2 | var array = [_:0]u8{ 1, 2, 3, 4 }; | |
| 3 | var src_slice: [:0]u8 = &array; | |
| 4 | var slice = src_slice[2..6]; | |
| 5 | _ = slice; | |
| 6 | } | |
| 7 | comptime { | |
| 8 | var array = [_:0]u8{ 1, 2, 3, 4 }; | |
| 9 | var slice = array[2..6]; | |
| 10 | _ = slice; | |
| 11 | } | |
| 12 | comptime { | |
| 13 | var array = [_]u8{ 1, 2, 3, 4 }; | |
| 14 | var slice = array[2..5]; | |
| 15 | _ = slice; | |
| 16 | } | |
| 17 | comptime { | |
| 18 | var array = [_:0]u8{ 1, 2, 3, 4 }; | |
| 19 | var slice = array[3..2]; | |
| 20 | _ = slice; | |
| 21 | } | |
| 22 | ||
| 23 | // error | |
| 24 | // target=native | |
| 25 | // | |
| 26 | // :4:30: error: end index 6 out of bounds for slice of length 4 +1 (sentinel) | |
| 27 | // :9:26: error: end index 6 out of bounds for array of length 4 +1 (sentinel) | |
| 28 | // :14:26: error: end index 5 out of bounds for array of length 4 | |
| 29 | // :19:23: error: start index 3 is larger than end index 2 |
test/cases/compile_errors/stage2/reified_enum_field_value_overflow.zig deleted-20| ... | ... | @@ -1,20 +0,0 @@ |
| 1 | comptime { | |
| 2 | const E = @Type(.{ .Enum = .{ | |
| 3 | .layout = .Auto, | |
| 4 | .tag_type = u1, | |
| 5 | .fields = &.{ | |
| 6 | .{ .name = "f0", .value = 0 }, | |
| 7 | .{ .name = "f1", .value = 1 }, | |
| 8 | .{ .name = "f2", .value = 2 }, | |
| 9 | }, | |
| 10 | .decls = &.{}, | |
| 11 | .is_exhaustive = true, | |
| 12 | } }); | |
| 13 | _ = E; | |
| 14 | } | |
| 15 | ||
| 16 | // error | |
| 17 | // target=native | |
| 18 | // backend=stage2 | |
| 19 | // | |
| 20 | // :2:15: error: field 'f2' with enumeration value '2' is too large for backing int type 'u1' |
test/cases/compile_errors/stage2/slice_of_null_pointer.zig deleted-11| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | comptime { | |
| 2 | var x: [*c]u8 = null; | |
| 3 | var runtime_len: usize = 0; | |
| 4 | var y = x[0..runtime_len]; | |
| 5 | _ = y; | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // target=native | |
| 10 | // | |
| 11 | // :4:14: error: slice of null pointer |
test/cases/compile_errors/stage2/struct_duplicate_field_name.zig deleted-16| ... | ... | @@ -1,16 +0,0 @@ |
| 1 | const S = struct { | |
| 2 | foo: u32, | |
| 3 | foo: u32, | |
| 4 | }; | |
| 5 | ||
| 6 | export fn entry() void { | |
| 7 | const s: S = .{ .foo = 100 }; | |
| 8 | _ = s; | |
| 9 | } | |
| 10 | ||
| 11 | // error | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // :3:5: error: duplicate struct field: 'foo' | |
| 15 | // :2:5: note: other field here | |
| 16 | // :1:11: note: struct declared here |
test/cases/compile_errors/stage2/tuple_ptr_to_mut_slice.zig deleted-32| ... | ... | @@ -1,32 +0,0 @@ |
| 1 | export fn entry1() void { | |
| 2 | var a = .{ 1, 2, 3 }; | |
| 3 | _ = @as([]u8, &a); | |
| 4 | } | |
| 5 | export fn entry2() void { | |
| 6 | var a = .{ @as(u8, 1), @as(u8, 2), @as(u8, 3) }; | |
| 7 | _ = @as([]u8, &a); | |
| 8 | } | |
| 9 | ||
| 10 | // runtime values | |
| 11 | var vals = [_]u7{ 4, 5, 6 }; | |
| 12 | export fn entry3() void { | |
| 13 | var a = .{ vals[0], vals[1], vals[2] }; | |
| 14 | _ = @as([]u8, &a); | |
| 15 | } | |
| 16 | export fn entry4() void { | |
| 17 | var a = .{ @as(u8, vals[0]), @as(u8, vals[1]), @as(u8, vals[2]) }; | |
| 18 | _ = @as([]u8, &a); | |
| 19 | } | |
| 20 | ||
| 21 | // error | |
| 22 | // backend=stage2 | |
| 23 | // target=native | |
| 24 | // | |
| 25 | // :3:19: error: cannot cast pointer to tuple to '[]u8' | |
| 26 | // :3:19: note: pointers to tuples can only coerce to constant pointers | |
| 27 | // :7:19: error: cannot cast pointer to tuple to '[]u8' | |
| 28 | // :7:19: note: pointers to tuples can only coerce to constant pointers | |
| 29 | // :14:19: error: cannot cast pointer to tuple to '[]u8' | |
| 30 | // :14:19: note: pointers to tuples can only coerce to constant pointers | |
| 31 | // :18:19: error: cannot cast pointer to tuple to '[]u8' | |
| 32 | // :18:19: note: pointers to tuples can only coerce to constant pointers |
test/cases/compile_errors/stage2/union_access_of_inactive_field.zig deleted-15| ... | ... | @@ -1,15 +0,0 @@ |
| 1 | const U = union { | |
| 2 | a: void, | |
| 3 | b: u64, | |
| 4 | }; | |
| 5 | comptime { | |
| 6 | var u: U = .{ .a = {} }; | |
| 7 | const v = u.b; | |
| 8 | _ = v; | |
| 9 | } | |
| 10 | ||
| 11 | // error | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // :7:16: error: access of union field 'b' while field 'a' is active | |
| 15 | // :1:11: note: union declared here |
test/cases/compile_errors/stage2/union_duplicate_enum_field.zig deleted-17| ... | ... | @@ -1,17 +0,0 @@ |
| 1 | const E = enum { a, b }; | |
| 2 | const U = union(E) { | |
| 3 | a: u32, | |
| 4 | a: u32, | |
| 5 | }; | |
| 6 | ||
| 7 | export fn foo() void { | |
| 8 | var u: U = .{ .a = 123 }; | |
| 9 | _ = u; | |
| 10 | } | |
| 11 | ||
| 12 | // error | |
| 13 | // target=native | |
| 14 | // | |
| 15 | // :4:5: error: duplicate union field: 'a' | |
| 16 | // :3:5: note: other field here | |
| 17 | // :2:11: note: union declared here |
test/cases/compile_errors/stage2/union_duplicate_field_definition.zig deleted-16| ... | ... | @@ -1,16 +0,0 @@ |
| 1 | const U = union { | |
| 2 | foo: u32, | |
| 3 | foo: u32, | |
| 4 | }; | |
| 5 | ||
| 6 | export fn entry() void { | |
| 7 | const u: U = .{ .foo = 100 }; | |
| 8 | _ = u; | |
| 9 | } | |
| 10 | ||
| 11 | // error | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // :3:5: error: duplicate union field: 'foo' | |
| 15 | // :2:5: note: other field here | |
| 16 | // :1:11: note: union declared here |
test/cases/compile_errors/stage2/union_enum_field_missing.zig deleted-21| ... | ... | @@ -1,21 +0,0 @@ |
| 1 | const E = enum { | |
| 2 | a, | |
| 3 | b, | |
| 4 | c, | |
| 5 | }; | |
| 6 | ||
| 7 | const U = union(E) { | |
| 8 | a: i32, | |
| 9 | b: f64, | |
| 10 | }; | |
| 11 | ||
| 12 | export fn entry() usize { | |
| 13 | return @sizeOf(U); | |
| 14 | } | |
| 15 | ||
| 16 | // error | |
| 17 | // target=native | |
| 18 | // | |
| 19 | // :7:11: error: enum field(s) missing in union | |
| 20 | // :4:5: note: field 'c' missing, declared here | |
| 21 | // :1:11: note: enum declared here |
test/cases/compile_errors/stage2/union_extra_field.zig deleted-20| ... | ... | @@ -1,20 +0,0 @@ |
| 1 | const E = enum { | |
| 2 | a, | |
| 3 | b, | |
| 4 | c, | |
| 5 | }; | |
| 6 | const U = union(E) { | |
| 7 | a: i32, | |
| 8 | b: f64, | |
| 9 | c: f64, | |
| 10 | d: f64, | |
| 11 | }; | |
| 12 | export fn entry() usize { | |
| 13 | return @sizeOf(U); | |
| 14 | } | |
| 15 | ||
| 16 | // error | |
| 17 | // target=native | |
| 18 | // | |
| 19 | // :10:5: error: no field named 'd' in enum 'tmp.E' | |
| 20 | // :1:11: note: enum declared here |
test/cases/compile_errors/stage2/union_runtime_coercion_from_enum.zig deleted-23| ... | ... | @@ -1,23 +0,0 @@ |
| 1 | const E = enum { | |
| 2 | a, | |
| 3 | b, | |
| 4 | }; | |
| 5 | const U = union(E) { | |
| 6 | a: u32, | |
| 7 | b: u64, | |
| 8 | }; | |
| 9 | fn foo() E { | |
| 10 | return E.b; | |
| 11 | } | |
| 12 | export fn doTheTest() u64 { | |
| 13 | var u: U = foo(); | |
| 14 | return u.b; | |
| 15 | } | |
| 16 | ||
| 17 | // error | |
| 18 | // target=native | |
| 19 | // | |
| 20 | // :13:19: error: runtime coercion from enum 'tmp.E' to union 'tmp.U' which has non-void fields | |
| 21 | // :6:5: note: field 'a' has type 'u32' | |
| 22 | // :7:5: note: field 'b' has type 'u64' | |
| 23 | // :5:11: note: union declared here |
test/cases/compile_errors/struct_duplicate_field_name.zig created+16| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | const S = struct { | |
| 2 | foo: u32, | |
| 3 | foo: u32, | |
| 4 | }; | |
| 5 | ||
| 6 | export fn entry() void { | |
| 7 | const s: S = .{ .foo = 100 }; | |
| 8 | _ = s; | |
| 9 | } | |
| 10 | ||
| 11 | // error | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // :3:5: error: duplicate struct field: 'foo' | |
| 15 | // :2:5: note: other field here | |
| 16 | // :1:11: note: struct declared here |
test/cases/compile_errors/tuple_ptr_to_mut_slice.zig created+32| ... | ... | @@ -0,0 +1,32 @@ |
| 1 | export fn entry1() void { | |
| 2 | var a = .{ 1, 2, 3 }; | |
| 3 | _ = @as([]u8, &a); | |
| 4 | } | |
| 5 | export fn entry2() void { | |
| 6 | var a = .{ @as(u8, 1), @as(u8, 2), @as(u8, 3) }; | |
| 7 | _ = @as([]u8, &a); | |
| 8 | } | |
| 9 | ||
| 10 | // runtime values | |
| 11 | var vals = [_]u7{ 4, 5, 6 }; | |
| 12 | export fn entry3() void { | |
| 13 | var a = .{ vals[0], vals[1], vals[2] }; | |
| 14 | _ = @as([]u8, &a); | |
| 15 | } | |
| 16 | export fn entry4() void { | |
| 17 | var a = .{ @as(u8, vals[0]), @as(u8, vals[1]), @as(u8, vals[2]) }; | |
| 18 | _ = @as([]u8, &a); | |
| 19 | } | |
| 20 | ||
| 21 | // error | |
| 22 | // backend=stage2 | |
| 23 | // target=native | |
| 24 | // | |
| 25 | // :3:19: error: cannot cast pointer to tuple to '[]u8' | |
| 26 | // :3:19: note: pointers to tuples can only coerce to constant pointers | |
| 27 | // :7:19: error: cannot cast pointer to tuple to '[]u8' | |
| 28 | // :7:19: note: pointers to tuples can only coerce to constant pointers | |
| 29 | // :14:19: error: cannot cast pointer to tuple to '[]u8' | |
| 30 | // :14:19: note: pointers to tuples can only coerce to constant pointers | |
| 31 | // :18:19: error: cannot cast pointer to tuple to '[]u8' | |
| 32 | // :18:19: note: pointers to tuples can only coerce to constant pointers |
test/cases/compile_errors/union_access_of_inactive_field.zig created+15| ... | ... | @@ -0,0 +1,15 @@ |
| 1 | const U = union { | |
| 2 | a: void, | |
| 3 | b: u64, | |
| 4 | }; | |
| 5 | comptime { | |
| 6 | var u: U = .{ .a = {} }; | |
| 7 | const v = u.b; | |
| 8 | _ = v; | |
| 9 | } | |
| 10 | ||
| 11 | // error | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // :7:16: error: access of union field 'b' while field 'a' is active | |
| 15 | // :1:11: note: union declared here |
test/cases/compile_errors/union_auto-enum_value_already_taken.zig created+18| ... | ... | @@ -0,0 +1,18 @@ |
| 1 | const MultipleChoice = union(enum(u32)) { | |
| 2 | A = 20, | |
| 3 | B = 40, | |
| 4 | C = 60, | |
| 5 | D = 1000, | |
| 6 | E = 60, | |
| 7 | }; | |
| 8 | export fn entry() void { | |
| 9 | var x = MultipleChoice { .C = {} }; | |
| 10 | _ = x; | |
| 11 | } | |
| 12 | ||
| 13 | // error | |
| 14 | // backend=stage2 | |
| 15 | // target=native | |
| 16 | // | |
| 17 | // :6:5: error: enum tag value 60 already taken | |
| 18 | // :4:5: note: other occurrence here |
test/cases/compile_errors/union_duplicate_enum_field.zig created+17| ... | ... | @@ -0,0 +1,17 @@ |
| 1 | const E = enum { a, b }; | |
| 2 | const U = union(E) { | |
| 3 | a: u32, | |
| 4 | a: u32, | |
| 5 | }; | |
| 6 | ||
| 7 | export fn foo() void { | |
| 8 | var u: U = .{ .a = 123 }; | |
| 9 | _ = u; | |
| 10 | } | |
| 11 | ||
| 12 | // error | |
| 13 | // target=native | |
| 14 | // | |
| 15 | // :4:5: error: duplicate union field: 'a' | |
| 16 | // :3:5: note: other field here | |
| 17 | // :2:11: note: union declared here |
test/cases/compile_errors/union_duplicate_field_definition.zig created+16| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | const U = union { | |
| 2 | foo: u32, | |
| 3 | foo: u32, | |
| 4 | }; | |
| 5 | ||
| 6 | export fn entry() void { | |
| 7 | const u: U = .{ .foo = 100 }; | |
| 8 | _ = u; | |
| 9 | } | |
| 10 | ||
| 11 | // error | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // :3:5: error: duplicate union field: 'foo' | |
| 15 | // :2:5: note: other field here | |
| 16 | // :1:11: note: union declared here |
test/cases/compile_errors/union_enum_field_does_not_match_enum.zig created+22| ... | ... | @@ -0,0 +1,22 @@ |
| 1 | const Letter = enum { | |
| 2 | A, | |
| 3 | B, | |
| 4 | C, | |
| 5 | }; | |
| 6 | const Payload = union(Letter) { | |
| 7 | A: i32, | |
| 8 | B: f64, | |
| 9 | C: bool, | |
| 10 | D: bool, | |
| 11 | }; | |
| 12 | export fn entry() void { | |
| 13 | var a = Payload {.A = 1234}; | |
| 14 | _ = a; | |
| 15 | } | |
| 16 | ||
| 17 | // error | |
| 18 | // backend=stage2 | |
| 19 | // target=native | |
| 20 | // | |
| 21 | // :10:5: error: no field named 'D' in enum 'tmp.Letter' | |
| 22 | // :1:16: note: enum declared here |
test/cases/compile_errors/union_enum_field_missing.zig created+21| ... | ... | @@ -0,0 +1,21 @@ |
| 1 | const E = enum { | |
| 2 | a, | |
| 3 | b, | |
| 4 | c, | |
| 5 | }; | |
| 6 | ||
| 7 | const U = union(E) { | |
| 8 | a: i32, | |
| 9 | b: f64, | |
| 10 | }; | |
| 11 | ||
| 12 | export fn entry() usize { | |
| 13 | return @sizeOf(U); | |
| 14 | } | |
| 15 | ||
| 16 | // error | |
| 17 | // target=native | |
| 18 | // | |
| 19 | // :7:11: error: enum field(s) missing in union | |
| 20 | // :4:5: note: field 'c' missing, declared here | |
| 21 | // :1:11: note: enum declared here |
test/cases/compile_errors/union_extra_field.zig created+20| ... | ... | @@ -0,0 +1,20 @@ |
| 1 | const E = enum { | |
| 2 | a, | |
| 3 | b, | |
| 4 | c, | |
| 5 | }; | |
| 6 | const U = union(E) { | |
| 7 | a: i32, | |
| 8 | b: f64, | |
| 9 | c: f64, | |
| 10 | d: f64, | |
| 11 | }; | |
| 12 | export fn entry() usize { | |
| 13 | return @sizeOf(U); | |
| 14 | } | |
| 15 | ||
| 16 | // error | |
| 17 | // target=native | |
| 18 | // | |
| 19 | // :10:5: error: no field named 'd' in enum 'tmp.E' | |
| 20 | // :1:11: note: enum declared here |
test/cases/compile_errors/union_runtime_coercion_from_enum.zig created+23| ... | ... | @@ -0,0 +1,23 @@ |
| 1 | const E = enum { | |
| 2 | a, | |
| 3 | b, | |
| 4 | }; | |
| 5 | const U = union(E) { | |
| 6 | a: u32, | |
| 7 | b: u64, | |
| 8 | }; | |
| 9 | fn foo() E { | |
| 10 | return E.b; | |
| 11 | } | |
| 12 | export fn doTheTest() u64 { | |
| 13 | var u: U = foo(); | |
| 14 | return u.b; | |
| 15 | } | |
| 16 | ||
| 17 | // error | |
| 18 | // target=native | |
| 19 | // | |
| 20 | // :13:19: error: runtime coercion from enum 'tmp.E' to union 'tmp.U' which has non-void fields | |
| 21 | // :6:5: note: field 'a' has type 'u32' | |
| 22 | // :7:5: note: field 'b' has type 'u64' | |
| 23 | // :5:11: note: union declared here |
test/cases/compile_errors/union_with_too_small_explicit_signed_tag_type.zig created+16| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | const U = union(enum(i2)) { | |
| 2 | A: u8, | |
| 3 | B: u8, | |
| 4 | C: u8, | |
| 5 | D: u8, | |
| 6 | }; | |
| 7 | export fn entry() void { | |
| 8 | _ = U{ .D = 1 }; | |
| 9 | } | |
| 10 | ||
| 11 | // error | |
| 12 | // backend=stage2 | |
| 13 | // target=native | |
| 14 | // | |
| 15 | // :1:22: error: specified integer tag type cannot represent every field | |
| 16 | // :1:22: note: type 'i2' cannot fit values in range 0...3 |
test/cases/compile_errors/union_with_too_small_explicit_unsigned_tag_type.zig created+17| ... | ... | @@ -0,0 +1,17 @@ |
| 1 | const U = union(enum(u2)) { | |
| 2 | A: u8, | |
| 3 | B: u8, | |
| 4 | C: u8, | |
| 5 | D: u8, | |
| 6 | E: u8, | |
| 7 | }; | |
| 8 | export fn entry() void { | |
| 9 | _ = U{ .E = 1 }; | |
| 10 | } | |
| 11 | ||
| 12 | // error | |
| 13 | // backend=stage2 | |
| 14 | // target=native | |
| 15 | // | |
| 16 | // :1:22: error: specified integer tag type cannot represent every field | |
| 17 | // :1:22: note: type 'u2' cannot fit values in range 0...4 |
test/cases/compile_errors/wrong_function_type.zig created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | const fns = [_]fn() void { a, b, c }; | |
| 2 | fn a() i32 {return 0;} | |
| 3 | fn b() i32 {return 1;} | |
| 4 | fn c() i32 {return 2;} | |
| 5 | export fn entry() usize { return @sizeOf(@TypeOf(fns)); } | |
| 6 | ||
| 7 | // error | |
| 8 | // backend=stage2 | |
| 9 | // target=native | |
| 10 | // | |
| 11 | // :1:28: error: expected type 'fn() void', found 'fn() i32' | |
| 12 | // :1:28: note: return type 'i32' cannot cast into return type 'void' |