| author | |
| committer | |
| log | f5b6019646fe76678c993596130f03116989eb12 |
| tree | 9b5a112189d53c3f591c0ae33e5dc208e318daf2 |
| parent | 0c30e006c90db4e6ca77d9054d391340282b96f6 |
Closes #140632 files changed, 25 insertions(+), 0 deletions(-)
src/Sema.zig+12| ... | ... | @@ -29743,6 +29743,18 @@ pub fn resolveTypeLayout(sema: *Sema, ty: Type) CompileError!void { |
| 29743 | 29743 | const payload_ty = ty.errorUnionPayload(); |
| 29744 | 29744 | return sema.resolveTypeLayout(payload_ty); |
| 29745 | 29745 | }, |
| 29746 | .Fn => { | |
| 29747 | const info = ty.fnInfo(); | |
| 29748 | if (info.is_generic) { | |
| 29749 | // Resolving of generic function types is defeerred to when | |
| 29750 | // the function is instantiated. | |
| 29751 | return; | |
| 29752 | } | |
| 29753 | for (info.param_types) |param_ty| { | |
| 29754 | try sema.resolveTypeLayout(param_ty); | |
| 29755 | } | |
| 29756 | try sema.resolveTypeLayout(info.return_type); | |
| 29757 | }, | |
| 29746 | 29758 | else => {}, |
| 29747 | 29759 | } |
| 29748 | 29760 | } |
test/behavior/struct.zig+13| ... | ... | @@ -1419,3 +1419,16 @@ test "struct field has a pointer to an aligned version of itself" { |
| 1419 | 1419 | |
| 1420 | 1420 | try expect(&e == e.next); |
| 1421 | 1421 | } |
| 1422 | ||
| 1423 | test "struct only referenced from optional parameter/return" { | |
| 1424 | const S = struct { | |
| 1425 | fn f(_: ?struct { x: u8 }) void {} | |
| 1426 | fn g() ?struct { x: u8 } { | |
| 1427 | return null; | |
| 1428 | } | |
| 1429 | }; | |
| 1430 | ||
| 1431 | const fp: *const anyopaque = &S.f; | |
| 1432 | const gp: *const anyopaque = &S.g; | |
| 1433 | try expect(fp != gp); | |
| 1434 | } |