| author | |
| committer | |
| log | cc6964c5dc7a4d4c3081db06697b8ba0d7900b85 |
| tree | 0399e6a434b93734a329452923927f014d9dc99f |
| parent | a7f3c2eab427397846f619dba7abb72378ac2ce9 |
2 files changed, 31 insertions(+), 0 deletions(-)
src/InternPool.zig+11| ... | ... | @@ -7069,6 +7069,17 @@ pub fn funcIesResolved(ip: *const InternPool, func_index: Index) *Index { |
| 7069 | 7069 | const extra_index = switch (tags[@intFromEnum(func_index)]) { |
| 7070 | 7070 | .func_decl => func_start + @typeInfo(Tag.FuncDecl).Struct.fields.len, |
| 7071 | 7071 | .func_instance => func_start + @typeInfo(Tag.FuncInstance).Struct.fields.len, |
| 7072 | .func_coerced => i: { | |
| 7073 | const uncoerced_func_index: Index = @enumFromInt(ip.extra.items[ | |
| 7074 | func_start + std.meta.fieldIndex(Tag.FuncCoerced, "func").? | |
| 7075 | ]); | |
| 7076 | const uncoerced_func_start = datas[@intFromEnum(uncoerced_func_index)]; | |
| 7077 | break :i switch (tags[@intFromEnum(uncoerced_func_index)]) { | |
| 7078 | .func_decl => uncoerced_func_start + @typeInfo(Tag.FuncDecl).Struct.fields.len, | |
| 7079 | .func_instance => uncoerced_func_start + @typeInfo(Tag.FuncInstance).Struct.fields.len, | |
| 7080 | else => unreachable, | |
| 7081 | }; | |
| 7082 | }, | |
| 7072 | 7083 | else => unreachable, |
| 7073 | 7084 | }; |
| 7074 | 7085 | return @ptrCast(&ip.extra.items[extra_index]); |
test/behavior/generics.zig+20| ... | ... | @@ -456,3 +456,23 @@ test "return type of generic function is function pointer" { |
| 456 | 456 | |
| 457 | 457 | try expect(null == S.b(void)); |
| 458 | 458 | } |
| 459 | ||
| 460 | test "coerced function body has inequal value with its uncoerced body" { | |
| 461 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | |
| 462 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 463 | ||
| 464 | const S = struct { | |
| 465 | const A = B(i32, c); | |
| 466 | fn c() !i32 { | |
| 467 | return 1234; | |
| 468 | } | |
| 469 | fn B(comptime T: type, comptime d: ?fn () anyerror!T) type { | |
| 470 | return struct { | |
| 471 | fn do() T { | |
| 472 | return d.?() catch @panic("fail"); | |
| 473 | } | |
| 474 | }; | |
| 475 | } | |
| 476 | }; | |
| 477 | try expect(S.A.do() == 1234); | |
| 478 | } |