aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-03-07 13:54:25 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-03-07 13:54:25 -0700
commit38c161afabe1dc7d0df7ad981d70b962ef87120a (patch)
treef1944a2512b4567b2e35a0c2ac7b87c47c8d2cb7 /src
parentc467f6693eb815906088b15f25d4e21092526bb4 (diff)
downloadzig-38c161afabe1dc7d0df7ad981d70b962ef87120a.tar.gz
zig-38c161afabe1dc7d0df7ad981d70b962ef87120a.zip
Sema: fix `@hasDecl` for simple enums
Diffstat (limited to 'src')
-rw-r--r--src/Sema.zig18
1 files changed, 10 insertions, 8 deletions
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()) {