From 195ddab2be938c1201767909d39106cdf99fd07e Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 29 Mar 2021 21:59:08 -0700 Subject: Sema: implement switch expressions The logic for putting ranges into the else prong is moved from AstGen to Sema. However, logic to emit multi-items the same as single-items cannot be done until TZIR supports mapping multiple items to the same block of code. This will be simple to represent when we do the upcoming TZIR memory layout changes. Not yet implemented in this commit is the validation of duplicate values. The trick is going to be emitting error messages with accurate source locations, without adding extra source nodes to the ZIR switch instruction. This will be done by computing the respective AST node based on the switch node (which we do have available), only when a compile error occurs and we need to know the source location to attach the message to. --- src/type.zig | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/type.zig') diff --git a/src/type.zig b/src/type.zig index f6ffaefe0b..333854296e 100644 --- a/src/type.zig +++ b/src/type.zig @@ -3303,6 +3303,10 @@ pub const Type = extern union { } } + pub fn isExhaustiveEnum(ty: Type) bool { + return false; // TODO + } + /// This enum does not directly correspond to `std.builtin.TypeId` because /// it has extra enum tags in it, as a way of using less memory. For example, /// even though Zig recognizes `*align(10) i32` and `*i32` both as Pointer types -- cgit v1.2.3