diff --git a/src/Sema.zig b/src/Sema.zig index 5be0ef364f..99762f4807 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -7747,14 +7747,9 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air const container_type = try sema.resolveType(block, lhs_src, extra.lhs); const decl_name = try sema.resolveConstString(block, rhs_src, extra.rhs); - // tuples are structs but they don't have a namespace - if (container_type.isTupleOrAnonStruct()) return Air.Inst.Ref.bool_false; - const namespace = container_type.getNamespace() orelse return sema.fail( - block, - lhs_src, - "expected struct, enum, union, or opaque, found '{}'", - .{container_type}, - ); + try checkNamespaceType(sema, block, lhs_src, container_type); + + const namespace = container_type.getNamespace() orelse return Air.Inst.Ref.bool_false; if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |decl| { if (decl.is_pub or decl.getFileScope() == block.getFileScope()) { return Air.Inst.Ref.bool_true; @@ -12882,6 +12877,13 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6 } } +fn checkNamespaceType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!void { + switch (ty.zigTypeTag()) { + .Struct, .Enum, .Union, .Opaque => return, + else => return sema.fail(block, src, "expected struct, enum, union, or opaque; found '{}'", .{ty}), + } +} + /// Returns `true` if the type was a comptime_int. fn checkIntType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!bool { switch (ty.zigTypeTag()) { diff --git a/test/behavior/switch.zig b/test/behavior/switch.zig index 659202361b..66c1b342e1 100644 --- a/test/behavior/switch.zig +++ b/test/behavior/switch.zig @@ -631,7 +631,11 @@ test "switch on error set with single else" { } test "switch capture copies its payload" { - if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO const S = struct { fn doTheTest() !void { diff --git a/test/behavior/union.zig b/test/behavior/union.zig index 5152edd46e..c879b44638 100644 --- a/test/behavior/union.zig +++ b/test/behavior/union.zig @@ -217,7 +217,7 @@ test "union with specified enum tag" { comptime try doTest(); } -test "packed union generates correctly aligned LLVM type" { +test "packed union generates correctly aligned type" { if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; @@ -1104,8 +1104,6 @@ test "@unionInit on union with tag but no fields" { } test "union enum type gets a separate scope" { - if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO - const S = struct { const U = union(enum) { a: u8,