Template compilation errors on bad switch
This commit is contained in:
parent
ad513d70e2
commit
882ff042e2
1 changed files with 5 additions and 0 deletions
|
@ -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)) {
|
||||
|
|
Loading…
Reference in a new issue