authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-08 15:56:21-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-08 15:57:25-05:00
log3cf5c2c62b12aa0615633a150a1ea8c279e53004
tree70c8fdf0c5613c0cfb1a2265ba107b2e282ec226
parent3834d3dac0d901e8319aa515b64ade8604fe1ecf
signaturelock-open Commit is signed but in an unrecognized format.

fix regressed tests and update docs to use "type coercion"


14 files changed, 203 insertions(+), 199 deletions(-)

build.zig+1-1
......@@ -155,7 +155,7 @@ fn dependOnLib(b: *Builder, lib_exe_obj: var, dep: LibraryDep) void {
155155 ) catch unreachable;
156156 for (dep.system_libs.toSliceConst()) |lib| {
157157 const static_bare_name = if (mem.eql(u8, lib, "curses"))
158 @as([]const u8,"libncurses.a")
158 @as([]const u8, "libncurses.a")
159159 else
160160 b.fmt("lib{}.a", lib);
161161 const static_lib_name = fs.path.join(
doc/docgen.zig+2-2
......@@ -10,8 +10,8 @@ const testing = std.testing;
1010
1111const max_doc_file_size = 10 * 1024 * 1024;
1212
13const exe_ext = std.build.Target(std.build.Target.Native).exeFileExt();
14const obj_ext = std.build.Target(std.build.Target.Native).oFileExt();
13const exe_ext = @as(std.build.Target, std.build.Target.Native).exeFileExt();
14const obj_ext = @as(std.build.Target, std.build.Target.Native).oFileExt();
1515const tmp_dir_name = "docgen_tmp";
1616const test_out_path = tmp_dir_name ++ fs.path.sep_str ++ "test" ++ exe_ext;
1717
doc/langref.html.in+70-70
......@@ -712,7 +712,7 @@ test "init with undefined" {
712712}
713713 {#code_end#}
714714 <p>
715 {#syntax#}undefined{#endsyntax#} can be {#link|implicitly cast|Implicit Casts#} to any type.
715 {#syntax#}undefined{#endsyntax#} can be {#link|coerced|Type Coercion#} to any type.
716716 Once this happens, it is no longer possible to detect that the value is {#syntax#}undefined{#endsyntax#}.
717717 {#syntax#}undefined{#endsyntax#} means the value could be anything, even something that is nonsense
718718 according to the type. Translated into English, {#syntax#}undefined{#endsyntax#} means "Not a meaningful
......@@ -920,7 +920,7 @@ fn divide(a: i32, b: i32) i32 {
920920 {#syntax#}f128{#endsyntax#}.
921921 </p>
922922 <p>
923 Float literals {#link|implicitly cast|Implicit Casts#} to any floating point type,
923 Float literals {#link|coerce|Type Coercion#} to any floating point type,
924924 and to any {#link|integer|Integers#} type when there is no fractional component.
925925 </p>
926926 {#code_begin|syntax#}
......@@ -950,7 +950,7 @@ const nan = std.math.nan(f128);
950950 {#code_begin|obj|foo#}
951951 {#code_release_fast#}
952952const builtin = @import("builtin");
953const big = f64(1 << 40);
953const big = @as(f64, 1 << 40);
954954
955955export fn foo_strict(x: f64) f64 {
956956 return x + big - big;
......@@ -1652,7 +1652,7 @@ test "iterate over an array" {
16521652 for (message) |byte| {
16531653 sum += byte;
16541654 }
1655 assert(sum == usize('h') + usize('e') + usize('l') * 2 + usize('o'));
1655 assert(sum == 'h' + 'e' + 'l' * 2 + 'o');
16561656}
16571657
16581658// modifiable array
......@@ -2003,7 +2003,7 @@ test "variable alignment" {
20032003 }
20042004}
20052005 {#code_end#}
2006 <p>In the same way that a {#syntax#}*i32{#endsyntax#} can be {#link|implicitly cast|Implicit Casts#} to a
2006 <p>In the same way that a {#syntax#}*i32{#endsyntax#} can be {#link|coerced|Type Coercion#} to a
20072007 {#syntax#}*const i32{#endsyntax#}, a pointer with a larger alignment can be implicitly
20082008 cast to a pointer with a smaller alignment, but not vice versa.
20092009 </p>
......@@ -2019,7 +2019,7 @@ var foo: u8 align(4) = 100;
20192019test "global variable alignment" {
20202020 assert(@typeOf(&foo).alignment == 4);
20212021 assert(@typeOf(&foo) == *align(4) u8);
2022 const slice = (*[1]u8)(&foo)[0..];
2022 const slice = @as(*[1]u8, &foo)[0..];
20232023 assert(@typeOf(slice) == []align(4) u8);
20242024}
20252025
......@@ -2114,7 +2114,7 @@ const fmt = @import("std").fmt;
21142114test "using slices for strings" {
21152115 // Zig has no concept of strings. String literals are arrays of u8, and
21162116 // in general the string type is []u8 (slice of u8).
2117 // Here we implicitly cast [5]u8 to []const u8
2117 // Here we coerce [5]u8 to []const u8
21182118 const hello: []const u8 = "hello";
21192119 const world: []const u8 = "世界";
21202120
......@@ -2778,7 +2778,7 @@ test "simple union" {
27782778 This turns the union into a <em>tagged</em> union, which makes it eligible
27792779 to use with {#link|switch#} expressions. One can use {#link|@TagType#} to
27802780 obtain the enum type from the union type.
2781 Tagged unions implicitly cast to their enum {#link|Implicit Cast: unions and enums#}
2781 Tagged unions coerce to their enum {#link|Type Coercion: unions and enums#}
27822782 </p>
27832783 {#code_begin|test#}
27842784const std = @import("std");
......@@ -2795,7 +2795,7 @@ const ComplexType = union(ComplexTypeTag) {
27952795
27962796test "switch on tagged union" {
27972797 const c = ComplexType{ .Ok = 42 };
2798 assert(ComplexTypeTag(c) == ComplexTypeTag.Ok);
2798 assert(@as(ComplexTypeTag, c) == ComplexTypeTag.Ok);
27992799
28002800 switch (c) {
28012801 ComplexTypeTag.Ok => |value| assert(value == 42),
......@@ -2807,7 +2807,7 @@ test "@TagType" {
28072807 assert(@TagType(ComplexType) == ComplexTypeTag);
28082808}
28092809
2810test "implicit cast to enum" {
2810test "coerce to enum" {
28112811 const c1 = ComplexType{ .Ok = 42 };
28122812 const c2 = ComplexType.NotOk;
28132813
......@@ -2833,7 +2833,7 @@ const ComplexType = union(ComplexTypeTag) {
28332833
28342834test "modify tagged union in switch" {
28352835 var c = ComplexType{ .Ok = 42 };
2836 assert(ComplexTypeTag(c) == ComplexTypeTag.Ok);
2836 assert(@as(ComplexTypeTag, c) == ComplexTypeTag.Ok);
28372837
28382838 switch (c) {
28392839 ComplexTypeTag.Ok => |*value| value.* += 1,
......@@ -3943,7 +3943,7 @@ test "fn reflection" {
39433943 However right now it is hard coded to be a {#syntax#}u16{#endsyntax#}. See <a href="https://github.com/ziglang/zig/issues/786">#768</a>.
39443944 </p>
39453945 <p>
3946 You can {#link|implicitly cast|Implicit Casts#} an error from a subset to a superset:
3946 You can {#link|coerce|Type Coercion#} an error from a subset to a superset:
39473947 </p>
39483948 {#code_begin|test#}
39493949const std = @import("std");
......@@ -3958,7 +3958,7 @@ const AllocationError = error {
39583958 OutOfMemory,
39593959};
39603960
3961test "implicit cast subset to superset" {
3961test "coerce subset to superset" {
39623962 const err = foo(AllocationError.OutOfMemory);
39633963 std.debug.assert(err == FileOpenError.OutOfMemory);
39643964}
......@@ -3968,7 +3968,7 @@ fn foo(err: AllocationError) FileOpenError {
39683968}
39693969 {#code_end#}
39703970 <p>
3971 But you cannot implicitly cast an error from a superset to a subset:
3971 But you cannot {#link|coerce|Type Coercion#} an error from a superset to a subset:
39723972 </p>
39733973 {#code_begin|test_err|not a member of destination error set#}
39743974const FileOpenError = error {
......@@ -3981,7 +3981,7 @@ const AllocationError = error {
39813981 OutOfMemory,
39823982};
39833983
3984test "implicit cast superset to subset" {
3984test "coerce superset to subset" {
39853985 foo(FileOpenError.OutOfMemory) catch {};
39863986}
39873987
......@@ -4008,7 +4008,7 @@ const err = (error {FileNotFound}).FileNotFound;
40084008 It is a superset of all other error sets and a subset of none of them.
40094009 </p>
40104010 <p>
4011 You can implicitly cast any error set to the global one, and you can explicitly
4011 You can {#link|coerce|Type Coercion#} any error set to the global one, and you can explicitly
40124012 cast an error of the global error set to a non-global one. This inserts a language-level
40134013 assert to make sure the error value is in fact in the destination error set.
40144014 </p>
......@@ -4079,7 +4079,7 @@ test "parse u64" {
40794079 <p>
40804080 Within the function definition, you can see some return statements that return
40814081 an error, and at the bottom a return statement that returns a {#syntax#}u64{#endsyntax#}.
4082 Both types {#link|implicitly cast|Implicit Casts#} to {#syntax#}anyerror!u64{#endsyntax#}.
4082 Both types {#link|coerce|Type Coercion#} to {#syntax#}anyerror!u64{#endsyntax#}.
40834083 </p>
40844084 <p>
40854085 What it looks like to use this function varies depending on what you're
......@@ -4218,10 +4218,10 @@ const assert = @import("std").debug.assert;
42184218test "error union" {
42194219 var foo: anyerror!i32 = undefined;
42204220
4221 // Implicitly cast from child type of an error union:
4221 // Coerce from child type of an error union:
42224222 foo = 1234;
42234223
4224 // Implicitly cast from an error set:
4224 // Coerce from an error set:
42254225 foo = error.SomeError;
42264226
42274227 // Use compile-time reflection to access the payload type of an error union:
......@@ -4598,10 +4598,10 @@ fn doAThing(optional_foo: ?*Foo) void {
45984598const assert = @import("std").debug.assert;
45994599
46004600test "optional type" {
4601 // Declare an optional and implicitly cast from null:
4601 // Declare an optional and coerce from null:
46024602 var foo: ?i32 = null;
46034603
4604 // Implicitly cast from child type of an optional
4604 // Coerce from child type of an optional
46054605 foo = 1234;
46064606
46074607 // Use compile-time reflection to access the child type of the optional:
......@@ -4644,38 +4644,38 @@ test "optional pointers" {
46444644 {#header_open|Casting#}
46454645 <p>
46464646 A <strong>type cast</strong> converts a value of one type to another.
4647 Zig has {#link|Implicit Casts#} for conversions that are known to be completely safe and unambiguous,
4647 Zig has {#link|Type Coercion#} for conversions that are known to be completely safe and unambiguous,
46484648 and {#link|Explicit Casts#} for conversions that one would not want to happen on accident.
46494649 There is also a third kind of type conversion called {#link|Peer Type Resolution#} for
46504650 the case when a result type must be decided given multiple operand types.
46514651 </p>
4652 {#header_open|Implicit Casts#}
4652 {#header_open|Type Coercion#}
46534653 <p>
4654 An implicit cast occurs when one type is expected, but different type is provided:
4654 Type coercion occurs when one type is expected, but different type is provided:
46554655 </p>
46564656 {#code_begin|test#}
4657test "implicit cast - variable declaration" {
4657test "type coercion - variable declaration" {
46584658 var a: u8 = 1;
46594659 var b: u16 = a;
46604660}
46614661
4662test "implicit cast - function call" {
4662test "type coercion - function call" {
46634663 var a: u8 = 1;
46644664 foo(a);
46654665}
46664666
46674667fn foo(b: u16) void {}
46684668
4669test "implicit cast - invoke a type as a function" {
4669test "type coercion - @as builtin" {
46704670 var a: u8 = 1;
4671 var b = u16(a);
4671 var b = @as(u16, a);
46724672}
46734673 {#code_end#}
46744674 <p>
4675 Implicit casts are only allowed when it is completely unambiguous how to get from one type to another,
4675 Type coercions are only allowed when it is completely unambiguous how to get from one type to another,
46764676 and the transformation is guaranteed to be safe. There is one exception, which is {#link|C Pointers#}.
46774677 </p>
4678 {#header_open|Implicit Cast: Stricter Qualification#}
4678 {#header_open|Type Coercion: Stricter Qualification#}
46794679 <p>
46804680 Values which have the same representation at runtime can be cast to increase the strictness
46814681 of the qualifiers, no matter how nested the qualifiers are:
......@@ -4690,7 +4690,7 @@ test "implicit cast - invoke a type as a function" {
46904690 These casts are no-ops at runtime since the value representation does not change.
46914691 </p>
46924692 {#code_begin|test#}
4693test "implicit cast - const qualification" {
4693test "type coercion - const qualification" {
46944694 var a: i32 = 1;
46954695 var b: *i32 = &a;
46964696 foo(b);
......@@ -4699,7 +4699,7 @@ test "implicit cast - const qualification" {
46994699fn foo(a: *const i32) void {}
47004700 {#code_end#}
47014701 <p>
4702 In addition, pointers implicitly cast to const optional pointers:
4702 In addition, pointers coerce to const optional pointers:
47034703 </p>
47044704 {#code_begin|test#}
47054705const std = @import("std");
......@@ -4713,10 +4713,10 @@ test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
47134713}
47144714 {#code_end#}
47154715 {#header_close#}
4716 {#header_open|Implicit Cast: Integer and Float Widening#}
4716 {#header_open|Type Coercion: Integer and Float Widening#}
47174717 <p>
4718 {#link|Integers#} implicitly cast to integer types which can represent every value of the old type, and likewise
4719 {#link|Floats#} implicitly cast to float types which can represent every value of the old type.
4718 {#link|Integers#} coerce to integer types which can represent every value of the old type, and likewise
4719 {#link|Floats#} coerce to float types which can represent every value of the old type.
47204720 </p>
47214721 {#code_begin|test#}
47224722const std = @import("std");
......@@ -4748,7 +4748,7 @@ test "float widening" {
47484748}
47494749 {#code_end#}
47504750 {#header_close#}
4751 {#header_open|Implicit Cast: Arrays and Pointers#}
4751 {#header_open|Type Coercion: Arrays and Pointers#}
47524752 {#code_begin|test#}
47534753const std = @import("std");
47544754const assert = std.debug.assert;
......@@ -4797,7 +4797,7 @@ test "*[N]T to []T" {
47974797 assert(std.mem.eql(f32, x2, [2]f32{ 1.2, 3.4 }));
47984798}
47994799
4800// Single-item pointers to arrays can be implicitly casted to
4800// Single-item pointers to arrays can be coerced to
48014801// unknown length pointers.
48024802test "*[N]T to [*]T" {
48034803 var buf: [5]u8 = "hello";
......@@ -4823,15 +4823,15 @@ test "*T to *[1]T" {
48234823 {#code_end#}
48244824 {#see_also|C Pointers#}
48254825 {#header_close#}
4826 {#header_open|Implicit Cast: Optionals#}
4826 {#header_open|Type Coercion: Optionals#}
48274827 <p>
4828 The payload type of {#link|Optionals#}, as well as {#link|null#}, implicitly cast to the optional type.
4828 The payload type of {#link|Optionals#}, as well as {#link|null#}, coerce to the optional type.
48294829 </p>
48304830 {#code_begin|test#}
48314831const std = @import("std");
48324832const assert = std.debug.assert;
48334833
4834test "implicit casting to optionals" {
4834test "coerce to optionals" {
48354835 const x: ?i32 = 1234;
48364836 const y: ?i32 = null;
48374837
......@@ -4844,7 +4844,7 @@ test "implicit casting to optionals" {
48444844const std = @import("std");
48454845const assert = std.debug.assert;
48464846
4847test "implicit casting to optionals wrapped in error union" {
4847test "coerce to optionals wrapped in error union" {
48484848 const x: anyerror!?i32 = 1234;
48494849 const y: anyerror!?i32 = null;
48504850
......@@ -4853,15 +4853,15 @@ test "implicit casting to optionals wrapped in error union" {
48534853}
48544854 {#code_end#}
48554855 {#header_close#}
4856 {#header_open|Implicit Cast: Error Unions#}
4856 {#header_open|Type Coercion: Error Unions#}
48574857 <p>The payload type of an {#link|Error Union Type#} as well as the {#link|Error Set Type#}
4858 implicitly cast to the error union type:
4858 coerce to the error union type:
48594859 </p>
48604860 {#code_begin|test#}
48614861const std = @import("std");
48624862const assert = std.debug.assert;
48634863
4864test "implicit casting to error unions" {
4864test "coercion to error unions" {
48654865 const x: anyerror!i32 = 1234;
48664866 const y: anyerror!i32 = error.Failure;
48674867
......@@ -4870,23 +4870,23 @@ test "implicit casting to error unions" {
48704870}
48714871 {#code_end#}
48724872 {#header_close#}
4873 {#header_open|Implicit Cast: Compile-Time Known Numbers#}
4873 {#header_open|Type Coercion: Compile-Time Known Numbers#}
48744874 <p>When a number is {#link|comptime#}-known to be representable in the destination type,
4875 it may be implicitly casted:
4875 it may be coerced:
48764876 </p>
48774877 {#code_begin|test#}
48784878const std = @import("std");
48794879const assert = std.debug.assert;
48804880
4881test "implicit casting large integer type to smaller one when value is comptime known to fit" {
4881test "coercing large integer type to smaller one when value is comptime known to fit" {
48824882 const x: u64 = 255;
48834883 const y: u8 = x;
48844884 assert(y == 255);
48854885}
48864886 {#code_end#}
48874887 {#header_close#}
4888 {#header_open|Implicit Cast: unions and enums#}
4889 <p>Tagged unions can be implicitly cast to enums, and enums can be implicitly casted to tagged unions
4888 {#header_open|Type Coercion: unions and enums#}
4889 <p>Tagged unions can be coerced to enums, and enums can be coerced to tagged unions
48904890 when they are {#link|comptime#}-known to be a field of the union that has only one possible value, such as
48914891 {#link|void#}:
48924892 </p>
......@@ -4906,7 +4906,7 @@ const U = union(E) {
49064906 Three,
49074907};
49084908
4909test "implicit casting between unions and enums" {
4909test "coercion between unions and enums" {
49104910 var u = U{ .Two = 12.34 };
49114911 var e: E = u;
49124912 assert(e == E.Two);
......@@ -4918,20 +4918,20 @@ test "implicit casting between unions and enums" {
49184918 {#code_end#}
49194919 {#see_also|union|enum#}
49204920 {#header_close#}
4921 {#header_open|Implicit Cast: Zero Bit Types#}
4922 <p>{#link|Zero Bit Types#} may be implicitly casted to single-item {#link|Pointers#},
4921 {#header_open|Type Coercion: Zero Bit Types#}
4922 <p>{#link|Zero Bit Types#} may be coerced to single-item {#link|Pointers#},
49234923 regardless of const.</p>
49244924 <p>TODO document the reasoning for this</p>
49254925 <p>TODO document whether vice versa should work and why</p>
49264926 {#code_begin|test#}
4927test "implicit casting of zero bit types" {
4927test "coercion of zero bit types" {
49284928 var x: void = {};
49294929 var y: *void = x;
49304930 //var z: void = y; // TODO
49314931}
49324932 {#code_end#}
49334933 {#header_close#}
4934 {#header_open|Implicit Cast: undefined#}
4934 {#header_open|Type Coercion: undefined#}
49354935 <p>{#link|undefined#} can be cast to any type.</p>
49364936 {#header_close#}
49374937 {#header_close#}
......@@ -4976,7 +4976,7 @@ test "implicit casting of zero bit types" {
49764976 <li>Some {#link|binary operations|Table of Operators#}</li>
49774977 </ul>
49784978 <p>
4979 This kind of type resolution chooses a type that all peer types can implicitly cast into. Here are
4979 This kind of type resolution chooses a type that all peer types can coerce into. Here are
49804980 some examples:
49814981 </p>
49824982 {#code_begin|test#}
......@@ -5007,8 +5007,8 @@ test "peer resolve array and const slice" {
50075007 comptime testPeerResolveArrayConstSlice(true);
50085008}
50095009fn testPeerResolveArrayConstSlice(b: bool) void {
5010 const value1 = if (b) "aoeu" else ([]const u8)("zz");
5011 const value2 = if (b) ([]const u8)("zz") else "aoeu";
5010 const value1 = if (b) "aoeu" else @as([]const u8, "zz");
5011 const value2 = if (b) @as([]const u8, "zz") else "aoeu";
50125012 assert(mem.eql(u8, value1, "aoeu"));
50135013 assert(mem.eql(u8, value2, "zz"));
50145014}
......@@ -5023,10 +5023,10 @@ test "peer type resolution: ?T and T" {
50235023}
50245024fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
50255025 if (c) {
5026 return if (b) null else usize(0);
5026 return if (b) null else @as(usize, 0);
50275027 }
50285028
5029 return usize(3);
5029 return @as(usize, 3);
50305030}
50315031
50325032test "peer type resolution: [0]u8 and []const u8" {
......@@ -5815,7 +5815,7 @@ test "printf too many arguments" {
58155815 </p>
58165816 <p>
58175817 Zig doesn't care whether the format argument is a string literal,
5818 only that it is a compile-time known value that is implicitly castable to a {#syntax#}[]const u8{#endsyntax#}:
5818 only that it is a compile-time known value that can be coerced to a {#syntax#}[]const u8{#endsyntax#}:
58195819 </p>
58205820 {#code_begin|exe|printf#}
58215821const warn = @import("std").debug.warn;
......@@ -6185,7 +6185,7 @@ fn func() void {
61856185 </p>
61866186 <p>
61876187 {#syntax#}await{#endsyntax#} is a suspend point, and takes as an operand anything that
6188 implicitly casts to {#syntax#}anyframe->T{#endsyntax#}.
6188 coerces to {#syntax#}anyframe->T{#endsyntax#}.
61896189 </p>
61906190 <p>
61916191 There is a common misconception that {#syntax#}await{#endsyntax#} resumes the target function.
......@@ -7116,7 +7116,7 @@ test "field access by string" {
71167116 <pre>{#syntax#}@frame() *@Frame(func){#endsyntax#}</pre>
71177117 <p>
71187118 This function returns a pointer to the frame for a given function. This type
7119 can be {#link|implicitly cast|Implicit Casts#} to {#syntax#}anyframe->T{#endsyntax#} and
7119 can be {#link|coerced|Type Coercion#} to {#syntax#}anyframe->T{#endsyntax#} and
71207120 to {#syntax#}anyframe{#endsyntax#}, where {#syntax#}T{#endsyntax#} is the return type
71217121 of the function in scope.
71227122 </p>
......@@ -7835,7 +7835,7 @@ test "vector @splat" {
78357835 const scalar: u32 = 5;
78367836 const result = @splat(4, scalar);
78377837 comptime assert(@typeOf(result) == @Vector(4, u32));
7838 assert(std.mem.eql(u32, ([4]u32)(result), [_]u32{ 5, 5, 5, 5 }));
7838 assert(std.mem.eql(u32, @as([4]u32, result), [_]u32{ 5, 5, 5, 5 }));
78397839}
78407840 {#code_end#}
78417841 <p>
......@@ -8033,7 +8033,7 @@ test "integer truncation" {
80338033 </p>
80348034 <p>
80358035 If {#syntax#}T{#endsyntax#} is {#syntax#}comptime_int{#endsyntax#},
8036 then this is semantically equivalent to an {#link|implicit cast|Implicit Casts#}.
8036 then this is semantically equivalent to {#link|Type Coercion#}.
80378037 </p>
80388038 {#header_close#}
80398039
......@@ -8537,7 +8537,7 @@ pub fn main() void {
85378537 {#header_close#}
85388538 {#header_open|Cast Truncates Data#}
85398539 <p>At compile-time:</p>
8540 {#code_begin|test_err|integer value 300 cannot be implicitly casted to type 'u8'#}
8540 {#code_begin|test_err|integer value 300 cannot be coerced to type 'u8'#}
85418541comptime {
85428542 const spartan_count: u16 = 300;
85438543 const byte = @intCast(u8, spartan_count);
......@@ -8673,7 +8673,7 @@ test "wraparound addition and subtraction" {
86738673 <p>At compile-time:</p>
86748674 {#code_begin|test_err|operation caused overflow#}
86758675comptime {
8676 const x = @shlExact(u8(0b01010101), 2);
8676 const x = @shlExact(@as(u8, 0b01010101), 2);
86778677}
86788678 {#code_end#}
86798679 <p>At runtime:</p>
......@@ -8691,7 +8691,7 @@ pub fn main() void {
86918691 <p>At compile-time:</p>
86928692 {#code_begin|test_err|exact shift shifted out 1 bits#}
86938693comptime {
8694 const x = @shrExact(u8(0b10101010), 2);
8694 const x = @shrExact(@as(u8, 0b10101010), 2);
86958695}
86968696 {#code_end#}
86978697 <p>At runtime:</p>
......@@ -9543,8 +9543,8 @@ const c = @cImport({
95439543 <p>{#syntax#}[*c]T{#endsyntax#} - C pointer.</p>
95449544 <ul>
95459545 <li>Supports all the syntax of the other two pointer types.</li>
9546 <li>Implicitly casts to other pointer types, as well as {#link|Optional Pointers#}.
9547 When a C pointer is implicitly casted to a non-optional pointer, safety-checked
9546 <li>Coerces to other pointer types, as well as {#link|Optional Pointers#}.
9547 When a C pointer is coerced to a non-optional pointer, safety-checked
95489548 {#link|Undefined Behavior#} occurs if the address is 0.
95499549 </li>
95509550 <li>Allows address 0. On non-freestanding targets, dereferencing address 0 is safety-checked
......@@ -9552,7 +9552,7 @@ const c = @cImport({
95529552 null, just like {#syntax#}?usize{#endsyntax#}. Note that creating an optional C pointer
95539553 is unnecessary as one can use normal {#link|Optional Pointers#}.
95549554 </li>
9555 <li>Supports {#link|implicit casting|Implicit Casts#} to and from integers.</li>
9555 <li>Supports {#link|Type Coercion#} to and from integers.</li>
95569556 <li>Supports comparison with integers.</li>
95579557 <li>Does not support Zig-only pointer attributes such as alignment. Use normal {#link|Pointers#}
95589558 please!</li>
lib/std/event/loop.zig+11-11
......@@ -266,7 +266,7 @@ pub const Loop = struct {
266266 },
267267 };
268268
269 const empty_kevs = ([*]os.Kevent)(undefined)[0..0];
269 const empty_kevs = &[0]os.Kevent{};
270270
271271 for (self.eventfd_resume_nodes) |*eventfd_node, i| {
272272 eventfd_node.* = std.atomic.Stack(ResumeNode.EventFd).Node{
......@@ -289,7 +289,7 @@ pub const Loop = struct {
289289 .next = undefined,
290290 };
291291 self.available_eventfd_resume_nodes.push(eventfd_node);
292 const kevent_array = (*const [1]os.Kevent)(&eventfd_node.data.kevent);
292 const kevent_array = @as(*const [1]os.Kevent, &eventfd_node.data.kevent);
293293 _ = try os.kevent(self.os_data.kqfd, kevent_array, empty_kevs, null);
294294 eventfd_node.data.kevent.flags = os.EV_CLEAR | os.EV_ENABLE;
295295 eventfd_node.data.kevent.fflags = os.NOTE_TRIGGER;
......@@ -305,7 +305,7 @@ pub const Loop = struct {
305305 .data = 0,
306306 .udata = @ptrToInt(&self.final_resume_node),
307307 };
308 const final_kev_arr = (*const [1]os.Kevent)(&self.os_data.final_kevent);
308 const final_kev_arr = @as(*const [1]os.Kevent, &self.os_data.final_kevent);
309309 _ = try os.kevent(self.os_data.kqfd, final_kev_arr, empty_kevs, null);
310310 self.os_data.final_kevent.flags = os.EV_ENABLE;
311311 self.os_data.final_kevent.fflags = os.NOTE_TRIGGER;
......@@ -572,8 +572,8 @@ pub const Loop = struct {
572572 eventfd_node.base.handle = next_tick_node.data;
573573 switch (builtin.os) {
574574 .macosx, .freebsd, .netbsd, .dragonfly => {
575 const kevent_array = (*const [1]os.Kevent)(&eventfd_node.kevent);
576 const empty_kevs = ([*]os.Kevent)(undefined)[0..0];
575 const kevent_array = @as(*const [1]os.Kevent, &eventfd_node.kevent);
576 const empty_kevs = &[0]os.Kevent{};
577577 _ = os.kevent(self.os_data.kqfd, kevent_array, empty_kevs, null) catch {
578578 self.next_tick_queue.unget(next_tick_node);
579579 self.available_eventfd_resume_nodes.push(resume_stack_node);
......@@ -695,8 +695,8 @@ pub const Loop = struct {
695695 },
696696 .macosx, .freebsd, .netbsd, .dragonfly => {
697697 self.posixFsRequest(&self.os_data.fs_end_request);
698 const final_kevent = (*const [1]os.Kevent)(&self.os_data.final_kevent);
699 const empty_kevs = ([*]os.Kevent)(undefined)[0..0];
698 const final_kevent = @as(*const [1]os.Kevent, &self.os_data.final_kevent);
699 const empty_kevs = &[0]os.Kevent{};
700700 // cannot fail because we already added it and this just enables it
701701 _ = os.kevent(self.os_data.kqfd, final_kevent, empty_kevs, null) catch unreachable;
702702 return;
......@@ -753,7 +753,7 @@ pub const Loop = struct {
753753 },
754754 .macosx, .freebsd, .netbsd, .dragonfly => {
755755 var eventlist: [1]os.Kevent = undefined;
756 const empty_kevs = ([*]os.Kevent)(undefined)[0..0];
756 const empty_kevs = &[0]os.Kevent{};
757757 const count = os.kevent(self.os_data.kqfd, empty_kevs, eventlist[0..], null) catch unreachable;
758758 for (eventlist[0..count]) |ev| {
759759 const resume_node = @intToPtr(*ResumeNode, ev.udata);
......@@ -815,8 +815,8 @@ pub const Loop = struct {
815815 self.os_data.fs_queue.put(request_node);
816816 switch (builtin.os) {
817817 .macosx, .freebsd, .netbsd, .dragonfly => {
818 const fs_kevs = (*const [1]os.Kevent)(&self.os_data.fs_kevent_wake);
819 const empty_kevs = ([*]os.Kevent)(undefined)[0..0];
818 const fs_kevs = @as(*const [1]os.Kevent, &self.os_data.fs_kevent_wake);
819 const empty_kevs = &[0]os.Kevent{};
820820 _ = os.kevent(self.os_data.fs_kqfd, fs_kevs, empty_kevs, null) catch unreachable;
821821 },
822822 .linux => {
......@@ -890,7 +890,7 @@ pub const Loop = struct {
890890 }
891891 },
892892 .macosx, .freebsd, .netbsd, .dragonfly => {
893 const fs_kevs = (*const [1]os.Kevent)(&self.os_data.fs_kevent_wait);
893 const fs_kevs = @as(*const [1]os.Kevent, &self.os_data.fs_kevent_wait);
894894 var out_kevs: [1]os.Kevent = undefined;
895895 _ = os.kevent(self.os_data.fs_kqfd, fs_kevs, out_kevs[0..], null) catch unreachable;
896896 },
lib/std/fs.zig+1-1
......@@ -584,7 +584,7 @@ pub const Dir = struct {
584584 .FileBothDirectoryInformation,
585585 w.FALSE,
586586 null,
587 if (self.first) w.BOOLEAN(w.TRUE) else w.BOOLEAN(w.FALSE),
587 if (self.first) @as(w.BOOLEAN, w.TRUE) else @as(w.BOOLEAN, w.FALSE),
588588 );
589589 self.first = false;
590590 if (io.Information == 0) return null;
lib/std/os.zig+2-2
......@@ -1126,9 +1126,9 @@ pub fn unlinkatW(dirfd: fd_t, sub_path_w: [*]const u16, flags: u32) UnlinkatErro
11261126
11271127 const want_rmdir_behavior = (flags & AT_REMOVEDIR) != 0;
11281128 const create_options_flags = if (want_rmdir_behavior)
1129 w.ULONG(w.FILE_DELETE_ON_CLOSE)
1129 @as(w.ULONG, w.FILE_DELETE_ON_CLOSE)
11301130 else
1131 w.ULONG(w.FILE_DELETE_ON_CLOSE | w.FILE_NON_DIRECTORY_FILE);
1131 @as(w.ULONG, w.FILE_DELETE_ON_CLOSE | w.FILE_NON_DIRECTORY_FILE);
11321132
11331133 const path_len_bytes = @intCast(u16, mem.toSliceConst(u16, sub_path_w).len * 2);
11341134 var nt_name = w.UNICODE_STRING{
lib/std/os/windows.zig+1-1
......@@ -262,7 +262,7 @@ pub const ReadFileError = error{Unexpected};
262262pub fn ReadFile(in_hFile: HANDLE, buffer: []u8) ReadFileError!usize {
263263 var index: usize = 0;
264264 while (index < buffer.len) {
265 const want_read_count = @intCast(DWORD, math.min(DWORD(maxInt(DWORD)), buffer.len - index));
265 const want_read_count = @intCast(DWORD, math.min(@as(DWORD, maxInt(DWORD)), buffer.len - index));
266266 var amt_read: DWORD = undefined;
267267 if (kernel32.ReadFile(in_hFile, buffer.ptr + index, want_read_count, &amt_read, null) == 0) {
268268 switch (kernel32.GetLastError()) {
lib/std/os/windows/bits.zig+12-12
......@@ -69,7 +69,7 @@ pub const FALSE = 0;
6969
7070pub const INVALID_HANDLE_VALUE = @intToPtr(HANDLE, maxInt(usize));
7171
72pub const INVALID_FILE_ATTRIBUTES = DWORD(maxInt(DWORD));
72pub const INVALID_FILE_ATTRIBUTES = @as(DWORD, maxInt(DWORD));
7373
7474pub const FILE_ALL_INFORMATION = extern struct {
7575 BasicInformation: FILE_BASIC_INFORMATION,
......@@ -571,16 +571,16 @@ pub const KF_FLAG_SIMPLE_IDLIST = 256;
571571pub const KF_FLAG_ALIAS_ONLY = -2147483648;
572572
573573pub const S_OK = 0;
574pub const E_NOTIMPL = @bitCast(c_long, c_ulong(0x80004001));
575pub const E_NOINTERFACE = @bitCast(c_long, c_ulong(0x80004002));
576pub const E_POINTER = @bitCast(c_long, c_ulong(0x80004003));
577pub const E_ABORT = @bitCast(c_long, c_ulong(0x80004004));
578pub const E_FAIL = @bitCast(c_long, c_ulong(0x80004005));
579pub const E_UNEXPECTED = @bitCast(c_long, c_ulong(0x8000FFFF));
580pub const E_ACCESSDENIED = @bitCast(c_long, c_ulong(0x80070005));
581pub const E_HANDLE = @bitCast(c_long, c_ulong(0x80070006));
582pub const E_OUTOFMEMORY = @bitCast(c_long, c_ulong(0x8007000E));
583pub const E_INVALIDARG = @bitCast(c_long, c_ulong(0x80070057));
574pub const E_NOTIMPL = @bitCast(c_long, @as(c_ulong, 0x80004001));
575pub const E_NOINTERFACE = @bitCast(c_long, @as(c_ulong, 0x80004002));
576pub const E_POINTER = @bitCast(c_long, @as(c_ulong, 0x80004003));
577pub const E_ABORT = @bitCast(c_long, @as(c_ulong, 0x80004004));
578pub const E_FAIL = @bitCast(c_long, @as(c_ulong, 0x80004005));
579pub const E_UNEXPECTED = @bitCast(c_long, @as(c_ulong, 0x8000FFFF));
580pub const E_ACCESSDENIED = @bitCast(c_long, @as(c_ulong, 0x80070005));
581pub const E_HANDLE = @bitCast(c_long, @as(c_ulong, 0x80070006));
582pub const E_OUTOFMEMORY = @bitCast(c_long, @as(c_ulong, 0x8007000E));
583pub const E_INVALIDARG = @bitCast(c_long, @as(c_ulong, 0x80070057));
584584
585585pub const FILE_FLAG_BACKUP_SEMANTICS = 0x02000000;
586586pub const FILE_FLAG_DELETE_ON_CLOSE = 0x04000000;
......@@ -873,4 +873,4 @@ pub const CURDIR = extern struct {
873873 Handle: HANDLE,
874874};
875875
876pub const DUPLICATE_SAME_ACCESS = 2;
\ No newline at end of file
876pub const DUPLICATE_SAME_ACCESS = 2;
src-self-hosted/translate_c.zig+10-6
......@@ -774,12 +774,14 @@ fn transCCast(
774774 if (qualTypeIsPtr(dst_type) and qualTypeIsPtr(src_type))
775775 return transCPtrCast(rp, loc, dst_type, src_type, expr);
776776 if (cIsUnsignedInteger(dst_type) and qualTypeIsPtr(src_type)) {
777 const cast_node = try transCreateNodeFnCall(rp.c, try transQualType(rp, dst_type, loc));
777 const cast_node = try transCreateNodeBuiltinFnCall(rp.c, "@as");
778 try cast_node.params.push(try transQualType(rp, dst_type, loc));
779 _ = try appendToken(rp.c, .Comma, ",");
778780 const builtin_node = try transCreateNodeBuiltinFnCall(rp.c, "@ptrToInt");
779781 try builtin_node.params.push(expr);
780782 builtin_node.rparen_token = try appendToken(rp.c, .RParen, ")");
781 try cast_node.op.Call.params.push(&builtin_node.base);
782 cast_node.rtoken = try appendToken(rp.c, .RParen, ")");
783 try cast_node.params.push(&builtin_node.base);
784 cast_node.rparen_token = try appendToken(rp.c, .RParen, ")");
783785 return &cast_node.base;
784786 }
785787 if (cIsUnsignedInteger(src_type) and qualTypeIsPtr(dst_type)) {
......@@ -793,9 +795,11 @@ fn transCCast(
793795 // TODO: maybe widen to increase size
794796 // TODO: maybe bitcast to change sign
795797 // TODO: maybe truncate to reduce size
796 const cast_node = try transCreateNodeFnCall(rp.c, try transQualType(rp, dst_type, loc));
797 try cast_node.op.Call.params.push(expr);
798 cast_node.rtoken = try appendToken(rp.c, .RParen, ")");
798 const cast_node = try transCreateNodeBuiltinFnCall(rp.c, "@as");
799 try cast_node.params.push(try transQualType(rp, dst_type, loc));
800 _ = try appendToken(rp.c, .Comma, ",");
801 try cast_node.params.push(expr);
802 cast_node.rparen_token = try appendToken(rp.c, .RParen, ")");
799803 return &cast_node.base;
800804}
801805
src/ir.cpp+8-7
......@@ -6339,7 +6339,8 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
63396339 return irb->codegen->invalid_instruction;
63406340
63416341 if (result_loc_cast != nullptr) {
6342 IrInstruction *implicit_cast = ir_build_implicit_cast(irb, scope, node, init_value, result_loc_cast);
6342 IrInstruction *implicit_cast = ir_build_implicit_cast(irb, scope, init_value->source_node,
6343 init_value, result_loc_cast);
63436344 ir_build_end_expr(irb, scope, node, implicit_cast, &result_loc_var->base);
63446345 }
63456346
......@@ -9610,7 +9611,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
96109611 }
96119612
96129613 ir_add_error(ira, instruction,
9613 buf_sprintf("%s value %s cannot be implicitly casted to type '%s'",
9614 buf_sprintf("%s value %s cannot be coerced to type '%s'",
96149615 num_lit_str,
96159616 buf_ptr(val_buf),
96169617 buf_ptr(&other_type->name)));
......@@ -13065,8 +13066,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1306513066 return ira->codegen->invalid_instruction;
1306613067}
1306713068
13068static IrInstruction *ir_implicit_cast_with_result(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type,
13069 ResultLoc *result_loc)
13069static IrInstruction *ir_implicit_cast_with_result(IrAnalyze *ira, IrInstruction *source_instr,
13070 IrInstruction *value, ZigType *expected_type, ResultLoc *result_loc)
1307013071{
1307113072 assert(value);
1307213073 assert(value != ira->codegen->invalid_instruction);
......@@ -13080,11 +13081,11 @@ static IrInstruction *ir_implicit_cast_with_result(IrAnalyze *ira, IrInstruction
1308013081 if (value->value.type->id == ZigTypeIdUnreachable)
1308113082 return value;
1308213083
13083 return ir_analyze_cast(ira, value, expected_type, value, result_loc);
13084 return ir_analyze_cast(ira, source_instr, expected_type, value, result_loc);
1308413085}
1308513086
1308613087static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type) {
13087 return ir_implicit_cast_with_result(ira, value, expected_type, nullptr);
13088 return ir_implicit_cast_with_result(ira, value, value, expected_type, nullptr);
1308813089}
1308913090
1309013091static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr,
......@@ -26068,7 +26069,7 @@ static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrIns
2606826069 ZigType *dest_type = ir_resolve_type(ira, instruction->result_loc_cast->base.source_instruction->child);
2606926070 if (type_is_invalid(dest_type))
2607026071 return ira->codegen->invalid_instruction;
26071 return ir_implicit_cast(ira, operand, dest_type);
26072 return ir_implicit_cast_with_result(ira, &instruction->base, operand, dest_type, nullptr);
2607226073}
2607326074
2607426075static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstructionBitCastSrc *instruction) {
src/translate_c.cpp+15-14
......@@ -221,6 +221,15 @@ static AstNode *trans_create_node_opaque(Context *c) {
221221 return trans_create_node_builtin_fn_call_str(c, "OpaqueType");
222222}
223223
224static AstNode *trans_create_node_cast(Context *c, AstNode *dest_type, AstNode *operand) {
225 AstNode *node = trans_create_node(c, NodeTypeFnCallExpr);
226 node->data.fn_call_expr.fn_ref_expr = trans_create_node_symbol(c, buf_create_from_str("as"));
227 node->data.fn_call_expr.modifier = CallModifierBuiltin;
228 node->data.fn_call_expr.params.append(dest_type);
229 node->data.fn_call_expr.params.append(operand);
230 return node;
231}
232
224233static AstNode *trans_create_node_fn_call_1(Context *c, AstNode *fn_ref_expr, AstNode *arg1) {
225234 AstNode *node = trans_create_node(c, NodeTypeFnCallExpr);
226235 node->data.fn_call_expr.fn_ref_expr = fn_ref_expr;
......@@ -337,14 +346,6 @@ static AstNode *trans_create_node_unsigned(Context *c, uint64_t x) {
337346 return trans_create_node_unsigned_negative(c, x, false);
338347}
339348
340static AstNode *trans_create_node_cast(Context *c, AstNode *dest, AstNode *src) {
341 AstNode *node = trans_create_node(c, NodeTypeFnCallExpr);
342 node->data.fn_call_expr.fn_ref_expr = dest;
343 node->data.fn_call_expr.params.resize(1);
344 node->data.fn_call_expr.params.items[0] = src;
345 return node;
346}
347
348349static AstNode *trans_create_node_unsigned_negative_type(Context *c, uint64_t x, bool is_negative,
349350 const char *type_name)
350351{
......@@ -701,7 +702,7 @@ static AstNode* trans_c_cast(Context *c, ZigClangSourceLocation source_location,
701702 if (c_is_unsigned_integer(c, dest_type) && qual_type_is_ptr(src_type)) {
702703 AstNode *addr_node = trans_create_node_builtin_fn_call_str(c, "ptrToInt");
703704 addr_node->data.fn_call_expr.params.append(expr);
704 return trans_create_node_fn_call_1(c, trans_qual_type(c, dest_type, source_location), addr_node);
705 return trans_create_node_cast(c, trans_qual_type(c, dest_type, source_location), addr_node);
705706 }
706707 if (c_is_unsigned_integer(c, src_type) && qual_type_is_ptr(dest_type)) {
707708 AstNode *ptr_node = trans_create_node_builtin_fn_call_str(c, "intToPtr");
......@@ -712,7 +713,7 @@ static AstNode* trans_c_cast(Context *c, ZigClangSourceLocation source_location,
712713 // TODO: maybe widen to increase size
713714 // TODO: maybe bitcast to change sign
714715 // TODO: maybe truncate to reduce size
715 return trans_create_node_fn_call_1(c, trans_qual_type(c, dest_type, source_location), expr);
716 return trans_create_node_cast(c, trans_qual_type(c, dest_type, source_location), expr);
716717}
717718
718719static bool c_is_signed_integer(Context *c, ZigClangQualType qt) {
......@@ -1527,7 +1528,7 @@ static AstNode *trans_create_shift_op(Context *c, TransScope *scope, ZigClangQua
15271528
15281529 AstNode *rhs = trans_expr(c, ResultUsedYes, scope, rhs_expr, TransRValue);
15291530 if (rhs == nullptr) return nullptr;
1530 AstNode *coerced_rhs = trans_create_node_fn_call_1(c, rhs_type, rhs);
1531 AstNode *coerced_rhs = trans_create_node_cast(c, rhs_type, rhs);
15311532
15321533 return trans_create_node_bin_op(c, lhs, bin_op, coerced_rhs);
15331534}
......@@ -1702,7 +1703,7 @@ static AstNode *trans_create_compound_assign_shift(Context *c, ResultUsed result
17021703
17031704 AstNode *rhs = trans_expr(c, ResultUsedYes, scope, ZigClangCompoundAssignOperator_getRHS(stmt), TransRValue);
17041705 if (rhs == nullptr) return nullptr;
1705 AstNode *coerced_rhs = trans_create_node_fn_call_1(c, rhs_type, rhs);
1706 AstNode *coerced_rhs = trans_create_node_cast(c, rhs_type, rhs);
17061707
17071708 return trans_create_node_bin_op(c, lhs, assign_op, coerced_rhs);
17081709 } else {
......@@ -1733,7 +1734,7 @@ static AstNode *trans_create_compound_assign_shift(Context *c, ResultUsed result
17331734
17341735 AstNode *rhs = trans_expr(c, ResultUsedYes, &child_scope->base, ZigClangCompoundAssignOperator_getRHS(stmt), TransRValue);
17351736 if (rhs == nullptr) return nullptr;
1736 AstNode *coerced_rhs = trans_create_node_fn_call_1(c, rhs_type, rhs);
1737 AstNode *coerced_rhs = trans_create_node_cast(c, rhs_type, rhs);
17371738
17381739 // operation_type(*_ref)
17391740 AstNode *operation_type_cast = trans_c_cast(c, rhs_location,
......@@ -2684,7 +2685,7 @@ static AstNode *to_enum_zero_cmp(Context *c, AstNode *expr, AstNode *enum_type)
26842685
26852686 // @TagType(Enum)(0)
26862687 AstNode *zero = trans_create_node_unsigned_negative(c, 0, false);
2687 AstNode *casted_zero = trans_create_node_fn_call_1(c, tag_type, zero);
2688 AstNode *casted_zero = trans_create_node_cast(c, tag_type, zero);
26882689
26892690 // @bitCast(Enum, @TagType(Enum)(0))
26902691 AstNode *bitcast = trans_create_node_builtin_fn_call_str(c, "bitCast");
test/compare_output.zig+9-9
......@@ -145,23 +145,23 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
145145 \\ _ = c._setmode(1, c._O_BINARY);
146146 \\ }
147147 \\ _ = c.printf(c"0: %llu\n",
148 \\ u64(0));
148 \\ @as(u64, 0));
149149 \\ _ = c.printf(c"320402575052271: %llu\n",
150 \\ u64(320402575052271));
150 \\ @as(u64, 320402575052271));
151151 \\ _ = c.printf(c"0x01236789abcdef: %llu\n",
152 \\ u64(0x01236789abcdef));
152 \\ @as(u64, 0x01236789abcdef));
153153 \\ _ = c.printf(c"0xffffffffffffffff: %llu\n",
154 \\ u64(0xffffffffffffffff));
154 \\ @as(u64, 0xffffffffffffffff));
155155 \\ _ = c.printf(c"0x000000ffffffffffffffff: %llu\n",
156 \\ u64(0x000000ffffffffffffffff));
156 \\ @as(u64, 0x000000ffffffffffffffff));
157157 \\ _ = c.printf(c"0o1777777777777777777777: %llu\n",
158 \\ u64(0o1777777777777777777777));
158 \\ @as(u64, 0o1777777777777777777777));
159159 \\ _ = c.printf(c"0o0000001777777777777777777777: %llu\n",
160 \\ u64(0o0000001777777777777777777777));
160 \\ @as(u64, 0o0000001777777777777777777777));
161161 \\ _ = c.printf(c"0b1111111111111111111111111111111111111111111111111111111111111111: %llu\n",
162 \\ u64(0b1111111111111111111111111111111111111111111111111111111111111111));
162 \\ @as(u64, 0b1111111111111111111111111111111111111111111111111111111111111111));
163163 \\ _ = c.printf(c"0b0000001111111111111111111111111111111111111111111111111111111111111111: %llu\n",
164 \\ u64(0b0000001111111111111111111111111111111111111111111111111111111111111111));
164 \\ @as(u64, 0b0000001111111111111111111111111111111111111111111111111111111111111111));
165165 \\
166166 \\ _ = c.printf(c"\n");
167167 \\
test/compile_errors.zig+35-37
......@@ -189,7 +189,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
189189 \\ const x = 1 << &@as(u8, 10);
190190 \\}
191191 ,
192 "tmp.zig:2:23: error: shift amount has to be an integer type, but found '*u8'",
192 "tmp.zig:2:21: error: shift amount has to be an integer type, but found '*u8'",
193193 "tmp.zig:2:17: note: referenced here",
194194 );
195195
......@@ -199,8 +199,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
199199 \\ const x = &@as(u8, 1) << 10;
200200 \\}
201201 ,
202 "tmp.zig:2:18: error: bit shifting operation expected integer type, found '*u8'",
203 "tmp.zig:2:22: note: referenced here",
202 "tmp.zig:2:16: error: bit shifting operation expected integer type, found '*u8'",
203 "tmp.zig:2:27: note: referenced here",
204204 );
205205
206206 cases.add(
......@@ -245,7 +245,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
245245 \\}
246246 ,
247247 "tmp.zig:2:20: error: expected type 'u29', found 'bool'",
248 "tmp.zig:5:22: error: fractional component prevents float value 12.340000 from being casted to type 'u29'",
248 "tmp.zig:5:19: error: fractional component prevents float value 12.340000 from being casted to type 'u29'",
249249 );
250250
251251 cases.addCase(x: {
......@@ -1243,7 +1243,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
12431243 \\ var ptr: [*c]u8 = x;
12441244 \\}
12451245 ,
1246 "tmp.zig:2:33: error: integer value 18446744073709551617 cannot be implicitly casted to type 'usize'",
1246 "tmp.zig:2:33: error: integer value 18446744073709551617 cannot be coerced to type 'usize'",
12471247 "tmp.zig:6:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8'",
12481248 );
12491249
......@@ -1300,14 +1300,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
13001300 \\ var z = @truncate(u8, @as(u16, undefined));
13011301 \\}
13021302 ,
1303 "tmp.zig:2:30: error: use of undefined value here causes undefined behavior",
1303 "tmp.zig:2:27: error: use of undefined value here causes undefined behavior",
13041304 );
13051305
13061306 cases.addTest(
13071307 "return invalid type from test",
13081308 \\test "example" { return 1; }
13091309 ,
1310 "tmp.zig:1:25: error: integer value 1 cannot be implicitly casted to type 'void'",
1310 "tmp.zig:1:25: error: integer value 1 cannot be coerced to type 'void'",
13111311 );
13121312
13131313 cases.add(
......@@ -1464,8 +1464,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
14641464 \\ var byte: u8 = spartan_count;
14651465 \\}
14661466 ,
1467 "tmp.zig:3:31: error: integer value 300 cannot be implicitly casted to type 'u8'",
1468 "tmp.zig:7:22: error: integer value 300 cannot be implicitly casted to type 'u8'",
1467 "tmp.zig:3:31: error: integer value 300 cannot be coerced to type 'u8'",
1468 "tmp.zig:7:22: error: integer value 300 cannot be coerced to type 'u8'",
14691469 "tmp.zig:11:20: error: expected type 'u8', found 'u16'",
14701470 );
14711471
......@@ -1498,7 +1498,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
14981498 \\ var x: i65536 = 1;
14991499 \\}
15001500 ,
1501 "tmp.zig:2:31: error: integer value 65536 cannot be implicitly casted to type 'u16'",
1501 "tmp.zig:2:31: error: integer value 65536 cannot be coerced to type 'u16'",
15021502 "tmp.zig:5:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535",
15031503 );
15041504
......@@ -1689,7 +1689,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
16891689 \\ const x = @floatToInt(i32, @as(i32, 54));
16901690 \\}
16911691 ,
1692 "tmp.zig:2:35: error: expected float type, found 'i32'",
1692 "tmp.zig:2:32: error: expected float type, found 'i32'",
16931693 );
16941694
16951695 cases.add(
......@@ -1698,7 +1698,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
16981698 \\ const x = @floatToInt(i8, 200);
16991699 \\}
17001700 ,
1701 "tmp.zig:2:31: error: integer value 200 cannot be implicitly casted to type 'i8'",
1701 "tmp.zig:2:31: error: integer value 200 cannot be coerced to type 'i8'",
17021702 );
17031703
17041704 cases.add(
......@@ -2207,7 +2207,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
22072207 \\ var rule_set = try Foo.init();
22082208 \\}
22092209 ,
2210 "tmp.zig:2:13: error: expected type 'i32', found 'type'",
2210 "tmp.zig:2:10: error: expected type 'i32', found 'type'",
22112211 );
22122212
22132213 cases.add(
......@@ -2357,10 +2357,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
23572357 cases.add(
23582358 "comptime slice of undefined pointer non-zero len",
23592359 \\export fn entry() void {
2360 \\ const slice = ([*]i32)(undefined)[0..1];
2360 \\ const slice = @as([*]i32, undefined)[0..1];
23612361 \\}
23622362 ,
2363 "tmp.zig:2:38: error: non-zero length slice of undefined pointer",
2363 "tmp.zig:2:41: error: non-zero length slice of undefined pointer",
23642364 );
23652365
23662366 cases.add(
......@@ -2660,7 +2660,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
26602660 \\ const x = @as(usize, -10);
26612661 \\}
26622662 ,
2663 "tmp.zig:2:21: error: cannot cast negative value -10 to unsigned integer type 'usize'",
2663 "tmp.zig:2:26: error: cannot cast negative value -10 to unsigned integer type 'usize'",
26642664 );
26652665
26662666 cases.add(
......@@ -3388,7 +3388,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
33883388 \\}
33893389 \\export fn entry() void { f(true); g(true); }
33903390 ,
3391 "tmp.zig:2:42: error: integer value 1 cannot be implicitly casted to type 'void'",
3391 "tmp.zig:2:21: error: expected type 'i32', found 'void'",
33923392 "tmp.zig:5:15: error: incompatible types: 'i32' and 'void'",
33933393 );
33943394
......@@ -3524,7 +3524,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
35243524 \\}
35253525 \\export fn entry() void { _ = f(); }
35263526 ,
3527 "tmp.zig:2:15: error: unreachable code",
3527 "tmp.zig:2:12: error: unreachable code",
35283528 );
35293529
35303530 cases.add(
......@@ -3765,7 +3765,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
37653765 \\const x : u8 = 300;
37663766 \\export fn entry() usize { return @sizeOf(@typeOf(x)); }
37673767 ,
3768 "tmp.zig:1:16: error: integer value 300 cannot be implicitly casted to type 'u8'",
3768 "tmp.zig:1:16: error: integer value 300 cannot be coerced to type 'u8'",
37693769 );
37703770
37713771 cases.add(
......@@ -3897,8 +3897,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
38973897 ,
38983898 "tmp.zig:1:21: error: division by zero",
38993899 "tmp.zig:2:25: error: division by zero",
3900 "tmp.zig:3:22: error: division by zero",
3901 "tmp.zig:4:26: error: division by zero",
3900 "tmp.zig:3:27: error: division by zero",
3901 "tmp.zig:4:31: error: division by zero",
39023902 );
39033903
39043904 cases.add(
......@@ -4908,7 +4908,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
49084908 \\ var vga_mem: u16 = 0xB8000;
49094909 \\}
49104910 ,
4911 "tmp.zig:2:24: error: integer value 753664 cannot be implicitly casted to type 'u16'",
4911 "tmp.zig:2:24: error: integer value 753664 cannot be coerced to type 'u16'",
49124912 );
49134913
49144914 cases.add(
......@@ -5080,7 +5080,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
50805080 cases.add(
50815081 "pass const ptr to mutable ptr fn",
50825082 \\fn foo() bool {
5083 \\ const a = ([]const u8)("a",);
5083 \\ const a = @as([]const u8, "a",);
50845084 \\ const b = &a;
50855085 \\ return ptrEql(b, b);
50865086 \\}
......@@ -5584,7 +5584,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
55845584 \\ return @as(i32, 12.34);
55855585 \\}
55865586 ,
5587 "tmp.zig:2:16: error: fractional component prevents float value 12.340000 from being casted to type 'i32'",
5587 "tmp.zig:2:21: error: fractional component prevents float value 12.340000 from being casted to type 'i32'",
55885588 );
55895589
55905590 cases.add(
......@@ -5671,16 +5671,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
56715671 \\export fn entry() void {
56725672 \\ var foo = Foo { .a = 1, .b = 10 };
56735673 \\ foo.b += 1;
5674 \\ bar((*[1]u32)(&foo.b)[0..]);
5674 \\ bar(@as(*[1]u32, &foo.b)[0..]);
56755675 \\}
56765676 \\
56775677 \\fn bar(x: []u32) void {
56785678 \\ x[0] += 1;
56795679 \\}
56805680 ,
5681 "tmp.zig:9:18: error: cast increases pointer alignment",
5682 "tmp.zig:9:23: note: '*align(1) u32' has alignment 1",
5683 "tmp.zig:9:18: note: '*[1]u32' has alignment 4",
5681 "tmp.zig:9:9: error: cast increases pointer alignment",
5682 "tmp.zig:9:26: note: '*align(1) u32' has alignment 1",
5683 "tmp.zig:9:9: note: '*[1]u32' has alignment 4",
56845684 );
56855685
56865686 cases.add(
......@@ -5702,7 +5702,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
57025702 \\ @alignCast(4, @as(u32, 3));
57035703 \\}
57045704 ,
5705 "tmp.zig:2:22: error: expected pointer or slice, found 'u32'",
5705 "tmp.zig:2:19: error: expected pointer or slice, found 'u32'",
57065706 );
57075707
57085708 cases.add(
......@@ -5740,7 +5740,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
57405740 );
57415741
57425742 cases.add(
5743 "wrong pointer implicitly casted to pointer to @OpaqueType()",
5743 "wrong pointer coerced to pointer to @OpaqueType()",
57445744 \\const Derp = @OpaqueType();
57455745 \\extern fn bar(d: *Derp) void;
57465746 \\export fn foo() void {
......@@ -5793,7 +5793,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
57935793 "tmp.zig:17:4: error: variable of type 'Opaque' not allowed",
57945794 "tmp.zig:20:4: error: variable of type 'type' must be const or comptime",
57955795 "tmp.zig:23:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime",
5796 "tmp.zig:26:4: error: unreachable code",
5796 "tmp.zig:26:22: error: unreachable code",
57975797 );
57985798
57995799 cases.add(
......@@ -5803,7 +5803,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
58035803 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, @as(u32, 1234), @as(u32, 1234))) {}
58045804 \\}
58055805 ,
5806 "tmp.zig:3:50: error: expected type 'std.builtin.AtomicOrder', found 'u32'",
5806 "tmp.zig:3:47: error: expected type 'std.builtin.AtomicOrder', found 'u32'",
58075807 );
58085808
58095809 cases.add(
......@@ -5813,7 +5813,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
58135813 \\ @export("entry", entry, @as(u32, 1234));
58145814 \\}
58155815 ,
5816 "tmp.zig:3:32: error: expected type 'std.builtin.GlobalLinkage', found 'u32'",
5816 "tmp.zig:3:29: error: expected type 'std.builtin.GlobalLinkage', found 'u32'",
58175817 );
58185818
58195819 cases.add(
......@@ -6185,7 +6185,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
61856185 \\};
61866186 \\
61876187 \\export fn entry() void {
6188 \\ var y = u3(3);
6188 \\ var y = @as(u3, 3);
61896189 \\ var x = @intToEnum(Small, y);
61906190 \\}
61916191 ,
......@@ -6722,8 +6722,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
67226722 "tmp.zig:1:1: note: declared here",
67236723 );
67246724
6725 // fixed bug #2032
6726 cases.add(
6725 cases.add( // fixed bug #2032
67276726 "compile diagnostic string for top level decl type",
67286727 \\export fn entry() void {
67296728 \\ var foo: u32 = @This(){};
......@@ -6731,6 +6730,5 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
67316730 ,
67326731 "tmp.zig:2:27: error: expected type 'u32', found '(root)'",
67336732 "tmp.zig:1:1: note: (root) declared here",
6734 "tmp.zig:2:5: note: referenced here",
67356733 );
67366734}
test/translate_c.zig+26-26
......@@ -144,7 +144,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
144144 \\pub extern fn foo() void;
145145 \\pub fn bar() void {
146146 \\ var func_ptr: ?*c_void = @ptrCast(?*c_void, foo);
147 \\ var typed_func_ptr: ?extern fn () void = @intToPtr(?extern fn () void, c_ulong(@ptrToInt(func_ptr)));
147 \\ var typed_func_ptr: ?extern fn () void = @intToPtr(?extern fn () void, @as(c_ulong, @ptrToInt(func_ptr)));
148148 \\}
149149 );
150150
......@@ -567,37 +567,37 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
567567 cases.add("l integer suffix after hex literal",
568568 \\#define SDL_INIT_VIDEO 0x00000020l /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
569569 ,
570 \\pub const SDL_INIT_VIDEO = c_long(32);
570 \\pub const SDL_INIT_VIDEO = @as(c_long, 32);
571571 );
572572
573573 cases.add("ul integer suffix after hex literal",
574574 \\#define SDL_INIT_VIDEO 0x00000020ul /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
575575 ,
576 \\pub const SDL_INIT_VIDEO = c_ulong(32);
576 \\pub const SDL_INIT_VIDEO = @as(c_ulong, 32);
577577 );
578578
579579 cases.add("lu integer suffix after hex literal",
580580 \\#define SDL_INIT_VIDEO 0x00000020lu /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
581581 ,
582 \\pub const SDL_INIT_VIDEO = c_ulong(32);
582 \\pub const SDL_INIT_VIDEO = @as(c_ulong, 32);
583583 );
584584
585585 cases.add("ll integer suffix after hex literal",
586586 \\#define SDL_INIT_VIDEO 0x00000020ll /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
587587 ,
588 \\pub const SDL_INIT_VIDEO = c_longlong(32);
588 \\pub const SDL_INIT_VIDEO = @as(c_longlong, 32);
589589 );
590590
591591 cases.add("ull integer suffix after hex literal",
592592 \\#define SDL_INIT_VIDEO 0x00000020ull /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
593593 ,
594 \\pub const SDL_INIT_VIDEO = c_ulonglong(32);
594 \\pub const SDL_INIT_VIDEO = @as(c_ulonglong, 32);
595595 );
596596
597597 cases.add("llu integer suffix after hex literal",
598598 \\#define SDL_INIT_VIDEO 0x00000020llu /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
599599 ,
600 \\pub const SDL_INIT_VIDEO = c_ulonglong(32);
600 \\pub const SDL_INIT_VIDEO = @as(c_ulonglong, 32);
601601 );
602602
603603 cases.add("zig keywords in C code",
......@@ -677,7 +677,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
677677 \\ var a = _arg_a;
678678 \\ var i: c_int = 0;
679679 \\ while (a > @as(c_uint, 0)) {
680 \\ a >>= @import("std").math.Log2Int(c_uint)(1);
680 \\ a >>= @as(@import("std").math.Log2Int(c_uint), 1);
681681 \\ }
682682 \\ return i;
683683 \\}
......@@ -849,7 +849,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
849849 \\ var a = _arg_a;
850850 \\ var i: c_int = 0;
851851 \\ while (a > @as(c_uint, 0)) {
852 \\ a >>= u5(1);
852 \\ a >>= @as(u5, 1);
853853 \\ }
854854 \\ return i;
855855 \\}
......@@ -1027,7 +1027,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
10271027 \\}
10281028 ,
10291029 \\pub export fn foo() c_int {
1030 \\ return (1 << @import("std").math.Log2Int(c_int)(2)) >> @import("std").math.Log2Int(c_int)(1);
1030 \\ return (1 << @as(@import("std").math.Log2Int(c_int), 2)) >> @as(@import("std").math.Log2Int(c_int), 1);
10311031 \\}
10321032 );
10331033
......@@ -1076,14 +1076,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
10761076 \\ _ref.* = (_ref.* ^ 1);
10771077 \\ break :x _ref.*;
10781078 \\ });
1079 \\ a >>= @import("std").math.Log2Int(c_int)((x: {
1079 \\ a >>= @as(@import("std").math.Log2Int(c_int), (x: {
10801080 \\ const _ref = &a;
1081 \\ _ref.* = (_ref.* >> @import("std").math.Log2Int(c_int)(1));
1081 \\ _ref.* = (_ref.* >> @as(@import("std").math.Log2Int(c_int), 1));
10821082 \\ break :x _ref.*;
10831083 \\ }));
1084 \\ a <<= @import("std").math.Log2Int(c_int)((x: {
1084 \\ a <<= @as(@import("std").math.Log2Int(c_int), (x: {
10851085 \\ const _ref = &a;
1086 \\ _ref.* = (_ref.* << @import("std").math.Log2Int(c_int)(1));
1086 \\ _ref.* = (_ref.* << @as(@import("std").math.Log2Int(c_int), 1));
10871087 \\ break :x _ref.*;
10881088 \\ }));
10891089 \\}
......@@ -1134,14 +1134,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
11341134 \\ _ref.* = (_ref.* ^ @as(c_uint, 1));
11351135 \\ break :x _ref.*;
11361136 \\ });
1137 \\ a >>= @import("std").math.Log2Int(c_uint)((x: {
1137 \\ a >>= @as(@import("std").math.Log2Int(c_uint), (x: {
11381138 \\ const _ref = &a;
1139 \\ _ref.* = (_ref.* >> @import("std").math.Log2Int(c_uint)(1));
1139 \\ _ref.* = (_ref.* >> @as(@import("std").math.Log2Int(c_uint), 1));
11401140 \\ break :x _ref.*;
11411141 \\ }));
1142 \\ a <<= @import("std").math.Log2Int(c_uint)((x: {
1142 \\ a <<= @as(@import("std").math.Log2Int(c_uint), (x: {
11431143 \\ const _ref = &a;
1144 \\ _ref.* = (_ref.* << @import("std").math.Log2Int(c_uint)(1));
1144 \\ _ref.* = (_ref.* << @as(@import("std").math.Log2Int(c_uint), 1));
11451145 \\ break :x _ref.*;
11461146 \\ }));
11471147 \\}
......@@ -1539,7 +1539,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
15391539 cases.add("macro pointer cast",
15401540 \\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE)
15411541 ,
1542 \\pub const NRF_GPIO = if (@typeId(@typeOf(NRF_GPIO_BASE)) == @import("builtin").TypeId.Pointer) @ptrCast([*c]NRF_GPIO_Type, NRF_GPIO_BASE) else if (@typeId(@typeOf(NRF_GPIO_BASE)) == @import("builtin").TypeId.Int) @intToPtr([*c]NRF_GPIO_Type, NRF_GPIO_BASE) else ([*c]NRF_GPIO_Type)(NRF_GPIO_BASE);
1542 \\pub const NRF_GPIO = if (@typeId(@typeOf(NRF_GPIO_BASE)) == @import("builtin").TypeId.Pointer) @ptrCast([*c]NRF_GPIO_Type, NRF_GPIO_BASE) else if (@typeId(@typeOf(NRF_GPIO_BASE)) == @import("builtin").TypeId.Int) @intToPtr([*c]NRF_GPIO_Type, NRF_GPIO_BASE) else @as([*c]NRF_GPIO_Type, NRF_GPIO_BASE);
15431543 );
15441544
15451545 cases.add("if on non-bool",
......@@ -1564,7 +1564,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
15641564 \\ if (a != 0) return 0;
15651565 \\ if (b != 0) return 1;
15661566 \\ if (c != null) return 2;
1567 \\ if (d != @bitCast(enum_SomeEnum, @TagType(enum_SomeEnum)(0))) return 3;
1567 \\ if (d != @bitCast(enum_SomeEnum, @as(@TagType(enum_SomeEnum), 0))) return 3;
15681568 \\ return 4;
15691569 \\}
15701570 );
......@@ -1652,37 +1652,37 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
16521652 cases.addC(
16531653 "l integer suffix after 0 (zero) in macro definition",
16541654 "#define ZERO 0L",
1655 "pub const ZERO = c_long(0);",
1655 "pub const ZERO = @as(c_long, 0);",
16561656 );
16571657
16581658 cases.addC(
16591659 "ul integer suffix after 0 (zero) in macro definition",
16601660 "#define ZERO 0UL",
1661 "pub const ZERO = c_ulong(0);",
1661 "pub const ZERO = @as(c_ulong, 0);",
16621662 );
16631663
16641664 cases.addC(
16651665 "lu integer suffix after 0 (zero) in macro definition",
16661666 "#define ZERO 0LU",
1667 "pub const ZERO = c_ulong(0);",
1667 "pub const ZERO = @as(c_ulong, 0);",
16681668 );
16691669
16701670 cases.addC(
16711671 "ll integer suffix after 0 (zero) in macro definition",
16721672 "#define ZERO 0LL",
1673 "pub const ZERO = c_longlong(0);",
1673 "pub const ZERO = @as(c_longlong, 0);",
16741674 );
16751675
16761676 cases.addC(
16771677 "ull integer suffix after 0 (zero) in macro definition",
16781678 "#define ZERO 0ULL",
1679 "pub const ZERO = c_ulonglong(0);",
1679 "pub const ZERO = @as(c_ulonglong, 0);",
16801680 );
16811681
16821682 cases.addC(
16831683 "llu integer suffix after 0 (zero) in macro definition",
16841684 "#define ZERO 0LLU",
1685 "pub const ZERO = c_ulonglong(0);",
1685 "pub const ZERO = @as(c_ulonglong, 0);",
16861686 );
16871687
16881688 cases.addC(