authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-07 13:54:25-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-07 13:54:25-07:00
log38c161afabe1dc7d0df7ad981d70b962ef87120a
treef1944a2512b4567b2e35a0c2ac7b87c47c8d2cb7
parentc467f6693eb815906088b15f25d4e21092526bb4

Sema: fix `@hasDecl` for simple enums


3 files changed, 16 insertions(+), 12 deletions(-)

src/Sema.zig+10-8
......@@ -7747,14 +7747,9 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
77477747 const container_type = try sema.resolveType(block, lhs_src, extra.lhs);
77487748 const decl_name = try sema.resolveConstString(block, rhs_src, extra.rhs);
77497749
7750 // tuples are structs but they don't have a namespace
7751 if (container_type.isTupleOrAnonStruct()) return Air.Inst.Ref.bool_false;
7752 const namespace = container_type.getNamespace() orelse return sema.fail(
7753 block,
7754 lhs_src,
7755 "expected struct, enum, union, or opaque, found '{}'",
7756 .{container_type},
7757 );
7750 try checkNamespaceType(sema, block, lhs_src, container_type);
7751
7752 const namespace = container_type.getNamespace() orelse return Air.Inst.Ref.bool_false;
77587753 if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |decl| {
77597754 if (decl.is_pub or decl.getFileScope() == block.getFileScope()) {
77607755 return Air.Inst.Ref.bool_true;
......@@ -12882,6 +12877,13 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6
1288212877 }
1288312878}
1288412879
12880fn checkNamespaceType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!void {
12881 switch (ty.zigTypeTag()) {
12882 .Struct, .Enum, .Union, .Opaque => return,
12883 else => return sema.fail(block, src, "expected struct, enum, union, or opaque; found '{}'", .{ty}),
12884 }
12885}
12886
1288512887/// Returns `true` if the type was a comptime_int.
1288612888fn checkIntType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!bool {
1288712889 switch (ty.zigTypeTag()) {
test/behavior/switch.zig+5-1
......@@ -631,7 +631,11 @@ test "switch on error set with single else" {
631631}
632632
633633test "switch capture copies its payload" {
634 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
634 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
635 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
636 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
637 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
638 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
635639
636640 const S = struct {
637641 fn doTheTest() !void {
test/behavior/union.zig+1-3
......@@ -217,7 +217,7 @@ test "union with specified enum tag" {
217217 comptime try doTest();
218218}
219219
220test "packed union generates correctly aligned LLVM type" {
220test "packed union generates correctly aligned type" {
221221 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
222222 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
223223 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
......@@ -1104,8 +1104,6 @@ test "@unionInit on union with tag but no fields" {
11041104}
11051105
11061106test "union enum type gets a separate scope" {
1107 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
1108
11091107 const S = struct {
11101108 const U = union(enum) {
11111109 a: u8,