From e6a088e6bbd6ec4c3304c5f46f1f274b7ef4703c Mon Sep 17 00:00:00 2001 From: cce <51567+cce@users.noreply.github.com> Date: Fri, 24 Oct 2025 14:37:40 -0400 Subject: [PATCH] fix alias handling and upgrade to go >=1.24 --- .github/workflows/ci.yml | 20 +++----------------- Makefile | 2 -- common.go | 3 +++ enum.go | 5 +++-- go.mod | 9 ++++++--- go.sum | 13 ++++++++----- map.go | 16 +++++++++------- 7 files changed, 32 insertions(+), 36 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f48d30d..9a637a9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 }} @@ -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 diff --git a/Makefile b/Makefile index 868f7fc..2e4d94d 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,6 @@ 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 @@ -32,7 +31,6 @@ install-vet: .PHONY: vet vet: go vet ./... - exhaustive ./... ineffassign ./... errcheck ./... staticcheck -checks="inherit,-S1034" ./... diff --git a/common.go b/common.go index 71bc8d5..bf30ff7 100644 --- a/common.go +++ b/common.go @@ -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) diff --git a/enum.go b/enum.go index e95e78e..1960edd 100644 --- a/enum.go +++ b/enum.go @@ -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 @@ -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 diff --git a/go.mod b/go.mod index 0edefe7..d3caaf5 100644 --- a/go.mod +++ b/go.mod @@ -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 +) diff --git a/go.sum b/go.sum index 0c8cfcf..9b34f09 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/map.go b/map.go index aa5e9bd..4243f32 100644 --- a/map.go +++ b/map.go @@ -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 {