| author | |
| committer | |
| log | 4068fafcc621a05f4149f5e838c938f78c9500ad |
| tree | 802ef56a2e9b73b901de3375ab01bf38521a369b |
| parent | fe6fd0d5412bdef86cf200d664b37e05a3050966 |
Closes #140632 files changed, 25 insertions(+), 0 deletions(-)
src/Sema.zig+12| ... | @@ -29155,6 +29155,18 @@ pub fn resolveTypeLayout(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -29155,6 +29155,18 @@ pub fn resolveTypeLayout(sema: *Sema, ty: Type) CompileError!void { |
| 29155 | const payload_ty = ty.errorUnionPayload(); | 29155 | const payload_ty = ty.errorUnionPayload(); |
| 29156 | return sema.resolveTypeLayout(payload_ty); | 29156 | return sema.resolveTypeLayout(payload_ty); |
| 29157 | }, | 29157 | }, |
| 29158 | .Fn => { | ||
| 29159 | const info = ty.fnInfo(); | ||
| 29160 | if (info.is_generic) { | ||
| 29161 | // Resolving of generic function types is defeerred to when | ||
| 29162 | // the function is instantiated. | ||
| 29163 | return; | ||
| 29164 | } | ||
| 29165 | for (info.param_types) |param_ty| { | ||
| 29166 | try sema.resolveTypeLayout(param_ty); | ||
| 29167 | } | ||
| 29168 | try sema.resolveTypeLayout(info.return_type); | ||
| 29169 | }, | ||
| 29158 | else => {}, | 29170 | else => {}, |
| 29159 | } | 29171 | } |
| 29160 | } | 29172 | } |
test/behavior/struct.zig+13| ... | @@ -1430,3 +1430,16 @@ test "struct field has a pointer to an aligned version of itself" { | ... | @@ -1430,3 +1430,16 @@ test "struct field has a pointer to an aligned version of itself" { |
| 1430 | 1430 | ||
| 1431 | try expect(&e == e.next); | 1431 | try expect(&e == e.next); |
| 1432 | } | 1432 | } |
| 1433 | |||
| 1434 | test "struct only referenced from optional parameter/return" { | ||
| 1435 | const S = struct { | ||
| 1436 | fn f(_: ?struct { x: u8 }) void {} | ||
| 1437 | fn g() ?struct { x: u8 } { | ||
| 1438 | return null; | ||
| 1439 | } | ||
| 1440 | }; | ||
| 1441 | |||
| 1442 | const fp: *const anyopaque = &S.f; | ||
| 1443 | const gp: *const anyopaque = &S.g; | ||
| 1444 | try expect(fp != gp); | ||
| 1445 | } |