diff --git a/src/Sema.zig b/src/Sema.zig index 76e7e779e7..45dd182903 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -28775,6 +28775,7 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi try sema.checkBackingIntType(&block, backing_int_src, backing_int_ty, fields_bit_sum); struct_obj.backing_int_ty = try backing_int_ty.copy(decl_arena_allocator); + try wip_captures.finalize(); } else { var buf: Type.Payload.Bits = .{ .base = .{ .tag = .int_unsigned }, @@ -29386,6 +29387,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void } } } + try wip_captures.finalize(); struct_obj.have_field_inits = true; } diff --git a/test/behavior.zig b/test/behavior.zig index b3c1654607..2f5d752087 100644 --- a/test/behavior.zig +++ b/test/behavior.zig @@ -108,6 +108,7 @@ test { _ = @import("behavior/bugs/13112.zig"); _ = @import("behavior/bugs/13128.zig"); _ = @import("behavior/bugs/13164.zig"); + _ = @import("behavior/bugs/13171.zig"); _ = @import("behavior/byteswap.zig"); _ = @import("behavior/byval_arg_var.zig"); _ = @import("behavior/call.zig"); diff --git a/test/behavior/bugs/13171.zig b/test/behavior/bugs/13171.zig new file mode 100644 index 0000000000..11579a7356 --- /dev/null +++ b/test/behavior/bugs/13171.zig @@ -0,0 +1,16 @@ +const std = @import("std"); +const expect = std.testing.expect; + +fn BuildType(comptime T: type) type { + return struct { + val: union { + b: T, + }, + }; +} + +test { + const TestStruct = BuildType(u32); + const c = TestStruct{ .val = .{ .b = 10 } }; + try expect(c.val.b == 10); +}