| author | |
| committer | |
| log | 50754ba336e99ac3db972a8b4e7bc583d77f2892 |
| tree | ed8b11fcf5bd5aa73587635dcaa269f5f448f578 |
| parent | 4c87281b5cf0e9268107f6456aeb16d097d1eb76 |
Closes #4022
Closes #36992 files changed, 23 insertions(+), 1 deletions(-)
src/analyze.cpp+4-1| ... | ... | @@ -5289,7 +5289,10 @@ static uint32_t hash_const_val(ZigValue *const_val) { |
| 5289 | 5289 | case ZigTypeIdAnyFrame: |
| 5290 | 5290 | // TODO better hashing algorithm |
| 5291 | 5291 | return 3747294894; |
| 5292 | case ZigTypeIdBoundFn: | |
| 5292 | case ZigTypeIdBoundFn: { | |
| 5293 | assert(const_val->data.x_bound_fn.fn != nullptr); | |
| 5294 | return 3677364617 ^ hash_ptr(const_val->data.x_bound_fn.fn); | |
| 5295 | } | |
| 5293 | 5296 | case ZigTypeIdInvalid: |
| 5294 | 5297 | case ZigTypeIdUnreachable: |
| 5295 | 5298 | zig_unreachable(); |
test/stage1/behavior/call.zig+19| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const expect = std.testing.expect; |
| 3 | const expectEqual = std.testing.expectEqual; | |
| 3 | 4 | |
| 4 | 5 | test "basic invocations" { |
| 5 | 6 | const foo = struct { |
| ... | ... | @@ -53,3 +54,21 @@ test "tuple parameters" { |
| 53 | 54 | expect(@call(.{ .modifier = .always_inline }, add, separate_args3) == 46); |
| 54 | 55 | } |
| 55 | 56 | } |
| 57 | ||
| 58 | test "comptime call with bound function as parameter" { | |
| 59 | const S = struct { | |
| 60 | fn ReturnType(func: var) type { | |
| 61 | return switch (@typeInfo(@TypeOf(func))) { | |
| 62 | .BoundFn => |info| info, | |
| 63 | else => unreachable, | |
| 64 | }.return_type orelse void; | |
| 65 | } | |
| 66 | ||
| 67 | fn call_me_maybe() ?i32 { | |
| 68 | return 123; | |
| 69 | } | |
| 70 | }; | |
| 71 | ||
| 72 | var inst: S = undefined; | |
| 73 | expectEqual(?i32, S.ReturnType(inst.call_me_maybe)); | |
| 74 | } |