diff --git a/src/Module.zig b/src/Module.zig index 3bc763103b..1fd83108ff 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -3909,19 +3909,18 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool { const decl_arena_state = try decl_arena_allocator.create(std.heap.ArenaAllocator.State); if (decl.is_usingnamespace) { - const ty_ty = Type.initTag(.type); - if (!decl_tv.ty.eql(ty_ty, target)) { + if (!decl_tv.ty.eql(Type.type, target)) { return sema.fail(&block_scope, src, "expected type, found {}", .{ decl_tv.ty.fmt(target), }); } var buffer: Value.ToTypeBuffer = undefined; - const ty = decl_tv.val.toType(&buffer); + const ty = try decl_tv.val.toType(&buffer).copy(decl_arena_allocator); if (ty.getNamespace() == null) { return sema.fail(&block_scope, src, "type {} has no namespace", .{ty.fmt(target)}); } - decl.ty = ty_ty; + decl.ty = Type.type; decl.val = try Value.Tag.ty.create(decl_arena_allocator, ty); decl.@"align" = 0; decl.@"linksection" = null; diff --git a/test/behavior/usingnamespace.zig b/test/behavior/usingnamespace.zig index ed84c36071..426f0aa6b9 100644 --- a/test/behavior/usingnamespace.zig +++ b/test/behavior/usingnamespace.zig @@ -56,3 +56,23 @@ test "two files usingnamespace import each other" { try expect(@This().ok()); } + +test { + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO + + const AA = struct { + x: i32, + fn b(x: i32) @This() { + return .{ .x = x }; + } + fn c() type { + return if (true) struct { + const expected: i32 = 42; + } else struct {}; + } + usingnamespace c(); + }; + const a = AA.b(42); + try expect(a.x == AA.c().expected); +}