Skip to content

Conversation

@gregory-nisbet
Copy link
Contributor

gochecksumtype is a linter in golangci-lint that checks for switch statement exhaustiveness for types that look like sum types in other languages. More precisely, interface types with a //sumtype:decl annotation and an unexported nullary marker method are statically guaranteed to be closed (since new types that implement the interface can't be created). This means that we can check for exhaustiveness on type switches for values implementing the sumdecl-compatible interface, which is what the linter does.

The initial attempt to add this to every type with a marker interface #111 has grown in complexity since a few of the tests use unknownNode and unknownType types for checking the error paths. gochecksumtype has no way of indicating test-only variants of a sum type. So, to keep the diff size small and the code coverage at 100% (except for the generated parser) at each step, I'm going to break PR #111 into pieces and land them separately.

gochecksumtype is a linter in golangci-lint that checks for switch
statement exhaustiveness for types that look like sum types in other
languages. More precisely, interface types with a //sumtype:decl
annotation and an unexported nullary marker method are statically
guaranteed to be closed (since new types that implement the interface
can't be created). This means that we can check for exhaustiveness
on type switches for values implementing the sumdecl-compatible
interface, which is what the linter does.

The initial attempt to add this to every type with a marker interface
cedar-policy#111 has grown in
complexity since a few of the tests use unknownNode and unknownType
types for checking the error paths. gochecksumtype has no way of
indicating test-only variants of a sum type. So, to keep the diff size
small and the code coverage at 100% (except for the generated parser) at
each step, I'm going to break PR cedar-policy#111 into pieces and land them
separately.

Signed-off-by: Greg NISBET <[email protected]>
Copy link
Collaborator

@philhassey philhassey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@philhassey philhassey merged commit 3fcc669 into cedar-policy:main Nov 24, 2025
2 checks passed
@philhassey
Copy link
Collaborator

Thanks! I merged this, did you want to close #111 then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants