| author | |
| committer | |
| log | a7a8c433d0153bf8d71d17f2cf54027ba8eff805 |
| tree | 7337f6fe1320661e291930515061b2c11cdea6b2 |
| parent | 7634e67ba503fdbdf75daff48a13f9d35e331cd4 |
Closes #51402 files changed, 14 insertions(+), 0 deletions(-)
src/ir.cpp+6| ... | @@ -29079,6 +29079,12 @@ static IrInstGen *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstSrcPtrTy | ... | @@ -29079,6 +29079,12 @@ static IrInstGen *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstSrcPtrTy |
| 29079 | lazy_ptr_type->base.id = LazyValueIdPtrType; | 29079 | lazy_ptr_type->base.id = LazyValueIdPtrType; |
| 29080 | 29080 | ||
| 29081 | if (instruction->sentinel != nullptr) { | 29081 | if (instruction->sentinel != nullptr) { |
| 29082 | if (instruction->ptr_len != PtrLenUnknown) { | ||
| 29083 | ir_add_error(ira, &instruction->base.base, | ||
| 29084 | buf_sprintf("sentinels are only allowed on unknown-length pointers")); | ||
| 29085 | return ira->codegen->invalid_inst_gen; | ||
| 29086 | } | ||
| 29087 | |||
| 29082 | lazy_ptr_type->sentinel = instruction->sentinel->child; | 29088 | lazy_ptr_type->sentinel = instruction->sentinel->child; |
| 29083 | if (ir_resolve_const(ira, lazy_ptr_type->sentinel, LazyOk) == nullptr) | 29089 | if (ir_resolve_const(ira, lazy_ptr_type->sentinel, LazyOk) == nullptr) |
| 29084 | return ira->codegen->invalid_inst_gen; | 29090 | return ira->codegen->invalid_inst_gen; |
test/compile_errors.zig+8| ... | @@ -2,6 +2,14 @@ const tests = @import("tests.zig"); | ... | @@ -2,6 +2,14 @@ const tests = @import("tests.zig"); |
| 2 | const std = @import("std"); | 2 | const std = @import("std"); |
| 3 | 3 | ||
| 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { | 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5 | cases.add("invalid pointer syntax", | ||
| 6 | \\export fn foo() void { | ||
| 7 | \\ var guid: *:0 const u8 = undefined; | ||
| 8 | \\} | ||
| 9 | , &[_][]const u8{ | ||
| 10 | "tmp.zig:2:15: error: sentinels are only allowed on unknown-length pointers", | ||
| 11 | }); | ||
| 12 | |||
| 5 | cases.add("declaration between fields", | 13 | cases.add("declaration between fields", |
| 6 | \\const S = struct { | 14 | \\const S = struct { |
| 7 | \\ const foo = 2; | 15 | \\ const foo = 2; |