| author | |
| committer | |
| log | b0cd24f90ef159cc60c9607e9cc37af8b5bd147a |
| tree | 34447045027e830bde4aca5fa43ecfd5342997f4 |
| parent | 728cc73819a6511e4402498a8146854b9278285f |
| parent | 64865679cf173c024a01d158686fc1cc9965a012 |
| signature |
Fix #140322 files changed, 33 insertions(+), 8 deletions(-)
src/Sema.zig+8-2| ... | @@ -29708,6 +29708,12 @@ fn resolveLazyValue(sema: *Sema, val: Value) CompileError!void { | ... | @@ -29708,6 +29708,12 @@ fn resolveLazyValue(sema: *Sema, val: Value) CompileError!void { |
| 29708 | const field_ptr = val.castTag(.comptime_field_ptr).?.data; | 29708 | const field_ptr = val.castTag(.comptime_field_ptr).?.data; |
| 29709 | return sema.resolveLazyValue(field_ptr.field_val); | 29709 | return sema.resolveLazyValue(field_ptr.field_val); |
| 29710 | }, | 29710 | }, |
| 29711 | .eu_payload, | ||
| 29712 | .opt_payload, | ||
| 29713 | => { | ||
| 29714 | const sub_val = val.cast(Value.Payload.SubValue).?.data; | ||
| 29715 | return sema.resolveLazyValue(sub_val); | ||
| 29716 | }, | ||
| 29711 | .@"union" => { | 29717 | .@"union" => { |
| 29712 | const union_val = val.castTag(.@"union").?.data; | 29718 | const union_val = val.castTag(.@"union").?.data; |
| 29713 | return sema.resolveLazyValue(union_val.val); | 29719 | return sema.resolveLazyValue(union_val.val); |
| ... | @@ -29747,7 +29753,7 @@ pub fn resolveTypeLayout(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -29747,7 +29753,7 @@ pub fn resolveTypeLayout(sema: *Sema, ty: Type) CompileError!void { |
| 29747 | .Fn => { | 29753 | .Fn => { |
| 29748 | const info = ty.fnInfo(); | 29754 | const info = ty.fnInfo(); |
| 29749 | if (info.is_generic) { | 29755 | if (info.is_generic) { |
| 29750 | // Resolving of generic function types is defeerred to when | 29756 | // Resolving of generic function types is deferred to when |
| 29751 | // the function is instantiated. | 29757 | // the function is instantiated. |
| 29752 | return; | 29758 | return; |
| 29753 | } | 29759 | } |
| ... | @@ -30201,7 +30207,7 @@ pub fn resolveTypeFully(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -30201,7 +30207,7 @@ pub fn resolveTypeFully(sema: *Sema, ty: Type) CompileError!void { |
| 30201 | .Fn => { | 30207 | .Fn => { |
| 30202 | const info = ty.fnInfo(); | 30208 | const info = ty.fnInfo(); |
| 30203 | if (info.is_generic) { | 30209 | if (info.is_generic) { |
| 30204 | // Resolving of generic function types is defeerred to when | 30210 | // Resolving of generic function types is deferred to when |
| 30205 | // the function is instantiated. | 30211 | // the function is instantiated. |
| 30206 | return; | 30212 | return; |
| 30207 | } | 30213 | } |
test/behavior/struct.zig+25-6| ... | @@ -1420,15 +1420,34 @@ test "struct field has a pointer to an aligned version of itself" { | ... | @@ -1420,15 +1420,34 @@ test "struct field has a pointer to an aligned version of itself" { |
| 1420 | try expect(&e == e.next); | 1420 | try expect(&e == e.next); |
| 1421 | } | 1421 | } |
| 1422 | 1422 | ||
| 1423 | test "struct only referenced from optional parameter/return" { | 1423 | test "struct has only one reference" { |
| 1424 | const S = struct { | 1424 | const S = struct { |
| 1425 | fn f(_: ?struct { x: u8 }) void {} | 1425 | fn optionalStructParam(_: ?struct { x: u8 }) void {} |
| 1426 | fn g() ?struct { x: u8 } { | 1426 | fn errorUnionStructParam(_: error{}!struct { x: u8 }) void {} |
| 1427 | fn optionalStructReturn() ?struct { x: u8 } { | ||
| 1427 | return null; | 1428 | return null; |
| 1428 | } | 1429 | } |
| 1430 | fn errorUnionStructReturn() error{Foo}!struct { x: u8 } { | ||
| 1431 | return error.Foo; | ||
| 1432 | } | ||
| 1433 | fn optionalComptimeIntParam(comptime x: ?comptime_int) comptime_int { | ||
| 1434 | return x.?; | ||
| 1435 | } | ||
| 1436 | fn errorUnionComptimeIntParam(comptime x: error{}!comptime_int) comptime_int { | ||
| 1437 | return x catch unreachable; | ||
| 1438 | } | ||
| 1429 | }; | 1439 | }; |
| 1430 | 1440 | ||
| 1431 | const fp: *const anyopaque = &S.f; | 1441 | const optional_struct_param: *const anyopaque = &S.optionalStructParam; |
| 1432 | const gp: *const anyopaque = &S.g; | 1442 | const error_union_struct_param: *const anyopaque = &S.errorUnionStructParam; |
| 1433 | try expect(fp != gp); | 1443 | try expect(optional_struct_param != error_union_struct_param); |
| 1444 | |||
| 1445 | const optional_struct_return: *const anyopaque = &S.optionalStructReturn; | ||
| 1446 | const error_union_struct_return: *const anyopaque = &S.errorUnionStructReturn; | ||
| 1447 | try expect(optional_struct_return != error_union_struct_return); | ||
| 1448 | |||
| 1449 | try expectEqual(@alignOf(struct {}), S.optionalComptimeIntParam(@alignOf(struct {}))); | ||
| 1450 | try expectEqual(@alignOf(struct { x: u8 }), S.errorUnionComptimeIntParam(@alignOf(struct { x: u8 }))); | ||
| 1451 | try expectEqual(@sizeOf(struct { x: u16 }), S.optionalComptimeIntParam(@sizeOf(struct { x: u16 }))); | ||
| 1452 | try expectEqual(@sizeOf(struct { x: u32 }), S.errorUnionComptimeIntParam(@sizeOf(struct { x: u32 }))); | ||
| 1434 | } | 1453 | } |