| author | |
| committer | |
| log | ad9f48b74bb5d43b767bdf401002d8bfd57c8813 |
| tree | af4f30fc3ca17ccdcd2824ce23ec859dcc24e191 |
| parent | 27e4893ee59b965e4c030c43782798db258438ba |
closes #4083 files changed, 20 insertions(+), 0 deletions(-)
src/analyze.cpp+3| ... | ... | @@ -3704,6 +3704,9 @@ void init_const_undefined(CodeGen *g, ConstExprValue *const_val) { |
| 3704 | 3704 | const_val->data.x_array.special = ConstArraySpecialUndef; |
| 3705 | 3705 | } else if (wanted_type->id == TypeTableEntryIdStruct) { |
| 3706 | 3706 | ensure_complete_type(g, wanted_type); |
| 3707 | if (type_is_invalid(wanted_type)) { | |
| 3708 | return; | |
| 3709 | } | |
| 3707 | 3710 | |
| 3708 | 3711 | const_val->special = ConstValSpecialStatic; |
| 3709 | 3712 | size_t field_count = wanted_type->data.structure.src_field_count; |
src/ir.cpp+4| ... | ... | @@ -6945,6 +6945,9 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node |
| 6945 | 6945 | FnTableEntry *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name, |
| 6946 | 6946 | IrExecutable *parent_exec) |
| 6947 | 6947 | { |
| 6948 | if (expected_type != nullptr && type_is_invalid(expected_type)) | |
| 6949 | return codegen->invalid_instruction; | |
| 6950 | ||
| 6948 | 6951 | IrExecutable ir_executable = {0}; |
| 6949 | 6952 | ir_executable.source_node = source_node; |
| 6950 | 6953 | ir_executable.parent_exec = parent_exec; |
| ... | ... | @@ -14112,6 +14115,7 @@ TypeTableEntry *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutabl |
| 14112 | 14115 | TypeTableEntry *expected_type, AstNode *expected_type_source_node) |
| 14113 | 14116 | { |
| 14114 | 14117 | assert(!old_exec->invalid); |
| 14118 | assert(expected_type == nullptr || !type_is_invalid(expected_type)); | |
| 14115 | 14119 | |
| 14116 | 14120 | IrAnalyze ir_analyze_data = {}; |
| 14117 | 14121 | IrAnalyze *ira = &ir_analyze_data; |
test/compile_errors.zig+13| ... | ... | @@ -1918,4 +1918,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1918 | 1918 | ".tmp_source.zig:1:13: error: aoeu", |
| 1919 | 1919 | ".tmp_source.zig:3:19: note: referenced here", |
| 1920 | 1920 | ".tmp_source.zig:7:12: note: referenced here"); |
| 1921 | ||
| 1922 | cases.add("instantiating an undefined value for an invalid struct that contains itself", | |
| 1923 | \\const Foo = struct { | |
| 1924 | \\ x: Foo, | |
| 1925 | \\}; | |
| 1926 | \\ | |
| 1927 | \\var foo: Foo = undefined; | |
| 1928 | \\ | |
| 1929 | \\export fn entry() -> usize { | |
| 1930 | \\ return @sizeOf(@typeOf(foo.x)); | |
| 1931 | \\} | |
| 1932 | , | |
| 1933 | ".tmp_source.zig:1:13: error: struct 'Foo' contains itself"); | |
| 1921 | 1934 | } |