| author | |
| committer | |
| log | d88db4d34bad1f4e140217f425300b417b448b64 |
| tree | 3c7fef344bab3c701488e3aa8627597b9dff3e2d |
| parent | 75a4c02880393c08e245c80ed6114e97e2c47a25 |
3 files changed, 72 insertions(+), 72 deletions(-)
test/stage1/behavior.zig+1-1| ... | ... | @@ -40,7 +40,7 @@ comptime { |
| 40 | 40 | _ = @import("behavior/bugs/3384.zig"); |
| 41 | 41 | _ = @import("behavior/bugs/3586.zig"); |
| 42 | 42 | _ = @import("behavior/bugs/3742.zig"); |
| 43 | _ = @import("behavior/bugs/4328_5305.zig"); | |
| 43 | _ = @import("behavior/bugs/4328.zig"); | |
| 44 | 44 | _ = @import("behavior/bugs/4560.zig"); |
| 45 | 45 | _ = @import("behavior/bugs/4769_a.zig"); |
| 46 | 46 | _ = @import("behavior/bugs/4769_b.zig"); |
test/stage1/behavior/bugs/4328.zig created+71| ... | ... | @@ -0,0 +1,71 @@ |
| 1 | const expectEqual = @import("std").testing.expectEqual; | |
| 2 | ||
| 3 | const FILE = extern struct { | |
| 4 | dummy_field: u8, | |
| 5 | }; | |
| 6 | ||
| 7 | extern fn printf([*c]const u8, ...) c_int; | |
| 8 | extern fn fputs([*c]const u8, noalias [*c]FILE) c_int; | |
| 9 | extern fn ftell([*c]FILE) c_long; | |
| 10 | extern fn fopen([*c]const u8, [*c]const u8) [*c]FILE; | |
| 11 | ||
| 12 | const S = extern struct { | |
| 13 | state: c_short, | |
| 14 | ||
| 15 | extern fn s_do_thing([*c]S, b: c_int) c_short; | |
| 16 | }; | |
| 17 | ||
| 18 | test "Extern function calls in @TypeOf" { | |
| 19 | const Test = struct { | |
| 20 | fn test_fn_1(a: var, b: var) @TypeOf(printf("%d %s\n", a, b)) { | |
| 21 | return 0; | |
| 22 | } | |
| 23 | ||
| 24 | fn test_fn_2(a: var) @TypeOf((S{ .state = 0 }).s_do_thing(a)) { | |
| 25 | return 1; | |
| 26 | } | |
| 27 | ||
| 28 | fn doTheTest() void { | |
| 29 | expectEqual(c_int, @TypeOf(test_fn_1(0, 42))); | |
| 30 | expectEqual(c_short, @TypeOf(test_fn_2(0))); | |
| 31 | } | |
| 32 | }; | |
| 33 | ||
| 34 | Test.doTheTest(); | |
| 35 | comptime Test.doTheTest(); | |
| 36 | } | |
| 37 | ||
| 38 | test "Peer resolution of extern function calls in @TypeOf" { | |
| 39 | const Test = struct { | |
| 40 | fn test_fn() @TypeOf(ftell(null), fputs(null, null)) { | |
| 41 | return 0; | |
| 42 | } | |
| 43 | ||
| 44 | fn doTheTest() void { | |
| 45 | expectEqual(c_long, @TypeOf(test_fn())); | |
| 46 | } | |
| 47 | }; | |
| 48 | ||
| 49 | Test.doTheTest(); | |
| 50 | comptime Test.doTheTest(); | |
| 51 | } | |
| 52 | ||
| 53 | test "Extern function calls, dereferences and field access in @TypeOf" { | |
| 54 | const Test = struct { | |
| 55 | fn test_fn_1(a: c_long) @TypeOf(fopen("test", "r").*) { | |
| 56 | return .{ .dummy_field = 0 }; | |
| 57 | } | |
| 58 | ||
| 59 | fn test_fn_2(a: var) @TypeOf(fopen("test", "r").*.dummy_field) { | |
| 60 | return 255; | |
| 61 | } | |
| 62 | ||
| 63 | fn doTheTest() void { | |
| 64 | expectEqual(FILE, @TypeOf(test_fn_1(0))); | |
| 65 | expectEqual(u8, @TypeOf(test_fn_2(0))); | |
| 66 | } | |
| 67 | }; | |
| 68 | ||
| 69 | Test.doTheTest(); | |
| 70 | comptime Test.doTheTest(); | |
| 71 | } | |
| \ No newline at end of file |
test/stage1/behavior/bugs/4328_5305.zig deleted-71| ... | ... | @@ -1,71 +0,0 @@ |
| 1 | const expectEqual = @import("std").testing.expectEqual; | |
| 2 | ||
| 3 | const FILE = extern struct { | |
| 4 | dummy_field: u8, | |
| 5 | }; | |
| 6 | ||
| 7 | extern fn printf([*c]const u8, ...) c_int; | |
| 8 | extern fn fputs([*c]const u8, noalias [*c]FILE) c_int; | |
| 9 | extern fn ftell([*c]FILE) c_long; | |
| 10 | extern fn fopen([*c]const u8, [*c]const u8) [*c]FILE; | |
| 11 | ||
| 12 | const S = extern struct { | |
| 13 | state: c_short, | |
| 14 | ||
| 15 | extern fn s_do_thing([*c]S, b: c_int) c_short; | |
| 16 | }; | |
| 17 | ||
| 18 | test "Extern function calls in @TypeOf" { | |
| 19 | const Test = struct { | |
| 20 | fn test_fn_1(a: var, b: var) @TypeOf(printf("%d %s\n", a, b)) { | |
| 21 | return 0; | |
| 22 | } | |
| 23 | ||
| 24 | fn test_fn_2(a: var) @TypeOf((S{ .state = 0 }).s_do_thing(a)) { | |
| 25 | return 1; | |
| 26 | } | |
| 27 | ||
| 28 | fn doTheTest() void { | |
| 29 | expectEqual(c_int, @TypeOf(test_fn_1(0, 42))); | |
| 30 | expectEqual(c_short, @TypeOf(test_fn_2(0))); | |
| 31 | } | |
| 32 | }; | |
| 33 | ||
| 34 | Test.doTheTest(); | |
| 35 | comptime Test.doTheTest(); | |
| 36 | } | |
| 37 | ||
| 38 | test "Peer resolution of extern function calls in @TypeOf" { | |
| 39 | const Test = struct { | |
| 40 | fn test_fn() @TypeOf(ftell(null), fputs(null, null)) { | |
| 41 | return 0; | |
| 42 | } | |
| 43 | ||
| 44 | fn doTheTest() void { | |
| 45 | expectEqual(c_long, @TypeOf(test_fn())); | |
| 46 | } | |
| 47 | }; | |
| 48 | ||
| 49 | Test.doTheTest(); | |
| 50 | comptime Test.doTheTest(); | |
| 51 | } | |
| 52 | ||
| 53 | test "Extern function calls, dereferences and field access in @TypeOf" { | |
| 54 | const Test = struct { | |
| 55 | fn test_fn_1(a: c_long) @TypeOf(fopen("test", "r").*) { | |
| 56 | return .{ .dummy_field = 0 }; | |
| 57 | } | |
| 58 | ||
| 59 | fn test_fn_2(a: var) @TypeOf(fopen("test", "r").*.dummy_field) { | |
| 60 | return 255; | |
| 61 | } | |
| 62 | ||
| 63 | fn doTheTest() void { | |
| 64 | expectEqual(FILE, @TypeOf(test_fn_1(0))); | |
| 65 | expectEqual(u8, @TypeOf(test_fn_2(0))); | |
| 66 | } | |
| 67 | }; | |
| 68 | ||
| 69 | Test.doTheTest(); | |
| 70 | comptime Test.doTheTest(); | |
| 71 | } | |
| \ No newline at end of file |