mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
parent
fe6fd0d541
commit
4068fafcc6
2 changed files with 25 additions and 0 deletions
12
src/Sema.zig
12
src/Sema.zig
|
|
@ -29155,6 +29155,18 @@ pub fn resolveTypeLayout(sema: *Sema, ty: Type) CompileError!void {
|
||||||
const payload_ty = ty.errorUnionPayload();
|
const payload_ty = ty.errorUnionPayload();
|
||||||
return sema.resolveTypeLayout(payload_ty);
|
return sema.resolveTypeLayout(payload_ty);
|
||||||
},
|
},
|
||||||
|
.Fn => {
|
||||||
|
const info = ty.fnInfo();
|
||||||
|
if (info.is_generic) {
|
||||||
|
// Resolving of generic function types is defeerred to when
|
||||||
|
// the function is instantiated.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (info.param_types) |param_ty| {
|
||||||
|
try sema.resolveTypeLayout(param_ty);
|
||||||
|
}
|
||||||
|
try sema.resolveTypeLayout(info.return_type);
|
||||||
|
},
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1430,3 +1430,16 @@ test "struct field has a pointer to an aligned version of itself" {
|
||||||
|
|
||||||
try expect(&e == e.next);
|
try expect(&e == e.next);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "struct only referenced from optional parameter/return" {
|
||||||
|
const S = struct {
|
||||||
|
fn f(_: ?struct { x: u8 }) void {}
|
||||||
|
fn g() ?struct { x: u8 } {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const fp: *const anyopaque = &S.f;
|
||||||
|
const gp: *const anyopaque = &S.g;
|
||||||
|
try expect(fp != gp);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue