aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
diff options
context:
space:
mode:
authorRobin Voetter <robin@voetter.nl>2021-10-20 00:30:20 +0200
committerRobin Voetter <robin@voetter.nl>2021-10-20 03:44:02 +0200
commitd6f048c4565ee7b3d86c070c07dd555376a52ad2 (patch)
tree4d2eef96e5bd32163c14f4c9fa1adba7363c8429 /src/Sema.zig
parent7b97f6792fdc4f2774f109ec016ad19bf341e768 (diff)
downloadzig-d6f048c4565ee7b3d86c070c07dd555376a52ad2.tar.gz
zig-d6f048c4565ee7b3d86c070c07dd555376a52ad2.zip
stage2: make (typeHas)OnePossibleValue return the right value
Diffstat (limited to 'src/Sema.zig')
-rw-r--r--src/Sema.zig13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index 7a5ac1baa1..d30b46ffba 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -13835,7 +13835,14 @@ fn typeHasOnePossibleValue(
return null;
}
},
- .enum_nonexhaustive => ty = ty.castTag(.enum_nonexhaustive).?.data.tag_ty,
+ .enum_nonexhaustive => {
+ const tag_ty = ty.castTag(.enum_nonexhaustive).?.data.tag_ty;
+ if (tag_ty.cast(Type.Payload.Bits).?.data == 0) {
+ return Value.initTag(.zero);
+ } else {
+ return null;
+ }
+ },
.@"union" => {
return null; // TODO
},
@@ -13859,8 +13866,8 @@ fn typeHasOnePossibleValue(
.vector, .array, .array_u8 => {
if (ty.arrayLen() == 0)
return Value.initTag(.empty_array);
- ty = ty.elemType();
- continue;
+ _ = (try sema.typeHasOnePossibleValue(block, src, ty.elemType())) orelse return null;
+ return Value.initTag(.the_only_possible_value);
},
.inferred_alloc_const => unreachable,