Commit 4068fafcc6
2022-12-25 01:44:52
1 parent
fe6fd0dChanged files (2)
src
test
behavior
src/Sema.zig
@@ -29155,6 +29155,18 @@ pub fn resolveTypeLayout(sema: *Sema, ty: Type) CompileError!void {
const payload_ty = ty.errorUnionPayload();
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 => {},
}
}
test/behavior/struct.zig
@@ -1430,3 +1430,16 @@ test "struct field has a pointer to an aligned version of itself" {
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);
+}