Skip to content

Commit a446b9d

Browse files
committed
x/exp/schema/resolved: move sumtype linter out of golangci-lint
When running go-check-sumtype in golangci-lint, sum types can only be checked in the package in which they're defined (see golangci/golangci-lint#4158). Bummer. This change makes it so that we now run the linter explicitly in CI. Signed-Off-By: Patrick Jakubowski <patrick.jakubowski@strongdm.com>
1 parent 37ffd93 commit a446b9d

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

.github/workflows/build_and_test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ jobs:
2424
- name: Lint
2525
uses: golangci/golangci-lint-action@v7
2626

27+
- name: Sum type linter
28+
run: go install github.com/alecthomas/go-check-sumtype/cmd/go-check-sumtype@latest && go-check-sumtype -default-signifies-exhaustive=false ./...
29+
2730
- name: Fuzz
2831
run: mkdir -p testdata && go test -fuzz=FuzzParse -fuzztime 60s && go test -fuzz=FuzzTokenize -fuzztime 60s
2932

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ linters:
1010
enable:
1111
- errcheck
1212
- errname
13-
- gochecksumtype
1413
- govet
1514
- ineffassign
1615
- revive

x/exp/schema/resolved/resolve.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ func (r *resolverState) resolveType(ns types.Path, t ast.IsType) (IsType, error)
377377
case ast.TypeRef:
378378
return r.resolveTypeRef(ns, t)
379379
default:
380-
return nil, fmt.Errorf("unknown AST type: %T", t)
380+
panic(fmt.Sprintf("unknown AST type: %T", t))
381381
}
382382
}
383383

@@ -593,8 +593,10 @@ func collectTypeRefs(t ast.IsType) []ast.TypeRef {
593593
refs = append(refs, collectTypeRefs(attr.Type)...)
594594
}
595595
return refs
596-
default:
596+
case ast.BoolType, ast.EntityTypeRef, ast.ExtensionType, ast.LongType, ast.StringType:
597597
return nil
598+
default:
599+
panic(fmt.Sprintf("unknown AST type: %T", t))
598600
}
599601
}
600602

x/exp/schema/resolved/resolve_internal_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ func TestResolveTypeDefault(t *testing.T) {
1515
enumTypes: make(map[types.EntityType]bool),
1616
commonTypes: make(map[types.Path]ast.IsType),
1717
}
18-
_, err := r.resolveType("", nil)
19-
testutil.Error(t, err)
18+
testutil.Panic(t, func() {
19+
_, _ = r.resolveType("", nil)
20+
})
2021
}
2122

2223
func TestResolveTypePath(t *testing.T) {
@@ -55,9 +56,14 @@ func TestResolveActionParentRef(t *testing.T) {
5556
}
5657

5758
func TestCollectTypeRefsDefault(t *testing.T) {
58-
// Exercise the default branch (non-TypeRef, non-Set, non-Record).
59+
// Exercise the non-container type branch
5960
refs := collectTypeRefs(ast.StringType{})
6061
testutil.Equals(t, len(refs), 0)
62+
63+
// Exercise the impossible to hit branch
64+
testutil.Panic(t, func() {
65+
collectTypeRefs(nil)
66+
})
6167
}
6268

6369
func TestDetectCommonTypeCyclesBuiltinRef(t *testing.T) {

0 commit comments

Comments
 (0)