Skip to content

Conversation

@gregory-nisbet
Copy link
Contributor

@gregory-nisbet gregory-nisbet commented Oct 6, 2025

Some of the types within cedar-go match the sum type idiom (an interface with an unexported method) described in the linter below.

Let's add an explicit check for exhaustiveness for this specific linter.

https://github.com/alecthomas/go-check-sumtype

Issue #, if available:

n/a

Description of changes:

Add a sum type annotation, add two branches to convertNamespace, both of which are just comments. Let me know if the behavior in those branches should be a little smarter.

@gregory-nisbet gregory-nisbet force-pushed the 2025-10-05-golangci-lint-additions branch from bcc14bb to e0d4781 Compare October 6, 2025 00:59
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.

I think there's a typo to fix.

Sorry for the delay on reviewing this, there was some trouble with notifications.

@gregory-nisbet gregory-nisbet force-pushed the 2025-10-05-golangci-lint-additions branch from 4de67ff to e8315d1 Compare October 25, 2025 20:22
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.

Just a minor nit.

@gregory-nisbet gregory-nisbet force-pushed the 2025-10-05-golangci-lint-additions branch from e8315d1 to 11d1e87 Compare November 15, 2025 19:48
Some of the types within cedar-go match the sum type idiom (an interface with an unexported method) described in the linter below.

Let's add an explicit check for exhaustiveness for this specific linter.

https://github.com/alecthomas/go-check-sumtype

*Issue #, if available:*

IDK what issue tracker you use.

*Description of changes:*

Add a sum type annotation, add two branches to convertNamespace, both of which are just comments.
Let me know if the behavior in those branches should be a little smarter.

Signed-off-by: Greg NISBET <[email protected]>
Some nonce types have an embedded Node member and are in the same
package, so they appear to the sum type checker to be real variants
based on the heuristics that that package uses.

There are a few ways to handle this:
1) make the unknownNode and unknownType cases real variants
2) remove the tests that use unknownNode and unknownType
3) rewrite the tests that use unknownNode and unknownType to use a
   different strategy to detect the same defects.

Signed-off-by: Greg NISBET <[email protected]>
Remove unknownType and unknownNode and the two tests that depend on
them.

Signed-off-by: Greg NISBET <[email protected]>
@gregory-nisbet gregory-nisbet force-pushed the 2025-10-05-golangci-lint-additions branch from ffdcd12 to 685b2da Compare November 15, 2025 19:58
@gregory-nisbet
Copy link
Contributor Author

Rev'd PR. I think this will be the most controversial change (in convert_json.go).

+		case *SetType:
+			panic("SetType not yet handled in convertJSONAppliesTo")

at.ContextRecord = t
case *Path:
at.ContextPath = t
case *SetType:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you explain why this needed to be added, etc? I see there is another case of panic in this file, which I'm not really excited about either ... Is there a way we can rephrase both to avoid those panics? I'd rather we use error handling in bad cases.

Either way, the PR can't be merged without 100% coverage, so this does need to be covered with a test to show when it happens.

gregory-nisbet added a commit to gregory-nisbet/cedar-go that referenced this pull request Nov 22, 2025
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]>
@gregory-nisbet
Copy link
Contributor Author

I want to split this PR.

Here's the first piece: #121

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