mirror of
https://github.com/github/codeql.git
synced 2026-01-29 22:32:58 +01:00
Merge pull request #680 from github/rneatherway/example-query
Add an example query for inexhaustive switches
This commit is contained in:
17
ql/examples/snippets/incompleteswitchoverenum.ql
Normal file
17
ql/examples/snippets/incompleteswitchoverenum.ql
Normal 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()
|
||||
Reference in New Issue
Block a user