From 400a91e1c644228a66aa1702b9d800f018712105 Mon Sep 17 00:00:00 2001 From: Alexandros Naskos Date: Mon, 18 May 2020 19:15:44 +0300 Subject: Add TypeOf resolution of dereferences and struct fields of undefined values --- test/stage1/behavior/bugs/4328.zig | 49 --------------------------------- test/stage1/behavior/bugs/4328_5305.zig | 49 +++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 49 deletions(-) delete mode 100644 test/stage1/behavior/bugs/4328.zig create mode 100644 test/stage1/behavior/bugs/4328_5305.zig (limited to 'test') diff --git a/test/stage1/behavior/bugs/4328.zig b/test/stage1/behavior/bugs/4328.zig deleted file mode 100644 index bbad666c41..0000000000 --- a/test/stage1/behavior/bugs/4328.zig +++ /dev/null @@ -1,49 +0,0 @@ -const expectEqual = @import("std").testing.expectEqual; - -const FILE = extern struct { - dummy_field: u8, -}; -extern fn printf([*c]const u8, ...) c_int; -extern fn fputs([*c]const u8, noalias [*c]FILE) c_int; -extern fn ftell([*c]FILE) c_long; - -const S = extern struct { - state: c_short, - - extern fn s_do_thing([*c]S, b: c_int) c_short; -}; - -test "Extern function calls in @TypeOf" { - const Test = struct { - fn test_fn_1(a: var, b: var) @TypeOf(printf("%d %s\n", a, b)) { - return 0; - } - - fn test_fn_2(a: var) @TypeOf((S{ .state = 0 }).s_do_thing(a)) { - return 1; - } - - fn doTheTest() void { - expectEqual(c_int, @TypeOf(test_fn_1(0, 42))); - expectEqual(c_short, @TypeOf(test_fn_2(0))); - } - }; - - Test.doTheTest(); - comptime Test.doTheTest(); -} - -test "Peer resolution of extern function calls in @TypeOf" { - const Test = struct { - fn test_fn() @TypeOf(ftell(null), fputs(null, null)) { - return 0; - } - - fn doTheTest() void { - expectEqual(c_long, @TypeOf(test_fn())); - } - }; - - Test.doTheTest(); - comptime Test.doTheTest(); -} diff --git a/test/stage1/behavior/bugs/4328_5305.zig b/test/stage1/behavior/bugs/4328_5305.zig new file mode 100644 index 0000000000..bbad666c41 --- /dev/null +++ b/test/stage1/behavior/bugs/4328_5305.zig @@ -0,0 +1,49 @@ +const expectEqual = @import("std").testing.expectEqual; + +const FILE = extern struct { + dummy_field: u8, +}; +extern fn printf([*c]const u8, ...) c_int; +extern fn fputs([*c]const u8, noalias [*c]FILE) c_int; +extern fn ftell([*c]FILE) c_long; + +const S = extern struct { + state: c_short, + + extern fn s_do_thing([*c]S, b: c_int) c_short; +}; + +test "Extern function calls in @TypeOf" { + const Test = struct { + fn test_fn_1(a: var, b: var) @TypeOf(printf("%d %s\n", a, b)) { + return 0; + } + + fn test_fn_2(a: var) @TypeOf((S{ .state = 0 }).s_do_thing(a)) { + return 1; + } + + fn doTheTest() void { + expectEqual(c_int, @TypeOf(test_fn_1(0, 42))); + expectEqual(c_short, @TypeOf(test_fn_2(0))); + } + }; + + Test.doTheTest(); + comptime Test.doTheTest(); +} + +test "Peer resolution of extern function calls in @TypeOf" { + const Test = struct { + fn test_fn() @TypeOf(ftell(null), fputs(null, null)) { + return 0; + } + + fn doTheTest() void { + expectEqual(c_long, @TypeOf(test_fn())); + } + }; + + Test.doTheTest(); + comptime Test.doTheTest(); +} -- cgit v1.2.3