Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
all:
strategy:
matrix:
go-version: [1.18, 1.19, 1.x]
go-version: ["1.24", "1.25", "1.x"]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}

Expand All @@ -20,24 +20,10 @@ jobs:
- name: build
run: make build

# For earlier go versions, staticcheck build fails due to:
#
# ../../../go/pkg/mod/honnef.co/go/tools@v0.3.3/go/ir/builder.go:36:2:
# //go:build comment without // +build comment
#
# or due to:
#
# ../../../go/pkg/mod/honnef.co/go/tools@v0.4.3/staticcheck/lint.go:4030:36:
# sel.Obj().(*types.Func).Origin undefined (type *types.Func has no field
# or method Origin)
# note: module requires Go 1.19
#
- name: install vet tools (go 1.19 or later)
if: ${{ matrix.go-version >= '1.19' }}
- name: install vet tools
run: make install-vet

- name: vet (go 1.19 or later)
if: ${{ matrix.go-version >= '1.19' }}
- name: vet
run: make vet

- name: test
Expand Down
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ cover:

.PHONY: install-vet
install-vet:
go install github.com/nishanths/exhaustive/cmd/exhaustive@latest
go install github.com/gordonklaus/ineffassign@latest
go install github.com/kisielk/errcheck@latest
go install honnef.co/go/tools/cmd/staticcheck@latest

.PHONY: vet
vet:
go vet ./...
exhaustive ./...
ineffassign ./...
errcheck ./...
staticcheck -checks="inherit,-S1034" ./...
Expand Down
3 changes: 3 additions & 0 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ func fromTypeParam(pass *analysis.Pass, tp *types.TypeParam, typeparam bool) (re

func fromType(pass *analysis.Pass, t types.Type, typeparam bool) (result []enumTypeAndMembers, ok bool) {
switch t := t.(type) {
case *types.Alias:
return fromType(pass, types.Unalias(t), typeparam)

case *types.Named:
return fromNamed(pass, t, typeparam)

Expand Down
5 changes: 3 additions & 2 deletions enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func possibleEnumMember(constName *ast.Ident, info *types.Info) (et enumType, na
return enumType{}, "", "", false
}

named := obj.Type().(*types.Named) // guaranteed by validNamedBasic
named := types.Unalias(obj.Type()).(*types.Named) // guaranteed by validNamedBasic
tn := named.Obj()

// By definition, enum type's scope and enum member's scope must be the
Expand Down Expand Up @@ -216,8 +216,9 @@ func hasIgnoreDecl(pass *analysis.Pass, doc *ast.CommentGroup) bool {
//
// The following is guaranteed:
//
// validNamedBasic(t) == true => t.(*types.Named)
// validNamedBasic(t) == true => types.Unalias(t).(*types.Named)
func validNamedBasic(t types.Type) bool {
t = types.Unalias(t)
named, ok := t.(*types.Named)
if !ok {
return false
Expand Down
9 changes: 6 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
module github.com/nishanths/exhaustive

go 1.18
go 1.24.0

require golang.org/x/tools v0.18.0
require golang.org/x/tools v0.38.0

require golang.org/x/mod v0.15.0 // indirect
require (
golang.org/x/mod v0.29.0 // indirect
golang.org/x/sync v0.17.0 // indirect
)
13 changes: 8 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8=
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ=
golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
golang.org/x/mod v0.29.0 h1:HV8lRxZC4l2cr3Zq1LvtOsi/ThTgWnUk/y64QSs8GwA=
golang.org/x/mod v0.29.0/go.mod h1:NyhrlYXJ2H4eJiRy/WDBO6HMqZQ6q9nk4JzS3NuCK+w=
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/tools v0.38.0 h1:Hx2Xv8hISq8Lm16jvBZ2VQf+RLmbd7wVUsALibYI/IQ=
golang.org/x/tools v0.38.0/go.mod h1:yEsQ/d/YK8cjh0L6rZlY8tgtlKiBNTL14pGDJPJpYQs=
16 changes: 9 additions & 7 deletions map.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,18 @@ func mapChecker(pass *analysis.Pass, cfg mapConfig, generated boolCache, comment

lit := n.(*ast.CompositeLit)

mapType, ok := pass.TypesInfo.Types[lit.Type].Type.(*types.Map)
if !ok {
namedType, ok2 := pass.TypesInfo.Types[lit.Type].Type.(*types.Named)
if !ok2 {
return true, resultNotMapLiteral
}
mapType, ok = namedType.Underlying().(*types.Map)
var mapType *types.Map
switch tt := types.Unalias(pass.TypesInfo.Types[lit.Type].Type).(type) {
case *types.Map:
mapType = tt
case *types.Named:
var ok bool
mapType, ok = tt.Underlying().(*types.Map)
if !ok {
return true, resultNotMapLiteral
}
default:
return true, resultNotMapLiteral
}

if len(lit.Elts) == 0 {
Expand Down