Merge pull request #680 from github/rneatherway/example-query

Add an example query for inexhaustive switches
This commit is contained in:
Robin Neatherway
2022-02-02 17:33:22 +00:00
committed by GitHub

View File

@@ -0,0 +1,17 @@
/**
* @name Incomplete switch over enum
* @description A switch statement of enum type should explicitly reference each
* of the members of that enum.
* @kind problem
* @id go/examples/incomplete-switch
*/
import go
from ExpressionSwitchStmt ss, DeclaredConstant c, NamedType t
where
t.getUnderlyingType() instanceof IntegerType and
t = ss.getExpr().getType() and
c.getType() = t and
forall(CaseClause case | case = ss.getACase() | not case = c.getAReference().getParent())
select ss, "This switch statement is not exhaustive: missing $@", c, c.getName()