Documentation
¶
Overview ¶
Command typeswitchlint checks that type switches over values.Value are exhaustive — but only the ones that opt in with an //exhaustive marker.
Most type switches over values.Value are intentionally partial (eqv? only compares numeric pairs; a transcendental op only handles the real tower). Flagging every such switch produces pure noise, so this tool checks a switch only when it is annotated:
//exhaustive
switch v := x.(type) {
case *values.Integer: ...
}
or with a trailing marker on the switch line:
switch v := x.(type) { //exhaustive
For a marked switch, every exported values.Value type that is not cased is reported, and the tool exits non-zero — so it can gate `make lint`. A default clause does NOT excuse a missing case: marking a switch exhaustive is a declaration that the cases enumerate the whole domain.
Scope: completeness is checked against the value types DEFINED IN package values (the data types), addressed as values.X from another package. It does not know about Value implementers defined elsewhere (closures, continuations, parameters), nor about unexported singletons (voidType, eofType, emptyListType) that cannot be named in a cross-package case. The known-type list is kept honest by TestKnownValueTypesMatchesSource, which derives the real set from the values source and fails on drift.
Usage:
go run ./tools/cmd/typeswitchlint [-v] [dir...]
If no directories are given, it scans the current directory recursively.