| author | |
| committer | |
| log | 63f636e7b775bc8d2881104248f9579a089c4240 |
| tree | 25e7432ccd228f0507aa3cb8665ad66762e29db6 |
| parent | a08b65720b7a6b78ff59b36fff1b3a6910483609 |
| signature | Commit is signed but in an unrecognized format. |
closes #154114 files changed, 105 insertions(+), 145 deletions(-)
doc/langref.html.in+7-4| ... | ... | @@ -8,6 +8,7 @@ |
| 8 | 8 | body{ |
| 9 | 9 | background-color:#111; |
| 10 | 10 | color: #bbb; |
| 11 | font-family: sans-serif; | |
| 11 | 12 | } |
| 12 | 13 | a { |
| 13 | 14 | color: #88f; |
| ... | ... | @@ -467,9 +468,10 @@ pub fn main() void { |
| 467 | 468 | <p> |
| 468 | 469 | In addition to the integer types above, arbitrary bit-width integers can be referenced by using |
| 469 | 470 | an identifier of <code>i</code> or </code>u</code> followed by digits. For example, the identifier |
| 470 | {#syntax#}i7{#endsyntax#} refers to a signed 7-bit integer. | |
| 471 | {#syntax#}i7{#endsyntax#} refers to a signed 7-bit integer. The maximum allowed bit-width of an | |
| 472 | integer type is {#syntax#}65535{#endsyntax#}. | |
| 471 | 473 | </p> |
| 472 | {#see_also|Integers|Floats|void|Errors#} | |
| 474 | {#see_also|Integers|Floats|void|Errors|@IntType#} | |
| 473 | 475 | {#header_close#} |
| 474 | 476 | {#header_open|Primitive Values#} |
| 475 | 477 | <div class="table-wrapper"> |
| ... | ... | @@ -5814,9 +5816,10 @@ fn add(a: i32, b: i32) i32 { return a + b; } |
| 5814 | 5816 | {#header_close#} |
| 5815 | 5817 | |
| 5816 | 5818 | {#header_open|@IntType#} |
| 5817 | <pre>{#syntax#}@IntType(comptime is_signed: bool, comptime bit_count: u32) type{#endsyntax#}</pre> | |
| 5819 | <pre>{#syntax#}@IntType(comptime is_signed: bool, comptime bit_count: u16) type{#endsyntax#}</pre> | |
| 5818 | 5820 | <p> |
| 5819 | This function returns an integer type with the given signness and bit count. | |
| 5821 | This function returns an integer type with the given signness and bit count. The maximum | |
| 5822 | bit count for an integer type is {#syntax#}65535{#endsyntax#}. | |
| 5820 | 5823 | </p> |
| 5821 | 5824 | {#header_close#} |
| 5822 | 5825 | {#header_open|@memberCount#} |
src/all_types.hpp-1| ... | ... | @@ -1222,7 +1222,6 @@ struct ZigType { |
| 1222 | 1222 | ZigLLVMDIType *di_type; |
| 1223 | 1223 | |
| 1224 | 1224 | bool zero_bits; // this is denormalized data |
| 1225 | bool is_copyable; | |
| 1226 | 1225 | bool gen_h_loop_flag; |
| 1227 | 1226 | |
| 1228 | 1227 | union { |
src/analyze.cpp+24-44| ... | ... | @@ -367,23 +367,6 @@ uint64_t type_size_bits(CodeGen *g, ZigType *type_entry) { |
| 367 | 367 | return LLVMSizeOfTypeInBits(g->target_data_ref, type_entry->type_ref); |
| 368 | 368 | } |
| 369 | 369 | |
| 370 | Result<bool> type_is_copyable(CodeGen *g, ZigType *type_entry) { | |
| 371 | Error err; | |
| 372 | if ((err = type_resolve(g, type_entry, ResolveStatusZeroBitsKnown))) | |
| 373 | return err; | |
| 374 | ||
| 375 | if (!type_has_bits(type_entry)) | |
| 376 | return true; | |
| 377 | ||
| 378 | if (!handle_is_ptr(type_entry)) | |
| 379 | return true; | |
| 380 | ||
| 381 | if ((err = ensure_complete_type(g, type_entry))) | |
| 382 | return err; | |
| 383 | ||
| 384 | return type_entry->is_copyable; | |
| 385 | } | |
| 386 | ||
| 387 | 370 | static bool is_slice(ZigType *type) { |
| 388 | 371 | return type->id == ZigTypeIdStruct && type->data.structure.is_slice; |
| 389 | 372 | } |
| ... | ... | @@ -465,7 +448,6 @@ ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_cons |
| 465 | 448 | assert(type_is_resolved(child_type, ResolveStatusZeroBitsKnown)); |
| 466 | 449 | |
| 467 | 450 | ZigType *entry = new_type_table_entry(ZigTypeIdPointer); |
| 468 | entry->is_copyable = true; | |
| 469 | 451 | |
| 470 | 452 | const char *star_str = ptr_len == PtrLenSingle ? "*" : "[*]"; |
| 471 | 453 | const char *const_str = is_const ? "const " : ""; |
| ... | ... | @@ -581,7 +563,6 @@ ZigType *get_optional_type(CodeGen *g, ZigType *child_type) { |
| 581 | 563 | |
| 582 | 564 | ZigType *entry = new_type_table_entry(ZigTypeIdOptional); |
| 583 | 565 | assert(child_type->type_ref || child_type->zero_bits); |
| 584 | entry->is_copyable = type_is_copyable(g, child_type).unwrap(); | |
| 585 | 566 | |
| 586 | 567 | buf_resize(&entry->name, 0); |
| 587 | 568 | buf_appendf(&entry->name, "?%s", buf_ptr(&child_type->name)); |
| ... | ... | @@ -671,7 +652,6 @@ ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payloa |
| 671 | 652 | } |
| 672 | 653 | |
| 673 | 654 | ZigType *entry = new_type_table_entry(ZigTypeIdErrorUnion); |
| 674 | entry->is_copyable = true; | |
| 675 | 655 | assert(payload_type->di_type); |
| 676 | 656 | assert(type_is_complete(payload_type)); |
| 677 | 657 | |
| ... | ... | @@ -766,7 +746,6 @@ ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size) { |
| 766 | 746 | |
| 767 | 747 | ZigType *entry = new_type_table_entry(ZigTypeIdArray); |
| 768 | 748 | entry->zero_bits = (array_size == 0) || child_type->zero_bits; |
| 769 | entry->is_copyable = false; | |
| 770 | 749 | |
| 771 | 750 | buf_resize(&entry->name, 0); |
| 772 | 751 | buf_appendf(&entry->name, "[%" ZIG_PRI_u64 "]%s", array_size, buf_ptr(&child_type->name)); |
| ... | ... | @@ -831,7 +810,6 @@ ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) { |
| 831 | 810 | } |
| 832 | 811 | |
| 833 | 812 | ZigType *entry = new_type_table_entry(ZigTypeIdStruct); |
| 834 | entry->is_copyable = true; | |
| 835 | 813 | |
| 836 | 814 | // replace the & with [] to go from a ptr type name to a slice type name |
| 837 | 815 | buf_resize(&entry->name, 0); |
| ... | ... | @@ -986,7 +964,6 @@ ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const c |
| 986 | 964 | ImportTableEntry *import = scope ? get_scope_import(scope) : nullptr; |
| 987 | 965 | unsigned line = source_node ? (unsigned)(source_node->line + 1) : 0; |
| 988 | 966 | |
| 989 | entry->is_copyable = false; | |
| 990 | 967 | entry->type_ref = LLVMInt8Type(); |
| 991 | 968 | entry->di_type = ZigLLVMCreateDebugForwardDeclType(g->dbuilder, |
| 992 | 969 | ZigLLVMTag_DW_structure_type(), buf_ptr(&entry->name), |
| ... | ... | @@ -1005,7 +982,6 @@ ZigType *get_bound_fn_type(CodeGen *g, ZigFn *fn_entry) { |
| 1005 | 982 | return fn_type->data.fn.bound_fn_parent; |
| 1006 | 983 | |
| 1007 | 984 | ZigType *bound_fn_type = new_type_table_entry(ZigTypeIdBoundFn); |
| 1008 | bound_fn_type->is_copyable = false; | |
| 1009 | 985 | bound_fn_type->data.bound_fn.fn_type = fn_type; |
| 1010 | 986 | bound_fn_type->zero_bits = true; |
| 1011 | 987 | |
| ... | ... | @@ -1105,7 +1081,6 @@ ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { |
| 1105 | 1081 | } |
| 1106 | 1082 | |
| 1107 | 1083 | ZigType *fn_type = new_type_table_entry(ZigTypeIdFn); |
| 1108 | fn_type->is_copyable = true; | |
| 1109 | 1084 | fn_type->data.fn.fn_type_id = *fn_type_id; |
| 1110 | 1085 | |
| 1111 | 1086 | bool skip_debug_info = false; |
| ... | ... | @@ -1318,7 +1293,6 @@ ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) { |
| 1318 | 1293 | |
| 1319 | 1294 | ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) { |
| 1320 | 1295 | ZigType *fn_type = new_type_table_entry(ZigTypeIdFn); |
| 1321 | fn_type->is_copyable = false; | |
| 1322 | 1296 | buf_resize(&fn_type->name, 0); |
| 1323 | 1297 | if (fn_type->data.fn.fn_type_id.cc == CallingConventionAsync) { |
| 1324 | 1298 | const char *async_allocator_type_str = (fn_type->data.fn.fn_type_id.async_allocator_type == nullptr) ? |
| ... | ... | @@ -1526,7 +1500,6 @@ ZigType *get_auto_err_set_type(CodeGen *g, ZigFn *fn_entry) { |
| 1526 | 1500 | ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet); |
| 1527 | 1501 | buf_resize(&err_set_type->name, 0); |
| 1528 | 1502 | buf_appendf(&err_set_type->name, "@typeOf(%s).ReturnType.ErrorSet", buf_ptr(&fn_entry->symbol_name)); |
| 1529 | err_set_type->is_copyable = true; | |
| 1530 | 1503 | err_set_type->type_ref = g->builtin_types.entry_global_error_set->type_ref; |
| 1531 | 1504 | err_set_type->di_type = g->builtin_types.entry_global_error_set->di_type; |
| 1532 | 1505 | err_set_type->data.error_set.err_count = 0; |
| ... | ... | @@ -2846,7 +2819,6 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { |
| 2846 | 2819 | tag_type = new_type_table_entry(ZigTypeIdEnum); |
| 2847 | 2820 | buf_resize(&tag_type->name, 0); |
| 2848 | 2821 | buf_appendf(&tag_type->name, "@TagType(%s)", buf_ptr(&union_type->name)); |
| 2849 | tag_type->is_copyable = true; | |
| 2850 | 2822 | tag_type->type_ref = tag_int_type->type_ref; |
| 2851 | 2823 | tag_type->zero_bits = tag_int_type->zero_bits; |
| 2852 | 2824 | |
| ... | ... | @@ -3366,10 +3338,10 @@ static void add_top_level_decl(CodeGen *g, ScopeDecls *decls_scope, Tld *tld) { |
| 3366 | 3338 | } |
| 3367 | 3339 | |
| 3368 | 3340 | { |
| 3369 | ZigType *type = get_primitive_type(g, tld->name); | |
| 3370 | if (type != nullptr) { | |
| 3341 | ZigType *type; | |
| 3342 | if (get_primitive_type(g, tld->name, &type) != ErrorPrimitiveTypeNotFound) { | |
| 3371 | 3343 | add_node_error(g, tld->source_node, |
| 3372 | buf_sprintf("declaration shadows type '%s'", buf_ptr(&type->name))); | |
| 3344 | buf_sprintf("declaration shadows primitive type '%s'", buf_ptr(tld->name))); | |
| 3373 | 3345 | } |
| 3374 | 3346 | } |
| 3375 | 3347 | } |
| ... | ... | @@ -3613,10 +3585,10 @@ ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf |
| 3613 | 3585 | add_error_note(g, msg, existing_var->decl_node, buf_sprintf("previous declaration is here")); |
| 3614 | 3586 | variable_entry->value->type = g->builtin_types.entry_invalid; |
| 3615 | 3587 | } else { |
| 3616 | ZigType *type = get_primitive_type(g, name); | |
| 3617 | if (type != nullptr) { | |
| 3588 | ZigType *type; | |
| 3589 | if (get_primitive_type(g, name, &type) != ErrorPrimitiveTypeNotFound) { | |
| 3618 | 3590 | add_node_error(g, source_node, |
| 3619 | buf_sprintf("variable shadows type '%s'", buf_ptr(&type->name))); | |
| 3591 | buf_sprintf("variable shadows primitive type '%s'", buf_ptr(name))); | |
| 3620 | 3592 | variable_entry->value->type = g->builtin_types.entry_invalid; |
| 3621 | 3593 | } else { |
| 3622 | 3594 | Scope *search_scope = nullptr; |
| ... | ... | @@ -4435,6 +4407,7 @@ void semantic_analyze(CodeGen *g) { |
| 4435 | 4407 | } |
| 4436 | 4408 | |
| 4437 | 4409 | ZigType *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) { |
| 4410 | assert(size_in_bits <= 65535); | |
| 4438 | 4411 | TypeId type_id = {}; |
| 4439 | 4412 | type_id.id = ZigTypeIdInt; |
| 4440 | 4413 | type_id.data.integer.is_signed = is_signed; |
| ... | ... | @@ -4523,7 +4496,7 @@ Buf *get_linux_libc_lib_path(const char *o_file) { |
| 4523 | 4496 | Termination term; |
| 4524 | 4497 | Buf *out_stderr = buf_alloc(); |
| 4525 | 4498 | Buf *out_stdout = buf_alloc(); |
| 4526 | int err; | |
| 4499 | Error err; | |
| 4527 | 4500 | if ((err = os_exec_process(cc_exe, args, &term, out_stderr, out_stdout))) { |
| 4528 | 4501 | zig_panic("unable to determine libc lib path: executing C compiler: %s", err_str(err)); |
| 4529 | 4502 | } |
| ... | ... | @@ -4552,7 +4525,7 @@ Buf *get_linux_libc_include_path(void) { |
| 4552 | 4525 | Termination term; |
| 4553 | 4526 | Buf *out_stderr = buf_alloc(); |
| 4554 | 4527 | Buf *out_stdout = buf_alloc(); |
| 4555 | int err; | |
| 4528 | Error err; | |
| 4556 | 4529 | if ((err = os_exec_process(cc_exe, args, &term, out_stderr, out_stdout))) { |
| 4557 | 4530 | zig_panic("unable to determine libc include path: executing C compiler: %s", err_str(err)); |
| 4558 | 4531 | } |
| ... | ... | @@ -5977,8 +5950,8 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { |
| 5977 | 5950 | } |
| 5978 | 5951 | |
| 5979 | 5952 | ZigType *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) { |
| 5953 | assert(size_in_bits <= 65535); | |
| 5980 | 5954 | ZigType *entry = new_type_table_entry(ZigTypeIdInt); |
| 5981 | entry->is_copyable = true; | |
| 5982 | 5955 | entry->type_ref = (size_in_bits == 0) ? LLVMVoidType() : LLVMIntType(size_in_bits); |
| 5983 | 5956 | entry->zero_bits = (size_in_bits == 0); |
| 5984 | 5957 | |
| ... | ... | @@ -6455,7 +6428,10 @@ bool fn_type_can_fail(FnTypeId *fn_type_id) { |
| 6455 | 6428 | return type_can_fail(fn_type_id->return_type) || fn_type_id->cc == CallingConventionAsync; |
| 6456 | 6429 | } |
| 6457 | 6430 | |
| 6458 | ZigType *get_primitive_type(CodeGen *g, Buf *name) { | |
| 6431 | // ErrorNone - result pointer has the type | |
| 6432 | // ErrorOverflow - an integer primitive type has too large a bit width | |
| 6433 | // ErrorPrimitiveTypeNotFound - result pointer unchanged | |
| 6434 | Error get_primitive_type(CodeGen *g, Buf *name, ZigType **result) { | |
| 6459 | 6435 | if (buf_len(name) >= 2) { |
| 6460 | 6436 | uint8_t first_c = buf_ptr(name)[0]; |
| 6461 | 6437 | if (first_c == 'i' || first_c == 'u') { |
| ... | ... | @@ -6466,18 +6442,22 @@ ZigType *get_primitive_type(CodeGen *g, Buf *name) { |
| 6466 | 6442 | } |
| 6467 | 6443 | } |
| 6468 | 6444 | bool is_signed = (first_c == 'i'); |
| 6469 | uint32_t bit_count = atoi(buf_ptr(name) + 1); | |
| 6470 | return get_int_type(g, is_signed, bit_count); | |
| 6445 | unsigned long int bit_count = strtoul(buf_ptr(name) + 1, nullptr, 10); | |
| 6446 | // strtoul returns ULONG_MAX on errors, so this comparison catches that as well. | |
| 6447 | if (bit_count >= 65536) return ErrorOverflow; | |
| 6448 | *result = get_int_type(g, is_signed, bit_count); | |
| 6449 | return ErrorNone; | |
| 6471 | 6450 | } |
| 6472 | 6451 | } |
| 6473 | 6452 | |
| 6474 | 6453 | not_integer: |
| 6475 | 6454 | |
| 6476 | 6455 | auto primitive_table_entry = g->primitive_type_table.maybe_get(name); |
| 6477 | if (primitive_table_entry != nullptr) { | |
| 6478 | return primitive_table_entry->value; | |
| 6479 | } | |
| 6480 | return nullptr; | |
| 6456 | if (primitive_table_entry == nullptr) | |
| 6457 | return ErrorPrimitiveTypeNotFound; | |
| 6458 | ||
| 6459 | *result = primitive_table_entry->value; | |
| 6460 | return ErrorNone; | |
| 6481 | 6461 | } |
| 6482 | 6462 | |
| 6483 | 6463 | Error file_fetch(CodeGen *g, Buf *resolved_path, Buf *contents) { |
src/analyze.hpp+1-3| ... | ... | @@ -9,7 +9,6 @@ |
| 9 | 9 | #define ZIG_ANALYZE_HPP |
| 10 | 10 | |
| 11 | 11 | #include "all_types.hpp" |
| 12 | #include "result.hpp" | |
| 13 | 12 | |
| 14 | 13 | void semantic_analyze(CodeGen *g); |
| 15 | 14 | ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg); |
| ... | ... | @@ -180,7 +179,6 @@ ZigTypeId type_id_at_index(size_t index); |
| 180 | 179 | size_t type_id_len(); |
| 181 | 180 | size_t type_id_index(ZigType *entry); |
| 182 | 181 | ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id); |
| 183 | Result<bool> type_is_copyable(CodeGen *g, ZigType *type_entry); | |
| 184 | 182 | LinkLib *create_link_lib(Buf *name); |
| 185 | 183 | LinkLib *add_link_lib(CodeGen *codegen, Buf *lib); |
| 186 | 184 | |
| ... | ... | @@ -204,7 +202,7 @@ bool type_can_fail(ZigType *type_entry); |
| 204 | 202 | bool fn_eval_cacheable(Scope *scope, ZigType *return_type); |
| 205 | 203 | AstNode *type_decl_node(ZigType *type_entry); |
| 206 | 204 | |
| 207 | ZigType *get_primitive_type(CodeGen *g, Buf *name); | |
| 205 | Error get_primitive_type(CodeGen *g, Buf *name, ZigType **result); | |
| 208 | 206 | |
| 209 | 207 | bool calling_convention_allows_zig_types(CallingConvention cc); |
| 210 | 208 | const char *calling_convention_name(CallingConvention cc); |
src/codegen.cpp+3-3| ... | ... | @@ -7326,7 +7326,7 @@ void codegen_translate_c(CodeGen *g, Buf *full_path) { |
| 7326 | 7326 | import->di_file = ZigLLVMCreateFile(g->dbuilder, buf_ptr(src_basename), buf_ptr(src_dirname)); |
| 7327 | 7327 | |
| 7328 | 7328 | ZigList<ErrorMsg *> errors = {0}; |
| 7329 | int err = parse_h_file(import, &errors, buf_ptr(full_path), g, nullptr); | |
| 7329 | Error err = parse_h_file(import, &errors, buf_ptr(full_path), g, nullptr); | |
| 7330 | 7330 | |
| 7331 | 7331 | if (err == ErrorCCompileErrors && errors.length > 0) { |
| 7332 | 7332 | for (size_t i = 0; i < errors.length; i += 1) { |
| ... | ... | @@ -7446,7 +7446,7 @@ static void gen_root_source(CodeGen *g) { |
| 7446 | 7446 | return; |
| 7447 | 7447 | |
| 7448 | 7448 | Buf *source_code = buf_alloc(); |
| 7449 | int err; | |
| 7449 | Error err; | |
| 7450 | 7450 | // No need for using the caching system for this file fetch because it is handled |
| 7451 | 7451 | // separately. |
| 7452 | 7452 | if ((err = os_fetch_file_path(resolved_path, source_code, true))) { |
| ... | ... | @@ -7514,7 +7514,7 @@ void codegen_add_assembly(CodeGen *g, Buf *path) { |
| 7514 | 7514 | |
| 7515 | 7515 | static void gen_global_asm(CodeGen *g) { |
| 7516 | 7516 | Buf contents = BUF_INIT; |
| 7517 | int err; | |
| 7517 | Error err; | |
| 7518 | 7518 | for (size_t i = 0; i < g->assembly_files.length; i += 1) { |
| 7519 | 7519 | Buf *asm_file = g->assembly_files.at(i); |
| 7520 | 7520 | // No need to use the caching system for these fetches because they |
src/error.cpp+3-2| ... | ... | @@ -7,8 +7,8 @@ |
| 7 | 7 | |
| 8 | 8 | #include "error.hpp" |
| 9 | 9 | |
| 10 | const char *err_str(int err) { | |
| 11 | switch ((enum Error)err) { | |
| 10 | const char *err_str(Error err) { | |
| 11 | switch (err) { | |
| 12 | 12 | case ErrorNone: return "(no error)"; |
| 13 | 13 | case ErrorNoMem: return "out of memory"; |
| 14 | 14 | case ErrorInvalidFormat: return "invalid format"; |
| ... | ... | @@ -32,6 +32,7 @@ const char *err_str(int err) { |
| 32 | 32 | case ErrorUnsupportedOperatingSystem: return "unsupported operating system"; |
| 33 | 33 | case ErrorSharingViolation: return "sharing violation"; |
| 34 | 34 | case ErrorPipeBusy: return "pipe busy"; |
| 35 | case ErrorPrimitiveTypeNotFound: return "primitive type not found"; | |
| 35 | 36 | } |
| 36 | 37 | return "(invalid error)"; |
| 37 | 38 | } |
src/error.hpp+8-1| ... | ... | @@ -8,6 +8,8 @@ |
| 8 | 8 | #ifndef ERROR_HPP |
| 9 | 9 | #define ERROR_HPP |
| 10 | 10 | |
| 11 | #include <assert.h> | |
| 12 | ||
| 11 | 13 | enum Error { |
| 12 | 14 | ErrorNone, |
| 13 | 15 | ErrorNoMem, |
| ... | ... | @@ -32,8 +34,13 @@ enum Error { |
| 32 | 34 | ErrorUnsupportedOperatingSystem, |
| 33 | 35 | ErrorSharingViolation, |
| 34 | 36 | ErrorPipeBusy, |
| 37 | ErrorPrimitiveTypeNotFound, | |
| 35 | 38 | }; |
| 36 | 39 | |
| 37 | const char *err_str(int err); | |
| 40 | const char *err_str(Error err); | |
| 41 | ||
| 42 | static inline void assertNoError(Error err) { | |
| 43 | assert(err == ErrorNone); | |
| 44 | } | |
| 38 | 45 | |
| 39 | 46 | #endif |
src/ir.cpp+16-12| ... | ... | @@ -3055,10 +3055,10 @@ static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_s |
| 3055 | 3055 | add_error_note(codegen, msg, existing_var->decl_node, buf_sprintf("previous declaration is here")); |
| 3056 | 3056 | variable_entry->value->type = codegen->builtin_types.entry_invalid; |
| 3057 | 3057 | } else { |
| 3058 | ZigType *type = get_primitive_type(codegen, name); | |
| 3059 | if (type != nullptr) { | |
| 3058 | ZigType *type; | |
| 3059 | if (get_primitive_type(codegen, name, &type) != ErrorPrimitiveTypeNotFound) { | |
| 3060 | 3060 | add_node_error(codegen, node, |
| 3061 | buf_sprintf("variable shadows type '%s'", buf_ptr(&type->name))); | |
| 3061 | buf_sprintf("variable shadows primitive type '%s'", buf_ptr(name))); | |
| 3062 | 3062 | variable_entry->value->type = codegen->builtin_types.entry_invalid; |
| 3063 | 3063 | } else { |
| 3064 | 3064 | Tld *tld = find_decl(codegen, parent_scope, name); |
| ... | ... | @@ -3488,6 +3488,7 @@ static IrInstruction *ir_gen_null_literal(IrBuilder *irb, Scope *scope, AstNode |
| 3488 | 3488 | } |
| 3489 | 3489 | |
| 3490 | 3490 | static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval) { |
| 3491 | Error err; | |
| 3491 | 3492 | assert(node->type == NodeTypeSymbol); |
| 3492 | 3493 | |
| 3493 | 3494 | Buf *variable_name = node->data.symbol_expr.symbol; |
| ... | ... | @@ -3501,8 +3502,15 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, |
| 3501 | 3502 | return &const_instruction->base; |
| 3502 | 3503 | } |
| 3503 | 3504 | |
| 3504 | ZigType *primitive_type = get_primitive_type(irb->codegen, variable_name); | |
| 3505 | if (primitive_type != nullptr) { | |
| 3505 | ZigType *primitive_type; | |
| 3506 | if ((err = get_primitive_type(irb->codegen, variable_name, &primitive_type))) { | |
| 3507 | if (err == ErrorOverflow) { | |
| 3508 | add_node_error(irb->codegen, node, | |
| 3509 | buf_sprintf("primitive integer type '%s' exceeds maximum bit width of 65535", | |
| 3510 | buf_ptr(variable_name))); | |
| 3511 | return irb->codegen->invalid_instruction; | |
| 3512 | } | |
| 3513 | } else { | |
| 3506 | 3514 | IrInstruction *value = ir_build_const_type(irb, scope, node, primitive_type); |
| 3507 | 3515 | if (lval == LValPtr) { |
| 3508 | 3516 | return ir_build_ref(irb, scope, node, value, false, false); |
| ... | ... | @@ -6302,7 +6310,6 @@ static ZigType *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, ZigTyp |
| 6302 | 6310 | } |
| 6303 | 6311 | } |
| 6304 | 6312 | |
| 6305 | err_set_type->is_copyable = true; | |
| 6306 | 6313 | err_set_type->type_ref = g->builtin_types.entry_global_error_set->type_ref; |
| 6307 | 6314 | err_set_type->di_type = g->builtin_types.entry_global_error_set->di_type; |
| 6308 | 6315 | err_set_type->data.error_set.err_count = count; |
| ... | ... | @@ -6341,7 +6348,6 @@ static ZigType *make_err_set_with_one_item(CodeGen *g, Scope *parent_scope, AstN |
| 6341 | 6348 | ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet); |
| 6342 | 6349 | buf_resize(&err_set_type->name, 0); |
| 6343 | 6350 | buf_appendf(&err_set_type->name, "error.{%s}", buf_ptr(&err_entry->name)); |
| 6344 | err_set_type->is_copyable = true; | |
| 6345 | 6351 | err_set_type->type_ref = g->builtin_types.entry_global_error_set->type_ref; |
| 6346 | 6352 | err_set_type->di_type = g->builtin_types.entry_global_error_set->di_type; |
| 6347 | 6353 | err_set_type->data.error_set.err_count = 1; |
| ... | ... | @@ -6362,7 +6368,6 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A |
| 6362 | 6368 | Buf *type_name = get_anon_type_name(irb->codegen, irb->exec, "error set", node); |
| 6363 | 6369 | ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet); |
| 6364 | 6370 | buf_init_from_buf(&err_set_type->name, type_name); |
| 6365 | err_set_type->is_copyable = true; | |
| 6366 | 6371 | err_set_type->data.error_set.err_count = err_count; |
| 6367 | 6372 | err_set_type->type_ref = irb->codegen->builtin_types.entry_global_error_set->type_ref; |
| 6368 | 6373 | err_set_type->di_type = irb->codegen->builtin_types.entry_global_error_set->di_type; |
| ... | ... | @@ -8208,7 +8213,6 @@ static ZigType *get_error_set_intersection(IrAnalyze *ira, ZigType *set1, ZigTyp |
| 8208 | 8213 | } |
| 8209 | 8214 | free(errors); |
| 8210 | 8215 | |
| 8211 | err_set_type->is_copyable = true; | |
| 8212 | 8216 | err_set_type->type_ref = ira->codegen->builtin_types.entry_global_error_set->type_ref; |
| 8213 | 8217 | err_set_type->di_type = ira->codegen->builtin_types.entry_global_error_set->di_type; |
| 8214 | 8218 | err_set_type->data.error_set.err_count = intersection_list.length; |
| ... | ... | @@ -17650,7 +17654,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct |
| 17650 | 17654 | |
| 17651 | 17655 | ZigList<ErrorMsg *> errors = {0}; |
| 17652 | 17656 | |
| 17653 | int err; | |
| 17657 | Error err; | |
| 17654 | 17658 | if ((err = parse_h_buf(child_import, &errors, &cimport_scope->buf, ira->codegen, node))) { |
| 17655 | 17659 | if (err != ErrorCCompileErrors) { |
| 17656 | 17660 | ir_add_error_node(ira, node, buf_sprintf("C import failed: %s", err_str(err))); |
| ... | ... | @@ -17766,7 +17770,7 @@ static IrInstruction *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstru |
| 17766 | 17770 | |
| 17767 | 17771 | // load from file system into const expr |
| 17768 | 17772 | Buf *file_contents = buf_alloc(); |
| 17769 | int err; | |
| 17773 | Error err; | |
| 17770 | 17774 | if ((err = file_fetch(ira->codegen, file_path, file_contents))) { |
| 17771 | 17775 | if (err == ErrorFileNotFound) { |
| 17772 | 17776 | ir_add_error(ira, instruction->name, buf_sprintf("unable to find '%s'", buf_ptr(file_path))); |
| ... | ... | @@ -18252,7 +18256,7 @@ static IrInstruction *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstruct |
| 18252 | 18256 | |
| 18253 | 18257 | IrInstruction *bit_count_value = instruction->bit_count->child; |
| 18254 | 18258 | uint64_t bit_count; |
| 18255 | if (!ir_resolve_unsigned(ira, bit_count_value, ira->codegen->builtin_types.entry_u32, &bit_count)) | |
| 18259 | if (!ir_resolve_unsigned(ira, bit_count_value, ira->codegen->builtin_types.entry_u16, &bit_count)) | |
| 18256 | 18260 | return ira->codegen->invalid_instruction; |
| 18257 | 18261 | |
| 18258 | 18262 | return ir_const_type(ira, &instruction->base, get_int_type(ira->codegen, is_signed, (uint32_t)bit_count)); |
src/os.cpp+16-16| ... | ... | @@ -793,7 +793,7 @@ Error os_file_exists(Buf *full_path, bool *result) { |
| 793 | 793 | } |
| 794 | 794 | |
| 795 | 795 | #if defined(ZIG_OS_POSIX) |
| 796 | static int os_exec_process_posix(const char *exe, ZigList<const char *> &args, | |
| 796 | static Error os_exec_process_posix(const char *exe, ZigList<const char *> &args, | |
| 797 | 797 | Termination *term, Buf *out_stderr, Buf *out_stdout) |
| 798 | 798 | { |
| 799 | 799 | int stdin_pipe[2]; |
| ... | ... | @@ -872,7 +872,7 @@ static int os_exec_process_posix(const char *exe, ZigList<const char *> &args, |
| 872 | 872 | // LocalFree(messageBuffer); |
| 873 | 873 | //} |
| 874 | 874 | |
| 875 | static int os_exec_process_windows(const char *exe, ZigList<const char *> &args, | |
| 875 | static Error os_exec_process_windows(const char *exe, ZigList<const char *> &args, | |
| 876 | 876 | Termination *term, Buf *out_stderr, Buf *out_stdout) |
| 877 | 877 | { |
| 878 | 878 | Buf command_line = BUF_INIT; |
| ... | ... | @@ -983,7 +983,7 @@ static int os_exec_process_windows(const char *exe, ZigList<const char *> &args, |
| 983 | 983 | CloseHandle(piProcInfo.hProcess); |
| 984 | 984 | CloseHandle(piProcInfo.hThread); |
| 985 | 985 | |
| 986 | return 0; | |
| 986 | return ErrorNone; | |
| 987 | 987 | } |
| 988 | 988 | #endif |
| 989 | 989 | |
| ... | ... | @@ -1003,7 +1003,7 @@ Error os_execv(const char *exe, const char **argv) { |
| 1003 | 1003 | #endif |
| 1004 | 1004 | } |
| 1005 | 1005 | |
| 1006 | int os_exec_process(const char *exe, ZigList<const char *> &args, | |
| 1006 | Error os_exec_process(const char *exe, ZigList<const char *> &args, | |
| 1007 | 1007 | Termination *term, Buf *out_stderr, Buf *out_stdout) |
| 1008 | 1008 | { |
| 1009 | 1009 | #if defined(ZIG_OS_WINDOWS) |
| ... | ... | @@ -1027,7 +1027,7 @@ void os_write_file(Buf *full_path, Buf *contents) { |
| 1027 | 1027 | zig_panic("close failed"); |
| 1028 | 1028 | } |
| 1029 | 1029 | |
| 1030 | int os_copy_file(Buf *src_path, Buf *dest_path) { | |
| 1030 | Error os_copy_file(Buf *src_path, Buf *dest_path) { | |
| 1031 | 1031 | FILE *src_f = fopen(buf_ptr(src_path), "rb"); |
| 1032 | 1032 | if (!src_f) { |
| 1033 | 1033 | int err = errno; |
| ... | ... | @@ -1074,7 +1074,7 @@ int os_copy_file(Buf *src_path, Buf *dest_path) { |
| 1074 | 1074 | if (feof(src_f)) { |
| 1075 | 1075 | fclose(src_f); |
| 1076 | 1076 | fclose(dest_f); |
| 1077 | return 0; | |
| 1077 | return ErrorNone; | |
| 1078 | 1078 | } |
| 1079 | 1079 | } |
| 1080 | 1080 | } |
| ... | ... | @@ -1197,7 +1197,7 @@ bool os_stderr_tty(void) { |
| 1197 | 1197 | } |
| 1198 | 1198 | |
| 1199 | 1199 | #if defined(ZIG_OS_POSIX) |
| 1200 | static int os_buf_to_tmp_file_posix(Buf *contents, Buf *suffix, Buf *out_tmp_path) { | |
| 1200 | static Error os_buf_to_tmp_file_posix(Buf *contents, Buf *suffix, Buf *out_tmp_path) { | |
| 1201 | 1201 | const char *tmp_dir = getenv("TMPDIR"); |
| 1202 | 1202 | if (!tmp_dir) { |
| 1203 | 1203 | tmp_dir = P_tmpdir; |
| ... | ... | @@ -1221,12 +1221,12 @@ static int os_buf_to_tmp_file_posix(Buf *contents, Buf *suffix, Buf *out_tmp_pat |
| 1221 | 1221 | if (fclose(f)) |
| 1222 | 1222 | zig_panic("close failed"); |
| 1223 | 1223 | |
| 1224 | return 0; | |
| 1224 | return ErrorNone; | |
| 1225 | 1225 | } |
| 1226 | 1226 | #endif |
| 1227 | 1227 | |
| 1228 | 1228 | #if defined(ZIG_OS_WINDOWS) |
| 1229 | static int os_buf_to_tmp_file_windows(Buf *contents, Buf *suffix, Buf *out_tmp_path) { | |
| 1229 | static Error os_buf_to_tmp_file_windows(Buf *contents, Buf *suffix, Buf *out_tmp_path) { | |
| 1230 | 1230 | char tmp_dir[MAX_PATH + 1]; |
| 1231 | 1231 | if (GetTempPath(MAX_PATH, tmp_dir) == 0) { |
| 1232 | 1232 | zig_panic("GetTempPath failed"); |
| ... | ... | @@ -1255,11 +1255,11 @@ static int os_buf_to_tmp_file_windows(Buf *contents, Buf *suffix, Buf *out_tmp_p |
| 1255 | 1255 | if (fclose(f)) { |
| 1256 | 1256 | zig_panic("fclose failed"); |
| 1257 | 1257 | } |
| 1258 | return 0; | |
| 1258 | return ErrorNone; | |
| 1259 | 1259 | } |
| 1260 | 1260 | #endif |
| 1261 | 1261 | |
| 1262 | int os_buf_to_tmp_file(Buf *contents, Buf *suffix, Buf *out_tmp_path) { | |
| 1262 | Error os_buf_to_tmp_file(Buf *contents, Buf *suffix, Buf *out_tmp_path) { | |
| 1263 | 1263 | #if defined(ZIG_OS_WINDOWS) |
| 1264 | 1264 | return os_buf_to_tmp_file_windows(contents, suffix, out_tmp_path); |
| 1265 | 1265 | #elif defined(ZIG_OS_POSIX) |
| ... | ... | @@ -1269,17 +1269,17 @@ int os_buf_to_tmp_file(Buf *contents, Buf *suffix, Buf *out_tmp_path) { |
| 1269 | 1269 | #endif |
| 1270 | 1270 | } |
| 1271 | 1271 | |
| 1272 | int os_delete_file(Buf *path) { | |
| 1272 | Error os_delete_file(Buf *path) { | |
| 1273 | 1273 | if (remove(buf_ptr(path))) { |
| 1274 | 1274 | return ErrorFileSystem; |
| 1275 | 1275 | } else { |
| 1276 | return 0; | |
| 1276 | return ErrorNone; | |
| 1277 | 1277 | } |
| 1278 | 1278 | } |
| 1279 | 1279 | |
| 1280 | int os_rename(Buf *src_path, Buf *dest_path) { | |
| 1280 | Error os_rename(Buf *src_path, Buf *dest_path) { | |
| 1281 | 1281 | if (buf_eql_buf(src_path, dest_path)) { |
| 1282 | return 0; | |
| 1282 | return ErrorNone; | |
| 1283 | 1283 | } |
| 1284 | 1284 | #if defined(ZIG_OS_WINDOWS) |
| 1285 | 1285 | if (!MoveFileExA(buf_ptr(src_path), buf_ptr(dest_path), MOVEFILE_REPLACE_EXISTING)) { |
| ... | ... | @@ -1290,7 +1290,7 @@ int os_rename(Buf *src_path, Buf *dest_path) { |
| 1290 | 1290 | return ErrorFileSystem; |
| 1291 | 1291 | } |
| 1292 | 1292 | #endif |
| 1293 | return 0; | |
| 1293 | return ErrorNone; | |
| 1294 | 1294 | } |
| 1295 | 1295 | |
| 1296 | 1296 | double os_get_time(void) { |
src/os.hpp+5-6| ... | ... | @@ -13,7 +13,6 @@ |
| 13 | 13 | #include "error.hpp" |
| 14 | 14 | #include "zig_llvm.h" |
| 15 | 15 | #include "windows_sdk.h" |
| 16 | #include "result.hpp" | |
| 17 | 16 | |
| 18 | 17 | #include <stdio.h> |
| 19 | 18 | #include <inttypes.h> |
| ... | ... | @@ -85,7 +84,7 @@ struct OsTimeStamp { |
| 85 | 84 | int os_init(void); |
| 86 | 85 | |
| 87 | 86 | void os_spawn_process(const char *exe, ZigList<const char *> &args, Termination *term); |
| 88 | int os_exec_process(const char *exe, ZigList<const char *> &args, | |
| 87 | Error os_exec_process(const char *exe, ZigList<const char *> &args, | |
| 89 | 88 | Termination *term, Buf *out_stderr, Buf *out_stdout); |
| 90 | 89 | Error os_execv(const char *exe, const char **argv); |
| 91 | 90 | |
| ... | ... | @@ -109,7 +108,7 @@ Error ATTRIBUTE_MUST_USE os_file_overwrite(OsFile file, Buf *contents); |
| 109 | 108 | void os_file_close(OsFile file); |
| 110 | 109 | |
| 111 | 110 | void os_write_file(Buf *full_path, Buf *contents); |
| 112 | int os_copy_file(Buf *src_path, Buf *dest_path); | |
| 111 | Error os_copy_file(Buf *src_path, Buf *dest_path); | |
| 113 | 112 | |
| 114 | 113 | Error ATTRIBUTE_MUST_USE os_fetch_file(FILE *file, Buf *out_contents, bool skip_shebang); |
| 115 | 114 | Error ATTRIBUTE_MUST_USE os_fetch_file_path(Buf *full_path, Buf *out_contents, bool skip_shebang); |
| ... | ... | @@ -119,12 +118,12 @@ Error ATTRIBUTE_MUST_USE os_get_cwd(Buf *out_cwd); |
| 119 | 118 | bool os_stderr_tty(void); |
| 120 | 119 | void os_stderr_set_color(TermColor color); |
| 121 | 120 | |
| 122 | int os_buf_to_tmp_file(Buf *contents, Buf *suffix, Buf *out_tmp_path); | |
| 123 | int os_delete_file(Buf *path); | |
| 121 | Error os_buf_to_tmp_file(Buf *contents, Buf *suffix, Buf *out_tmp_path); | |
| 122 | Error os_delete_file(Buf *path); | |
| 124 | 123 | |
| 125 | 124 | Error ATTRIBUTE_MUST_USE os_file_exists(Buf *full_path, bool *result); |
| 126 | 125 | |
| 127 | int os_rename(Buf *src_path, Buf *dest_path); | |
| 126 | Error os_rename(Buf *src_path, Buf *dest_path); | |
| 128 | 127 | double os_get_time(void); |
| 129 | 128 | |
| 130 | 129 | bool os_is_sep(uint8_t c); |
src/result.hpp deleted-36| ... | ... | @@ -1,36 +0,0 @@ |
| 1 | /* | |
| 2 | * Copyright (c) 2018 Andrew Kelley | |
| 3 | * | |
| 4 | * This file is part of zig, which is MIT licensed. | |
| 5 | * See http://opensource.org/licenses/MIT | |
| 6 | */ | |
| 7 | ||
| 8 | #ifndef ZIG_RESULT_HPP | |
| 9 | #define ZIG_RESULT_HPP | |
| 10 | ||
| 11 | #include "error.hpp" | |
| 12 | ||
| 13 | #include <assert.h> | |
| 14 | ||
| 15 | static inline void assertNoError(Error err) { | |
| 16 | assert(err == ErrorNone); | |
| 17 | } | |
| 18 | ||
| 19 | template<typename T> | |
| 20 | struct Result { | |
| 21 | T data; | |
| 22 | Error err; | |
| 23 | ||
| 24 | Result(T x) : data(x), err(ErrorNone) {} | |
| 25 | ||
| 26 | Result(Error err) : err(err) { | |
| 27 | assert(err != ErrorNone); | |
| 28 | } | |
| 29 | ||
| 30 | T unwrap() { | |
| 31 | assert(err == ErrorNone); | |
| 32 | return data; | |
| 33 | } | |
| 34 | }; | |
| 35 | ||
| 36 | #endif |
src/translate_c.cpp+6-5| ... | ... | @@ -436,7 +436,8 @@ static AstNode *get_global(Context *c, Buf *name) { |
| 436 | 436 | if (entry) |
| 437 | 437 | return entry->value; |
| 438 | 438 | } |
| 439 | if (get_primitive_type(c->codegen, name) != nullptr) { | |
| 439 | ZigType *type; | |
| 440 | if (get_primitive_type(c->codegen, name, &type) != ErrorPrimitiveTypeNotFound) { | |
| 440 | 441 | return trans_create_node_symbol(c, name); |
| 441 | 442 | } |
| 442 | 443 | return nullptr; |
| ... | ... | @@ -4682,10 +4683,10 @@ static void process_preprocessor_entities(Context *c, ASTUnit &unit) { |
| 4682 | 4683 | } |
| 4683 | 4684 | } |
| 4684 | 4685 | |
| 4685 | int parse_h_buf(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, Buf *source, | |
| 4686 | Error parse_h_buf(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, Buf *source, | |
| 4686 | 4687 | CodeGen *codegen, AstNode *source_node) |
| 4687 | 4688 | { |
| 4688 | int err; | |
| 4689 | Error err; | |
| 4689 | 4690 | Buf tmp_file_path = BUF_INIT; |
| 4690 | 4691 | if ((err = os_buf_to_tmp_file(source, buf_create_from_str(".h"), &tmp_file_path))) { |
| 4691 | 4692 | return err; |
| ... | ... | @@ -4698,7 +4699,7 @@ int parse_h_buf(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, Buf *sour |
| 4698 | 4699 | return err; |
| 4699 | 4700 | } |
| 4700 | 4701 | |
| 4701 | int parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const char *target_file, | |
| 4702 | Error parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const char *target_file, | |
| 4702 | 4703 | CodeGen *codegen, AstNode *source_node) |
| 4703 | 4704 | { |
| 4704 | 4705 | Context context = {0}; |
| ... | ... | @@ -4865,5 +4866,5 @@ int parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const ch |
| 4865 | 4866 | |
| 4866 | 4867 | import->root = c->root; |
| 4867 | 4868 | |
| 4868 | return 0; | |
| 4869 | return ErrorNone; | |
| 4869 | 4870 | } |
src/translate_c.hpp+2-2| ... | ... | @@ -11,10 +11,10 @@ |
| 11 | 11 | |
| 12 | 12 | #include "all_types.hpp" |
| 13 | 13 | |
| 14 | int parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const char *target_file, | |
| 14 | Error parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const char *target_file, | |
| 15 | 15 | CodeGen *codegen, AstNode *source_node); |
| 16 | 16 | |
| 17 | int parse_h_buf(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, Buf *source, | |
| 17 | Error parse_h_buf(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, Buf *source, | |
| 18 | 18 | CodeGen *codegen, AstNode *source_node); |
| 19 | 19 | |
| 20 | 20 | #endif |
test/compile_errors.zig+14-10| ... | ... | @@ -1,6 +1,19 @@ |
| 1 | 1 | const tests = @import("tests.zig"); |
| 2 | 2 | |
| 3 | 3 | pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4 | cases.add( | |
| 5 | "exceeded maximum bit width of integer", | |
| 6 | \\export fn entry1() void { | |
| 7 | \\ const T = @IntType(false, 65536); | |
| 8 | \\} | |
| 9 | \\export fn entry2() void { | |
| 10 | \\ var x: i65536 = 1; | |
| 11 | \\} | |
| 12 | , | |
| 13 | ".tmp_source.zig:2:31: error: integer value 65536 cannot be implicitly casted to type 'u16'", | |
| 14 | ".tmp_source.zig:5:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535", | |
| 15 | ); | |
| 16 | ||
| 4 | 17 | cases.add( |
| 5 | 18 | "Panic declared with wrong type signature in tests", |
| 6 | 19 | \\test "" {} |
| ... | ... | @@ -534,15 +547,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 534 | 547 | ".tmp_source.zig:1:9: error: parameter of type 'fn(var)var' must be declared comptime", |
| 535 | 548 | ); |
| 536 | 549 | |
| 537 | cases.add( | |
| 538 | "bit count of @IntType too large", | |
| 539 | \\comptime { | |
| 540 | \\ _ = @IntType(false, @import("std").math.maxInt(u32) + 1); | |
| 541 | \\} | |
| 542 | , | |
| 543 | ".tmp_source.zig:2:57: error: integer value 4294967296 cannot be implicitly casted to type 'u32'", | |
| 544 | ); | |
| 545 | ||
| 546 | 550 | cases.add( |
| 547 | 551 | "optional pointer to void in extern struct", |
| 548 | 552 | \\const Foo = extern struct.{ |
| ... | ... | @@ -4278,7 +4282,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4278 | 4282 | \\ const a: u16 = 300; |
| 4279 | 4283 | \\} |
| 4280 | 4284 | , |
| 4281 | ".tmp_source.zig:1:1: error: declaration shadows type 'u16'", | |
| 4285 | ".tmp_source.zig:1:1: error: declaration shadows primitive type 'u16'", | |
| 4282 | 4286 | ); |
| 4283 | 4287 | |
| 4284 | 4288 | cases.add( |