diff --git a/src/template/lib.zig b/src/template/lib.zig index 7f02a20..33b55d3 100644 --- a/src/template/lib.zig +++ b/src/template/lib.zig @@ -130,6 +130,11 @@ fn executeStatement( .@"switch" => |switch_stmt| { const expr = evaluateExpression(switch_stmt.expression, args, captures, context); + const exhaustive = switch_stmt.cases.len == std.meta.fields(@TypeOf(expr)).len; + + if (exhaustive and switch_stmt.else_branch != null) @compileError("Unused else branch in switch"); + if (!exhaustive and switch_stmt.else_branch == null) @compileError("Not all switch cases covered"); + var found = false; inline for (switch_stmt.cases) |case| { if (std.meta.isTag(expr, case.header.tag)) {