| ... | @@ -3,9 +3,11 @@ const expectEqual = @import("std").testing.expectEqual; | ... | @@ -3,9 +3,11 @@ const expectEqual = @import("std").testing.expectEqual; |
| 3 | const FILE = extern struct { | 3 | const FILE = extern struct { |
| 4 | dummy_field: u8, | 4 | dummy_field: u8, |
| 5 | }; | 5 | }; |
| | 6 | |
| 6 | extern fn printf([*c]const u8, ...) c_int; | 7 | extern fn printf([*c]const u8, ...) c_int; |
| 7 | extern fn fputs([*c]const u8, noalias [*c]FILE) c_int; | 8 | extern fn fputs([*c]const u8, noalias [*c]FILE) c_int; |
| 8 | extern fn ftell([*c]FILE) c_long; | 9 | extern fn ftell([*c]FILE) c_long; |
| | 10 | extern fn fopen([*c]const u8, [*c]const u8) [*c]FILE; |
| 9 | | 11 | |
| 10 | const S = extern struct { | 12 | const S = extern struct { |
| 11 | state: c_short, | 13 | state: c_short, |
| ... | @@ -47,3 +49,23 @@ test "Peer resolution of extern function calls in @TypeOf" { | ... | @@ -47,3 +49,23 @@ test "Peer resolution of extern function calls in @TypeOf" { |
| 47 | Test.doTheTest(); | 49 | Test.doTheTest(); |
| 48 | comptime Test.doTheTest(); | 50 | comptime Test.doTheTest(); |
| 49 | } | 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 |