diff options
| author | Robin Voetter <robin@voetter.nl> | 2021-10-20 00:30:20 +0200 |
|---|---|---|
| committer | Robin Voetter <robin@voetter.nl> | 2021-10-20 03:44:02 +0200 |
| commit | d6f048c4565ee7b3d86c070c07dd555376a52ad2 (patch) | |
| tree | 4d2eef96e5bd32163c14f4c9fa1adba7363c8429 /src/type.zig | |
| parent | 7b97f6792fdc4f2774f109ec016ad19bf341e768 (diff) | |
| download | zig-d6f048c4565ee7b3d86c070c07dd555376a52ad2.tar.gz zig-d6f048c4565ee7b3d86c070c07dd555376a52ad2.zip | |
stage2: make (typeHas)OnePossibleValue return the right value
Diffstat (limited to 'src/type.zig')
| -rw-r--r-- | src/type.zig | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/type.zig b/src/type.zig index 2bf268bc5f..459a9b387f 100644 --- a/src/type.zig +++ b/src/type.zig @@ -3096,6 +3096,14 @@ pub const Type = extern union { } return Value.initTag(.empty_struct_value); }, + .enum_numbered => { + const enum_numbered = ty.castTag(.enum_numbered).?.data; + if (enum_numbered.fields.count() == 1) { + return enum_numbered.values.keys()[0]; + } else { + return null; + } + }, .enum_full => { const enum_full = ty.castTag(.enum_full).?.data; if (enum_full.fields.count() == 1) { @@ -3112,8 +3120,14 @@ pub const Type = extern union { return null; } }, - .enum_nonexhaustive => ty = ty.castTag(.enum_nonexhaustive).?.data.tag_ty, - .enum_numbered => ty = ty.castTag(.enum_numbered).?.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 }, @@ -3137,8 +3151,8 @@ pub const Type = extern union { .vector, .array, .array_u8 => { if (ty.arrayLen() == 0) return Value.initTag(.empty_array); - ty = ty.elemType(); - continue; + _ = ty.elemType().onePossibleValue() orelse return null; + return Value.initTag(.the_only_possible_value); }, .inferred_alloc_const => unreachable, |
