diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-04-07 22:19:17 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-04-07 22:19:17 -0700 |
| commit | 57aa289fdef543a507d8da039f5b7e7f2762c878 (patch) | |
| tree | 1e8f3c072f2c004554880cd23e53337bbc24a39b /src | |
| parent | e730172e47749db8a9d3be5949231bde95343b39 (diff) | |
| download | zig-57aa289fdef543a507d8da039f5b7e7f2762c878.tar.gz zig-57aa289fdef543a507d8da039f5b7e7f2762c878.zip | |
Sema: fix switch validation '_' prong on wrong type
Diffstat (limited to 'src')
| -rw-r--r-- | src/Sema.zig | 4 | ||||
| -rw-r--r-- | src/type.zig | 4 |
2 files changed, 4 insertions, 4 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index a0be08ed71..519d5df401 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -1972,7 +1972,7 @@ fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErr return mod.fail(&block.base, dest_ty_src, "expected enum, found {}", .{dest_ty}); } - if (!dest_ty.isExhaustiveEnum()) { + if (dest_ty.isNonexhaustiveEnum()) { if (operand.value()) |int_val| { return mod.constInst(arena, src, .{ .ty = dest_ty, @@ -2762,7 +2762,7 @@ fn analyzeSwitch( const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = src_node_offset }; // Validate usage of '_' prongs. - if (special_prong == .under and !operand.ty.isExhaustiveEnum()) { + if (special_prong == .under and !operand.ty.isNonexhaustiveEnum()) { const msg = msg: { const msg = try mod.errMsg( &block.base, diff --git a/src/type.zig b/src/type.zig index 1e52d2eb74..ab31991c36 100644 --- a/src/type.zig +++ b/src/type.zig @@ -2119,9 +2119,9 @@ pub const Type = extern union { } } - pub fn isExhaustiveEnum(ty: Type) bool { + pub fn isNonexhaustiveEnum(ty: Type) bool { return switch (ty.tag()) { - .enum_full, .enum_simple => true, + .enum_nonexhaustive => true, else => false, }; } |
