| author | |
| committer | |
| log | 927d20b46b5e959aeaa92cb6a1e782ad13c25e01 |
| tree | 8dfd033bfd8fc158ab90d0d0270cc883a9724e82 |
| parent | 423d7a74a479c1fae16024daed8edfbb2cf1b857 |
64 files changed, 680 insertions(+), 514 deletions(-)
src/Sema.zig+233-50| ... | ... | @@ -4109,6 +4109,8 @@ fn validateUnionInit( |
| 4109 | 4109 | const union_init = try sema.addConstant(union_ty, union_val); |
| 4110 | 4110 | try sema.storePtr2(block, init_src, union_ptr, init_src, union_init, init_src, .store); |
| 4111 | 4111 | return; |
| 4112 | } else if (try sema.typeRequiresComptime(union_ty)) { | |
| 4113 | return sema.failWithNeededComptime(block, field_ptr_data.src(), "initializer of comptime only union must be comptime-known"); | |
| 4112 | 4114 | } |
| 4113 | 4115 | |
| 4114 | 4116 | const new_tag = try sema.addConstant(tag_ty, tag_val); |
| ... | ... | @@ -4226,6 +4228,7 @@ fn validateStructInit( |
| 4226 | 4228 | var first_block_index = block.instructions.items.len; |
| 4227 | 4229 | var make_runtime = false; |
| 4228 | 4230 | |
| 4231 | const require_comptime = try sema.typeRequiresComptime(struct_ty); | |
| 4229 | 4232 | const air_tags = sema.air_instructions.items(.tag); |
| 4230 | 4233 | const air_datas = sema.air_instructions.items(.data); |
| 4231 | 4234 | |
| ... | ... | @@ -4301,6 +4304,9 @@ fn validateStructInit( |
| 4301 | 4304 | } |
| 4302 | 4305 | if (try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(bin_op.rhs, &make_runtime)) |val| { |
| 4303 | 4306 | field_values[i] = val; |
| 4307 | } else if (require_comptime) { | |
| 4308 | const field_ptr_data = sema.code.instructions.items(.data)[field_ptr].pl_node; | |
| 4309 | return sema.failWithNeededComptime(block, field_ptr_data.src(), "initializer of comptime only struct must be comptime-known"); | |
| 4304 | 4310 | } else { |
| 4305 | 4311 | struct_is_comptime = false; |
| 4306 | 4312 | } |
| ... | ... | @@ -5402,7 +5408,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 5402 | 5408 | const options = sema.resolveExportOptions(block, .unneeded, extra.options) catch |err| switch (err) { |
| 5403 | 5409 | error.NeededSourceLocation => { |
| 5404 | 5410 | _ = try sema.resolveExportOptions(block, options_src, extra.options); |
| 5405 | return error.AnalysisFail; | |
| 5411 | unreachable; | |
| 5406 | 5412 | }, |
| 5407 | 5413 | else => |e| return e, |
| 5408 | 5414 | }; |
| ... | ... | @@ -5429,7 +5435,7 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 5429 | 5435 | const options = sema.resolveExportOptions(block, .unneeded, extra.options) catch |err| switch (err) { |
| 5430 | 5436 | error.NeededSourceLocation => { |
| 5431 | 5437 | _ = try sema.resolveExportOptions(block, options_src, extra.options); |
| 5432 | return error.AnalysisFail; | |
| 5438 | unreachable; | |
| 5433 | 5439 | }, |
| 5434 | 5440 | else => |e| return e, |
| 5435 | 5441 | }; |
| ... | ... | @@ -6512,7 +6518,7 @@ fn analyzeCall( |
| 6512 | 6518 | func_ty_info.param_types, |
| 6513 | 6519 | func, |
| 6514 | 6520 | ); |
| 6515 | return error.AnalysisFail; | |
| 6521 | unreachable; | |
| 6516 | 6522 | }, |
| 6517 | 6523 | else => |e| return e, |
| 6518 | 6524 | }; |
| ... | ... | @@ -6674,7 +6680,7 @@ fn analyzeCall( |
| 6674 | 6680 | uncasted_arg, |
| 6675 | 6681 | opts, |
| 6676 | 6682 | ); |
| 6677 | return error.AnalysisFail; | |
| 6683 | unreachable; | |
| 6678 | 6684 | }, |
| 6679 | 6685 | else => |e| return e, |
| 6680 | 6686 | }; |
| ... | ... | @@ -6687,7 +6693,7 @@ fn analyzeCall( |
| 6687 | 6693 | uncasted_arg, |
| 6688 | 6694 | Module.argSrc(call_src.node_offset.x, sema.gpa, decl, i, bound_arg_src), |
| 6689 | 6695 | ); |
| 6690 | return error.AnalysisFail; | |
| 6696 | unreachable; | |
| 6691 | 6697 | }, |
| 6692 | 6698 | else => |e| return e, |
| 6693 | 6699 | }; |
| ... | ... | @@ -6991,7 +6997,7 @@ fn instantiateGenericCall( |
| 6991 | 6997 | const decl = sema.mod.declPtr(block.src_decl); |
| 6992 | 6998 | const arg_src = Module.argSrc(call_src.node_offset.x, sema.gpa, decl, i, bound_arg_src); |
| 6993 | 6999 | _ = try sema.analyzeGenericCallArgVal(block, arg_src, uncasted_args[i]); |
| 6994 | return error.AnalysisFail; | |
| 7000 | unreachable; | |
| 6995 | 7001 | }, |
| 6996 | 7002 | else => |e| return e, |
| 6997 | 7003 | }; |
| ... | ... | @@ -7174,7 +7180,7 @@ fn instantiateGenericCall( |
| 7174 | 7180 | const decl = sema.mod.declPtr(block.src_decl); |
| 7175 | 7181 | const arg_src = Module.argSrc(call_src.node_offset.x, sema.gpa, decl, arg_i, bound_arg_src); |
| 7176 | 7182 | _ = try sema.resolveConstValue(block, arg_src, arg, "argument to parameter with comptime-only type must be comptime-known"); |
| 7177 | return error.AnalysisFail; | |
| 7183 | unreachable; | |
| 7178 | 7184 | }, |
| 7179 | 7185 | else => |e| return e, |
| 7180 | 7186 | }; |
| ... | ... | @@ -7330,7 +7336,7 @@ fn instantiateGenericCall( |
| 7330 | 7336 | new_fn_info, |
| 7331 | 7337 | &runtime_i, |
| 7332 | 7338 | ); |
| 7333 | return error.AnalysisFail; | |
| 7339 | unreachable; | |
| 7334 | 7340 | }, |
| 7335 | 7341 | else => |e| return e, |
| 7336 | 7342 | }; |
| ... | ... | @@ -8417,6 +8423,10 @@ fn funcCommon( |
| 8417 | 8423 | const param_types = try sema.arena.alloc(Type, block.params.items.len); |
| 8418 | 8424 | const comptime_params = try sema.arena.alloc(bool, block.params.items.len); |
| 8419 | 8425 | for (block.params.items) |param, i| { |
| 8426 | const is_noalias = blk: { | |
| 8427 | const index = std.math.cast(u5, i) orelse break :blk false; | |
| 8428 | break :blk @truncate(u1, noalias_bits >> index) != 0; | |
| 8429 | }; | |
| 8420 | 8430 | param_types[i] = param.ty; |
| 8421 | 8431 | sema.analyzeParameter( |
| 8422 | 8432 | block, |
| ... | ... | @@ -8427,6 +8437,7 @@ fn funcCommon( |
| 8427 | 8437 | &is_generic, |
| 8428 | 8438 | cc_resolved, |
| 8429 | 8439 | has_body, |
| 8440 | is_noalias, | |
| 8430 | 8441 | ) catch |err| switch (err) { |
| 8431 | 8442 | error.NeededSourceLocation => { |
| 8432 | 8443 | const decl = sema.mod.declPtr(block.src_decl); |
| ... | ... | @@ -8439,8 +8450,9 @@ fn funcCommon( |
| 8439 | 8450 | &is_generic, |
| 8440 | 8451 | cc_resolved, |
| 8441 | 8452 | has_body, |
| 8453 | is_noalias, | |
| 8442 | 8454 | ); |
| 8443 | return error.AnalysisFail; | |
| 8455 | unreachable; | |
| 8444 | 8456 | }, |
| 8445 | 8457 | else => |e| return e, |
| 8446 | 8458 | }; |
| ... | ... | @@ -8689,6 +8701,7 @@ fn analyzeParameter( |
| 8689 | 8701 | is_generic: *bool, |
| 8690 | 8702 | cc: std.builtin.CallingConvention, |
| 8691 | 8703 | has_body: bool, |
| 8704 | is_noalias: bool, | |
| 8692 | 8705 | ) !void { |
| 8693 | 8706 | const requires_comptime = try sema.typeRequiresComptime(param.ty); |
| 8694 | 8707 | comptime_params[i] = param.is_comptime or requires_comptime; |
| ... | ... | @@ -8743,6 +8756,9 @@ fn analyzeParameter( |
| 8743 | 8756 | }; |
| 8744 | 8757 | return sema.failWithOwnedErrorMsg(msg); |
| 8745 | 8758 | } |
| 8759 | if (!this_generic and is_noalias and !param.ty.isPtrAtRuntime()) { | |
| 8760 | return sema.fail(block, param_src, "non-pointer parameter declared noalias", .{}); | |
| 8761 | } | |
| 8746 | 8762 | } |
| 8747 | 8763 | |
| 8748 | 8764 | fn zirParam( |
| ... | ... | @@ -10633,7 +10649,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10633 | 10649 | const case_src = Module.SwitchProngSrc{ .range = .{ .prong = multi_i, .item = range_i } }; |
| 10634 | 10650 | const decl = sema.mod.declPtr(case_block.src_decl); |
| 10635 | 10651 | try sema.emitBackwardBranch(block, case_src.resolve(sema.gpa, decl, src_node_offset, .none)); |
| 10636 | return error.AnalysisFail; | |
| 10652 | unreachable; | |
| 10637 | 10653 | }, |
| 10638 | 10654 | else => return err, |
| 10639 | 10655 | }; |
| ... | ... | @@ -10669,7 +10685,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10669 | 10685 | const case_src = Module.SwitchProngSrc{ .multi = .{ .prong = multi_i, .item = @intCast(u32, item_i) } }; |
| 10670 | 10686 | const decl = sema.mod.declPtr(case_block.src_decl); |
| 10671 | 10687 | try sema.emitBackwardBranch(block, case_src.resolve(sema.gpa, decl, src_node_offset, .none)); |
| 10672 | return error.AnalysisFail; | |
| 10688 | unreachable; | |
| 10673 | 10689 | }, |
| 10674 | 10690 | else => return err, |
| 10675 | 10691 | }; |
| ... | ... | @@ -11101,10 +11117,8 @@ fn resolveSwitchItemVal( |
| 11101 | 11117 | } else |err| switch (err) { |
| 11102 | 11118 | error.NeededSourceLocation => { |
| 11103 | 11119 | 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 | }; | |
| 11120 | _ = try sema.resolveConstValue(block, src, item, "switch prong values must be comptime-known"); | |
| 11121 | unreachable; | |
| 11108 | 11122 | }, |
| 11109 | 11123 | else => |e| return e, |
| 11110 | 11124 | } |
| ... | ... | @@ -11618,6 +11632,21 @@ fn zirShl( |
| 11618 | 11632 | }); |
| 11619 | 11633 | } |
| 11620 | 11634 | } |
| 11635 | if (rhs_ty.zigTypeTag() == .Vector) { | |
| 11636 | var i: usize = 0; | |
| 11637 | while (i < rhs_ty.vectorLen()) : (i += 1) { | |
| 11638 | if (rhs_val.indexVectorlike(i).compareHetero(.lt, Value.zero, target)) { | |
| 11639 | return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{ | |
| 11640 | rhs_val.indexVectorlike(i).fmtValue(scalar_ty, sema.mod), | |
| 11641 | i, | |
| 11642 | }); | |
| 11643 | } | |
| 11644 | } | |
| 11645 | } else if (rhs_val.compareHetero(.lt, Value.zero, target)) { | |
| 11646 | return sema.fail(block, rhs_src, "shift by negative amount '{}'", .{ | |
| 11647 | rhs_val.fmtValue(scalar_ty, sema.mod), | |
| 11648 | }); | |
| 11649 | } | |
| 11621 | 11650 | } |
| 11622 | 11651 | |
| 11623 | 11652 | const runtime_src = if (maybe_lhs_val) |lhs_val| rs: { |
| ... | ... | @@ -11787,6 +11816,21 @@ fn zirShr( |
| 11787 | 11816 | }); |
| 11788 | 11817 | } |
| 11789 | 11818 | } |
| 11819 | if (rhs_ty.zigTypeTag() == .Vector) { | |
| 11820 | var i: usize = 0; | |
| 11821 | while (i < rhs_ty.vectorLen()) : (i += 1) { | |
| 11822 | if (rhs_val.indexVectorlike(i).compareHetero(.lt, Value.zero, target)) { | |
| 11823 | return sema.fail(block, rhs_src, "shift by negative amount '{}' at index '{d}'", .{ | |
| 11824 | rhs_val.indexVectorlike(i).fmtValue(scalar_ty, sema.mod), | |
| 11825 | i, | |
| 11826 | }); | |
| 11827 | } | |
| 11828 | } | |
| 11829 | } else if (rhs_val.compareHetero(.lt, Value.zero, target)) { | |
| 11830 | return sema.fail(block, rhs_src, "shift by negative amount '{}'", .{ | |
| 11831 | rhs_val.fmtValue(scalar_ty, sema.mod), | |
| 11832 | }); | |
| 11833 | } | |
| 11790 | 11834 | if (maybe_lhs_val) |lhs_val| { |
| 11791 | 11835 | if (lhs_val.isUndef()) { |
| 11792 | 11836 | return sema.addConstUndef(lhs_ty); |
| ... | ... | @@ -14721,7 +14765,9 @@ fn analyzeCmp( |
| 14721 | 14765 | ) CompileError!Air.Inst.Ref { |
| 14722 | 14766 | const lhs_ty = sema.typeOf(lhs); |
| 14723 | 14767 | const rhs_ty = sema.typeOf(rhs); |
| 14724 | try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src); | |
| 14768 | if (lhs_ty.zigTypeTag() != .Optional and rhs_ty.zigTypeTag() != .Optional) { | |
| 14769 | try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src); | |
| 14770 | } | |
| 14725 | 14771 | |
| 14726 | 14772 | if (lhs_ty.zigTypeTag() == .Vector and rhs_ty.zigTypeTag() == .Vector) { |
| 14727 | 14773 | return sema.cmpVector(block, src, lhs, rhs, op, lhs_src, rhs_src); |
| ... | ... | @@ -15217,12 +15263,17 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15217 | 15263 | try Value.Tag.ty.create(params_anon_decl.arena(), try param_ty.copy(params_anon_decl.arena())), |
| 15218 | 15264 | ); |
| 15219 | 15265 | |
| 15266 | const is_noalias = blk: { | |
| 15267 | const index = std.math.cast(u5, i) orelse break :blk false; | |
| 15268 | break :blk @truncate(u1, info.noalias_bits >> index) != 0; | |
| 15269 | }; | |
| 15270 | ||
| 15220 | 15271 | const param_fields = try params_anon_decl.arena().create([3]Value); |
| 15221 | 15272 | param_fields.* = .{ |
| 15222 | 15273 | // is_generic: bool, |
| 15223 | 15274 | Value.makeBool(is_generic), |
| 15224 | 15275 | // is_noalias: bool, |
| 15225 | Value.false, // TODO | |
| 15276 | Value.makeBool(is_noalias), | |
| 15226 | 15277 | // arg_type: ?type, |
| 15227 | 15278 | param_ty_val, |
| 15228 | 15279 | }; |
| ... | ... | @@ -17409,7 +17460,7 @@ fn zirStructInitAnon( |
| 17409 | 17460 | const decl = sema.mod.declPtr(block.src_decl); |
| 17410 | 17461 | const field_src = Module.initSrc(src.node_offset.x, sema.gpa, decl, runtime_index); |
| 17411 | 17462 | try sema.requireRuntimeBlock(block, src, field_src); |
| 17412 | return error.AnalysisFail; | |
| 17463 | unreachable; | |
| 17413 | 17464 | }, |
| 17414 | 17465 | else => |e| return e, |
| 17415 | 17466 | }; |
| ... | ... | @@ -17474,25 +17525,31 @@ fn zirArrayInit( |
| 17474 | 17525 | defer gpa.free(resolved_args); |
| 17475 | 17526 | for (args[1..]) |arg, i| { |
| 17476 | 17527 | const resolved_arg = try sema.resolveInst(arg); |
| 17477 | const arg_src = src; // TODO better source location | |
| 17478 | 17528 | const elem_ty = if (array_ty.zigTypeTag() == .Struct) |
| 17479 | 17529 | array_ty.structFieldType(i) |
| 17480 | 17530 | else |
| 17481 | 17531 | array_ty.elemType2(); |
| 17482 | resolved_args[i] = try sema.coerce(block, elem_ty, resolved_arg, arg_src); | |
| 17532 | resolved_args[i] = sema.coerce(block, elem_ty, resolved_arg, .unneeded) catch |err| switch (err) { | |
| 17533 | error.NeededSourceLocation => { | |
| 17534 | const decl = sema.mod.declPtr(block.src_decl); | |
| 17535 | const elem_src = Module.initSrc(src.node_offset.x, sema.gpa, decl, i); | |
| 17536 | _ = try sema.coerce(block, elem_ty, resolved_arg, elem_src); | |
| 17537 | unreachable; | |
| 17538 | }, | |
| 17539 | else => return err, | |
| 17540 | }; | |
| 17483 | 17541 | } |
| 17484 | 17542 | |
| 17485 | 17543 | if (sentinel_val) |some| { |
| 17486 | 17544 | resolved_args[resolved_args.len - 1] = try sema.addConstant(array_ty.elemType2(), some); |
| 17487 | 17545 | } |
| 17488 | 17546 | |
| 17489 | const opt_runtime_src: ?LazySrcLoc = for (resolved_args) |arg| { | |
| 17490 | const arg_src = src; // TODO better source location | |
| 17547 | const opt_runtime_index: ?u32 = for (resolved_args) |arg, i| { | |
| 17491 | 17548 | const comptime_known = try sema.isComptimeKnown(arg); |
| 17492 | if (!comptime_known) break arg_src; | |
| 17549 | if (!comptime_known) break @intCast(u32, i); | |
| 17493 | 17550 | } else null; |
| 17494 | 17551 | |
| 17495 | const runtime_src = opt_runtime_src orelse { | |
| 17552 | const runtime_index = opt_runtime_index orelse { | |
| 17496 | 17553 | const elem_vals = try sema.arena.alloc(Value, resolved_args.len); |
| 17497 | 17554 | |
| 17498 | 17555 | for (resolved_args) |arg, i| { |
| ... | ... | @@ -17504,7 +17561,15 @@ fn zirArrayInit( |
| 17504 | 17561 | return sema.addConstantMaybeRef(block, array_ty, array_val, is_ref); |
| 17505 | 17562 | }; |
| 17506 | 17563 | |
| 17507 | try sema.requireRuntimeBlock(block, src, runtime_src); | |
| 17564 | sema.requireRuntimeBlock(block, src, .unneeded) catch |err| switch (err) { | |
| 17565 | error.NeededSourceLocation => { | |
| 17566 | const decl = sema.mod.declPtr(block.src_decl); | |
| 17567 | const elem_src = Module.initSrc(src.node_offset.x, sema.gpa, decl, runtime_index); | |
| 17568 | try sema.requireRuntimeBlock(block, src, elem_src); | |
| 17569 | unreachable; | |
| 17570 | }, | |
| 17571 | else => return err, | |
| 17572 | }; | |
| 17508 | 17573 | try sema.queueFullTypeResolution(array_ty); |
| 17509 | 17574 | |
| 17510 | 17575 | if (is_ref) { |
| ... | ... | @@ -18502,10 +18567,47 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in |
| 18502 | 18567 | } |
| 18503 | 18568 | |
| 18504 | 18569 | var buffer: Value.ToTypeBuffer = undefined; |
| 18570 | const field_ty = try field_type_val.toType(&buffer).copy(new_decl_arena_allocator); | |
| 18505 | 18571 | gop.value_ptr.* = .{ |
| 18506 | .ty = try field_type_val.toType(&buffer).copy(new_decl_arena_allocator), | |
| 18572 | .ty = field_ty, | |
| 18507 | 18573 | .abi_align = @intCast(u32, (try alignment_val.getUnsignedIntAdvanced(target, sema)).?), |
| 18508 | 18574 | }; |
| 18575 | ||
| 18576 | if (field_ty.zigTypeTag() == .Opaque) { | |
| 18577 | const msg = msg: { | |
| 18578 | const msg = try sema.errMsg(block, src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{}); | |
| 18579 | errdefer msg.destroy(sema.gpa); | |
| 18580 | ||
| 18581 | try sema.addDeclaredHereNote(msg, field_ty); | |
| 18582 | break :msg msg; | |
| 18583 | }; | |
| 18584 | return sema.failWithOwnedErrorMsg(msg); | |
| 18585 | } | |
| 18586 | if (union_obj.layout == .Extern and !try sema.validateExternType(field_ty, .union_field)) { | |
| 18587 | const msg = msg: { | |
| 18588 | const msg = try sema.errMsg(block, src, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)}); | |
| 18589 | errdefer msg.destroy(sema.gpa); | |
| 18590 | ||
| 18591 | const src_decl = sema.mod.declPtr(block.src_decl); | |
| 18592 | try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl), field_ty, .union_field); | |
| 18593 | ||
| 18594 | try sema.addDeclaredHereNote(msg, field_ty); | |
| 18595 | break :msg msg; | |
| 18596 | }; | |
| 18597 | return sema.failWithOwnedErrorMsg(msg); | |
| 18598 | } else if (union_obj.layout == .Packed and !(validatePackedType(field_ty))) { | |
| 18599 | const msg = msg: { | |
| 18600 | const msg = try sema.errMsg(block, src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)}); | |
| 18601 | errdefer msg.destroy(sema.gpa); | |
| 18602 | ||
| 18603 | const src_decl = sema.mod.declPtr(block.src_decl); | |
| 18604 | try sema.explainWhyTypeIsNotPacked(msg, src.toSrcLoc(src_decl), field_ty); | |
| 18605 | ||
| 18606 | try sema.addDeclaredHereNote(msg, field_ty); | |
| 18607 | break :msg msg; | |
| 18608 | }; | |
| 18609 | return sema.failWithOwnedErrorMsg(msg); | |
| 18610 | } | |
| 18509 | 18611 | } |
| 18510 | 18612 | |
| 18511 | 18613 | if (tag_ty_field_names) |names| { |
| ... | ... | @@ -18587,21 +18689,25 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in |
| 18587 | 18689 | // is_noalias: bool, |
| 18588 | 18690 | const arg_is_noalias = arg_val[1].toBool(); |
| 18589 | 18691 | // arg_type: ?type, |
| 18590 | const param_type_val = arg_val[2]; | |
| 18692 | const param_type_opt_val = arg_val[2]; | |
| 18591 | 18693 | |
| 18592 | 18694 | if (arg_is_generic) { |
| 18593 | 18695 | return sema.fail(block, src, "Type.Fn.Param.is_generic must be false for @Type", .{}); |
| 18594 | 18696 | } |
| 18595 | 18697 | |
| 18698 | const param_type_val = param_type_opt_val.optionalValue() orelse | |
| 18699 | return sema.fail(block, src, "Type.Fn.Param.arg_type must be non-null for @Type", .{}); | |
| 18700 | const param_type = try param_type_val.toType(&buf).copy(sema.arena); | |
| 18701 | ||
| 18596 | 18702 | if (arg_is_noalias) { |
| 18597 | noalias_bits = @as(u32, 1) << (std.math.cast(u5, i) orelse | |
| 18703 | if (!param_type.isPtrAtRuntime()) { | |
| 18704 | return sema.fail(block, src, "non-pointer parameter declared noalias", .{}); | |
| 18705 | } | |
| 18706 | noalias_bits |= @as(u32, 1) << (std.math.cast(u5, i) orelse | |
| 18598 | 18707 | return sema.fail(block, src, "this compiler implementation only supports 'noalias' on the first 32 parameters", .{})); |
| 18599 | 18708 | } |
| 18600 | 18709 | |
| 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); | |
| 18710 | param_types[i] = param_type; | |
| 18605 | 18711 | comptime_params[i] = false; |
| 18606 | 18712 | } |
| 18607 | 18713 | |
| ... | ... | @@ -18745,13 +18851,60 @@ fn reifyStruct( |
| 18745 | 18851 | } |
| 18746 | 18852 | |
| 18747 | 18853 | var buffer: Value.ToTypeBuffer = undefined; |
| 18854 | const field_ty = try field_type_val.toType(&buffer).copy(new_decl_arena_allocator); | |
| 18748 | 18855 | gop.value_ptr.* = .{ |
| 18749 | .ty = try field_type_val.toType(&buffer).copy(new_decl_arena_allocator), | |
| 18856 | .ty = field_ty, | |
| 18750 | 18857 | .abi_align = abi_align, |
| 18751 | 18858 | .default_val = default_val, |
| 18752 | 18859 | .is_comptime = is_comptime_val.toBool(), |
| 18753 | 18860 | .offset = undefined, |
| 18754 | 18861 | }; |
| 18862 | ||
| 18863 | if (field_ty.zigTypeTag() == .Opaque) { | |
| 18864 | const msg = msg: { | |
| 18865 | const msg = try sema.errMsg(block, src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{}); | |
| 18866 | errdefer msg.destroy(sema.gpa); | |
| 18867 | ||
| 18868 | try sema.addDeclaredHereNote(msg, field_ty); | |
| 18869 | break :msg msg; | |
| 18870 | }; | |
| 18871 | return sema.failWithOwnedErrorMsg(msg); | |
| 18872 | } | |
| 18873 | if (field_ty.zigTypeTag() == .NoReturn) { | |
| 18874 | const msg = msg: { | |
| 18875 | const msg = try sema.errMsg(block, src, "struct fields cannot be 'noreturn'", .{}); | |
| 18876 | errdefer msg.destroy(sema.gpa); | |
| 18877 | ||
| 18878 | try sema.addDeclaredHereNote(msg, field_ty); | |
| 18879 | break :msg msg; | |
| 18880 | }; | |
| 18881 | return sema.failWithOwnedErrorMsg(msg); | |
| 18882 | } | |
| 18883 | if (struct_obj.layout == .Extern and !try sema.validateExternType(field_ty, .struct_field)) { | |
| 18884 | const msg = msg: { | |
| 18885 | const msg = try sema.errMsg(block, src, "extern structs cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)}); | |
| 18886 | errdefer msg.destroy(sema.gpa); | |
| 18887 | ||
| 18888 | const src_decl = sema.mod.declPtr(block.src_decl); | |
| 18889 | try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl), field_ty, .struct_field); | |
| 18890 | ||
| 18891 | try sema.addDeclaredHereNote(msg, field_ty); | |
| 18892 | break :msg msg; | |
| 18893 | }; | |
| 18894 | return sema.failWithOwnedErrorMsg(msg); | |
| 18895 | } else if (struct_obj.layout == .Packed and !(validatePackedType(field_ty))) { | |
| 18896 | const msg = msg: { | |
| 18897 | const msg = try sema.errMsg(block, src, "packed structs cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)}); | |
| 18898 | errdefer msg.destroy(sema.gpa); | |
| 18899 | ||
| 18900 | const src_decl = sema.mod.declPtr(block.src_decl); | |
| 18901 | try sema.explainWhyTypeIsNotPacked(msg, src.toSrcLoc(src_decl), field_ty); | |
| 18902 | ||
| 18903 | try sema.addDeclaredHereNote(msg, field_ty); | |
| 18904 | break :msg msg; | |
| 18905 | }; | |
| 18906 | return sema.failWithOwnedErrorMsg(msg); | |
| 18907 | } | |
| 18755 | 18908 | } |
| 18756 | 18909 | |
| 18757 | 18910 | if (layout == .Packed) { |
| ... | ... | @@ -21544,7 +21697,7 @@ fn zirPrefetch( |
| 21544 | 21697 | const options = sema.resolvePrefetchOptions(block, .unneeded, extra.rhs) catch |err| switch (err) { |
| 21545 | 21698 | error.NeededSourceLocation => { |
| 21546 | 21699 | _ = try sema.resolvePrefetchOptions(block, opts_src, extra.rhs); |
| 21547 | return error.AnalysisFail; | |
| 21700 | unreachable; | |
| 21548 | 21701 | }, |
| 21549 | 21702 | else => |e| return e, |
| 21550 | 21703 | }; |
| ... | ... | @@ -21637,7 +21790,7 @@ fn zirBuiltinExtern( |
| 21637 | 21790 | const options = sema.resolveExternOptions(block, .unneeded, extra.rhs) catch |err| switch (err) { |
| 21638 | 21791 | error.NeededSourceLocation => { |
| 21639 | 21792 | _ = try sema.resolveExternOptions(block, options_src, extra.rhs); |
| 21640 | return error.AnalysisFail; | |
| 21793 | unreachable; | |
| 21641 | 21794 | }, |
| 21642 | 21795 | else => |e| return e, |
| 21643 | 21796 | }; |
| ... | ... | @@ -24493,7 +24646,7 @@ fn coerceExtra( |
| 24493 | 24646 | } |
| 24494 | 24647 | if (try sema.resolveMaybeUndefVal(inst)) |val| { |
| 24495 | 24648 | const result_val = try val.floatCast(sema.arena, dest_ty, target); |
| 24496 | if (!val.eql(result_val, dest_ty, sema.mod)) { | |
| 24649 | if (!val.eql(result_val, inst_ty, sema.mod)) { | |
| 24497 | 24650 | return sema.fail( |
| 24498 | 24651 | block, |
| 24499 | 24652 | inst_src, |
| ... | ... | @@ -24987,7 +25140,7 @@ const InMemoryCoercionResult = union(enum) { |
| 24987 | 25140 | cur = param.child; |
| 24988 | 25141 | }, |
| 24989 | 25142 | .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) }); | |
| 25143 | try sema.errNote(block, src, msg, "calling convention '{s}' cannot cast into calling convention '{s}'", .{ @tagName(cc.actual), @tagName(cc.wanted) }); | |
| 24991 | 25144 | break; |
| 24992 | 25145 | }, |
| 24993 | 25146 | .fn_return_type => |pair| { |
| ... | ... | @@ -26842,6 +26995,9 @@ fn coerceCompatiblePtrs( |
| 26842 | 26995 | ) !Air.Inst.Ref { |
| 26843 | 26996 | const inst_ty = sema.typeOf(inst); |
| 26844 | 26997 | if (try sema.resolveMaybeUndefVal(inst)) |val| { |
| 26998 | if (!val.isUndef() and val.isNull() and !dest_ty.isAllowzeroPtr()) { | |
| 26999 | return sema.fail(block, inst_src, "null pointer casted to type '{}'", .{dest_ty.fmt(sema.mod)}); | |
| 27000 | } | |
| 26845 | 27001 | // The comptime Value representation is compatible with both types. |
| 26846 | 27002 | return sema.addConstant(dest_ty, val); |
| 26847 | 27003 | } |
| ... | ... | @@ -30177,7 +30333,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 30177 | 30333 | const tree = try sema.getAstTree(&block_scope); |
| 30178 | 30334 | const init_src = containerFieldInitSrcLoc(decl, tree.*, 0, i); |
| 30179 | 30335 | _ = try sema.coerce(&block_scope, field.ty, init, init_src); |
| 30180 | return error.AnalysisFail; | |
| 30336 | unreachable; | |
| 30181 | 30337 | }, |
| 30182 | 30338 | else => |e| return e, |
| 30183 | 30339 | }; |
| ... | ... | @@ -30304,6 +30460,25 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 30304 | 30460 | if (int_tag_ty.zigTypeTag() != .Int and int_tag_ty.zigTypeTag() != .ComptimeInt) { |
| 30305 | 30461 | return sema.fail(&block_scope, tag_ty_src, "expected integer tag type, found '{}'", .{int_tag_ty.fmt(sema.mod)}); |
| 30306 | 30462 | } |
| 30463 | ||
| 30464 | if (fields_len > 0) { | |
| 30465 | var field_count_val: Value.Payload.U64 = .{ | |
| 30466 | .base = .{ .tag = .int_u64 }, | |
| 30467 | .data = fields_len - 1, | |
| 30468 | }; | |
| 30469 | if (!(try sema.intFitsInType(Value.initPayload(&field_count_val.base), int_tag_ty, null))) { | |
| 30470 | const msg = msg: { | |
| 30471 | const msg = try sema.errMsg(&block_scope, tag_ty_src, "specified integer tag type cannot represent every field", .{}); | |
| 30472 | errdefer msg.destroy(sema.gpa); | |
| 30473 | try sema.errNote(&block_scope, tag_ty_src, msg, "type '{}' cannot fit values in range 0...{d}", .{ | |
| 30474 | int_tag_ty.fmt(sema.mod), | |
| 30475 | fields_len - 1, | |
| 30476 | }); | |
| 30477 | break :msg msg; | |
| 30478 | }; | |
| 30479 | return sema.failWithOwnedErrorMsg(msg); | |
| 30480 | } | |
| 30481 | } | |
| 30307 | 30482 | union_obj.tag_ty = try sema.generateUnionTagTypeNumbered(&block_scope, fields_len, provided_ty, union_obj); |
| 30308 | 30483 | const enum_obj = union_obj.tag_ty.castTag(.enum_numbered).?.data; |
| 30309 | 30484 | enum_field_names = &enum_obj.fields; |
| ... | ... | @@ -30379,7 +30554,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 30379 | 30554 | } else .none; |
| 30380 | 30555 | |
| 30381 | 30556 | if (enum_value_map) |map| { |
| 30382 | if (tag_ref != .none) { | |
| 30557 | const copied_val = if (tag_ref != .none) blk: { | |
| 30383 | 30558 | const tag_src = src; // TODO better source location |
| 30384 | 30559 | const coerced = try sema.coerce(&block_scope, int_tag_ty, tag_ref, tag_src); |
| 30385 | 30560 | const val = try sema.resolveConstValue(&block_scope, tag_src, coerced, "enum tag value must be comptime-known"); |
| ... | ... | @@ -30387,23 +30562,31 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 30387 | 30562 | |
| 30388 | 30563 | // This puts the memory into the union arena, not the enum arena, but |
| 30389 | 30564 | // 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 { | |
| 30565 | break :blk try val.copy(decl_arena_allocator); | |
| 30566 | } else blk: { | |
| 30396 | 30567 | const val = if (last_tag_val) |val| |
| 30397 | 30568 | try sema.intAdd(val, Value.one, int_tag_ty) |
| 30398 | 30569 | else |
| 30399 | 30570 | Value.zero; |
| 30400 | 30571 | last_tag_val = val; |
| 30401 | 30572 | |
| 30402 | const copied_val = try val.copy(decl_arena_allocator); | |
| 30403 | map.putAssumeCapacityContext(copied_val, {}, .{ | |
| 30404 | .ty = int_tag_ty, | |
| 30405 | .mod = mod, | |
| 30406 | }); | |
| 30573 | break :blk try val.copy(decl_arena_allocator); | |
| 30574 | }; | |
| 30575 | const gop = map.getOrPutAssumeCapacityContext(copied_val, .{ | |
| 30576 | .ty = int_tag_ty, | |
| 30577 | .mod = mod, | |
| 30578 | }); | |
| 30579 | if (gop.found_existing) { | |
| 30580 | const tree = try sema.getAstTree(&block_scope); | |
| 30581 | const field_src = enumFieldSrcLoc(sema.mod.declPtr(block_scope.src_decl), tree.*, src.node_offset.x, field_i); | |
| 30582 | const other_field_src = enumFieldSrcLoc(sema.mod.declPtr(block_scope.src_decl), tree.*, src.node_offset.x, gop.index); | |
| 30583 | const msg = msg: { | |
| 30584 | const msg = try sema.errMsg(&block_scope, field_src, "enum tag value {} already taken", .{copied_val.fmtValue(int_tag_ty, sema.mod)}); | |
| 30585 | errdefer msg.destroy(gpa); | |
| 30586 | try sema.errNote(&block_scope, other_field_src, msg, "other occurrence here", .{}); | |
| 30587 | break :msg msg; | |
| 30588 | }; | |
| 30589 | return sema.failWithOwnedErrorMsg(msg); | |
| 30407 | 30590 | } |
| 30408 | 30591 | } |
| 30409 | 30592 |
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/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/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/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/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_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/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/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_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/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/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_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/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/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/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/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/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_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/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/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/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/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/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_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/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_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_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' |