| ... | @@ -384,6 +384,58 @@ fn testFunction() !void { | ... | @@ -384,6 +384,58 @@ fn testFunction() !void { |
| 384 | extern fn foo(a: usize, b: bool, ...) callconv(.C) usize; | 384 | extern fn foo(a: usize, b: bool, ...) callconv(.C) usize; |
| 385 | extern fn fooAligned(a: usize, b: bool, ...) align(4) callconv(.C) usize; | 385 | extern fn fooAligned(a: usize, b: bool, ...) align(4) callconv(.C) usize; |
| 386 | | 386 | |
| | 387 | test "type info: generic function types" { |
| | 388 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; |
| | 389 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; |
| | 390 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; |
| | 391 | |
| | 392 | if (builtin.zig_backend != .stage1) { |
| | 393 | // stage1 marks all args/return types as null if the function |
| | 394 | // is generic at all. stage2 is more specific. |
| | 395 | const G1 = @typeInfo(@TypeOf(generic1)); |
| | 396 | try expect(G1.Fn.args.len == 1); |
| | 397 | try expect(G1.Fn.args[0].is_generic == true); |
| | 398 | try expect(G1.Fn.args[0].arg_type == null); |
| | 399 | try expect(G1.Fn.return_type == void); |
| | 400 | |
| | 401 | const G2 = @typeInfo(@TypeOf(generic2)); |
| | 402 | try expect(G2.Fn.args.len == 3); |
| | 403 | try expect(G2.Fn.args[0].is_generic == false); |
| | 404 | try expect(G2.Fn.args[0].arg_type == type); |
| | 405 | try expect(G2.Fn.args[1].is_generic == true); |
| | 406 | try expect(G2.Fn.args[1].arg_type == null); |
| | 407 | try expect(G2.Fn.args[2].is_generic == false); |
| | 408 | try expect(G2.Fn.args[2].arg_type == u8); |
| | 409 | try expect(G2.Fn.return_type == void); |
| | 410 | } |
| | 411 | |
| | 412 | const G3 = @typeInfo(@TypeOf(generic3)); |
| | 413 | try expect(G3.Fn.args.len == 1); |
| | 414 | try expect(G3.Fn.args[0].is_generic == true); |
| | 415 | try expect(G3.Fn.args[0].arg_type == null); |
| | 416 | try expect(G3.Fn.return_type == null); |
| | 417 | |
| | 418 | const G4 = @typeInfo(@TypeOf(generic4)); |
| | 419 | try expect(G4.Fn.args.len == 1); |
| | 420 | try expect(G4.Fn.args[0].is_generic == true); |
| | 421 | try expect(G4.Fn.args[0].arg_type == null); |
| | 422 | try expect(G4.Fn.return_type == null); |
| | 423 | } |
| | 424 | |
| | 425 | fn generic1(param: anytype) void { |
| | 426 | _ = param; |
| | 427 | } |
| | 428 | fn generic2(comptime T: type, param: T, param2: u8) void { |
| | 429 | _ = param; |
| | 430 | _ = param2; |
| | 431 | } |
| | 432 | fn generic3(param: anytype) @TypeOf(param) { |
| | 433 | _ = param; |
| | 434 | } |
| | 435 | fn generic4(comptime param: anytype) @TypeOf(param) { |
| | 436 | _ = param; |
| | 437 | } |
| | 438 | |
| 387 | test "typeInfo with comptime parameter in struct fn def" { | 439 | test "typeInfo with comptime parameter in struct fn def" { |
| 388 | const S = struct { | 440 | const S = struct { |
| 389 | pub fn func(comptime x: f32) void { | 441 | pub fn func(comptime x: f32) void { |