| author | |
| committer | |
| log | dff1ac1089dd8a7cae5c167bdb4e6269c9b84bb6 |
| tree | ca2a2c57fcc9d948954ba346256f8e8b22139242 |
| parent | ef17af1270155e803a77955c9f37175dd09c43d4 |
2 files changed, 22 insertions(+), 1 deletions(-)
src/ir.cpp+6-1| ... | ... | @@ -25915,6 +25915,11 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 25915 | 25915 | { |
| 25916 | 25916 | return ira->codegen->invalid_inst_gen->value->type; |
| 25917 | 25917 | } |
| 25918 | if (sentinel != nullptr && (size_enum_index == BuiltinPtrSizeOne || size_enum_index == BuiltinPtrSizeC)) { | |
| 25919 | ir_add_error(ira, source_instr, | |
| 25920 | buf_sprintf("sentinels are only allowed on slices and unknown-length pointers")); | |
| 25921 | return ira->codegen->invalid_inst_gen->value->type; | |
| 25922 | } | |
| 25918 | 25923 | BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "alignment", 3); |
| 25919 | 25924 | if (bi == nullptr) |
| 25920 | 25925 | return ira->codegen->invalid_inst_gen->value->type; |
| ... | ... | @@ -25948,7 +25953,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeI |
| 25948 | 25953 | 0, // host_int_bytes |
| 25949 | 25954 | is_allowzero, |
| 25950 | 25955 | VECTOR_INDEX_NONE, nullptr, sentinel); |
| 25951 | if (size_enum_index != 2) | |
| 25956 | if (size_enum_index != BuiltinPtrSizeSlice) | |
| 25952 | 25957 | return ptr_type; |
| 25953 | 25958 | return get_slice_type(ira->codegen, ptr_type); |
| 25954 | 25959 | } |
test/compile_errors.zig+16| ... | ... | @@ -2,6 +2,22 @@ const tests = @import("tests.zig"); |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | |
| 4 | 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5 | cases.addTest("invalid pointer with @Type", | |
| 6 | \\export fn entry() void { | |
| 7 | \\ _ = @Type(.{ .Pointer = .{ | |
| 8 | \\ .size = .One, | |
| 9 | \\ .is_const = false, | |
| 10 | \\ .is_volatile = false, | |
| 11 | \\ .alignment = 1, | |
| 12 | \\ .child = u8, | |
| 13 | \\ .is_allowzero = false, | |
| 14 | \\ .sentinel = 0, | |
| 15 | \\ }}); | |
| 16 | \\} | |
| 17 | , &[_][]const u8{ | |
| 18 | "tmp.zig:2:16: error: sentinels are only allowed on slices and unknown-length pointers", | |
| 19 | }); | |
| 20 | ||
| 5 | 21 | cases.addTest("int/float conversion to comptime_int/float", |
| 6 | 22 | \\export fn foo() void { |
| 7 | 23 | \\ var a: f32 = 2; |