| ... | ... | @@ -422,3 +422,24 @@ test "import passed byref to function in return type" { |
| 422 | 422 | var list = S.get(); |
| 423 | 423 | try expect(list.items.len == 0); |
| 424 | 424 | } |
| 425 | |
| 426 | test "implicit cast function to function ptr" { |
| 427 | if (builtin.zig_backend == .stage1) return error.SkipZigTest; |
| 428 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO |
| 429 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 430 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO |
| 431 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO |
| 432 | |
| 433 | const S1 = struct { |
| 434 | export fn someFunctionThatReturnsAValue() c_int { |
| 435 | return 123; |
| 436 | } |
| 437 | }; |
| 438 | var fnPtr1: *const fn () callconv(.C) c_int = S1.someFunctionThatReturnsAValue; |
| 439 | try expect(fnPtr1() == 123); |
| 440 | const S2 = struct { |
| 441 | extern fn someFunctionThatReturnsAValue() c_int; |
| 442 | }; |
| 443 | var fnPtr2: *const fn () callconv(.C) c_int = S2.someFunctionThatReturnsAValue; |
| 444 | try expect(fnPtr2() == 123); |
| 445 | } |