Skip to content

x/tools/internal/typesinternal/: regression inside v0.19.0 related to ReceiverNamed #66259

@ldez

Description

@ldez

Go version

go version go1.22.1 linux/amd64

Output of go env in your module/workspace:

GO111MODULE='on'
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/ldez/.cache/go-build'
GOENV='/home/ldez/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/ldez/sources/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/ldez/sources/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.0'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/ldez/sources/go/src/github.com/golangci/golangci-lint/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1404820727=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Using httpresponse pass through golangci-lint (current master branch) on this project golangci-repro-4482

./golangci-lint run ./tools/cmd/debug/...

Related to golangci/golangci-lint#4482

I bisected x/tools and the first commit with this problem is c111c4dfa

the value of n in n, ok := aliases.Unalias(t).(*types.Named) (inside IsNamedType) is nil and ok is true.

I think the problem is related to named, _ = aliases.Unalias(t).(*types.Named) inside ReceiverNamed.

The type assertion is "forcing" the type of named.

I'm still trying to find a minimal reproducible example, but if I extract the code the panic disappears.

What did you see happen?

A panic:

runtime/debug.Stack()
        /usr/lib/go/src/runtime/debug/stack.go:24 +0x5e
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1()
        /home/ldez/sources/go/src/github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:108 +0x277
panic({0x169eda0?, 0x22c2360?})
        /usr/lib/go/src/runtime/panic.go:770 +0x132
go/types.(*Named).Obj(...)
        /usr/lib/go/src/go/types/named.go:295
golang.org/x/tools/go/analysis/passes/internal/analysisutil.IsNamedType({0x1aa5cf0?, 0x0?}, {0x180ef88, 0x8}, {0xc0022d7af8, 0x1, 0x6c61562a5d5b2073?})
        /home/ldez/sources/go/pkg/mod/golang.org/x/tools@v0.19.0/go/analysis/passes/internal/analysisutil/util.go:123 +0x49
golang.org/x/tools/go/analysis/passes/httpresponse.isHTTPFuncOrMethodOnClient(0xc015ef7380, 0xc0022d7ba0?)
        /home/ldez/sources/go/pkg/mod/golang.org/x/tools@v0.19.0/go/analysis/passes/httpresponse/httpresponse.go:122 +0xfb
golang.org/x/tools/go/analysis/passes/httpresponse.run.func1({0x1aa5110?, 0xc01642f700?}, 0x10?, {0xc007030200, 0x6, 0x20})
        /home/ldez/sources/go/pkg/mod/golang.org/x/tools@v0.19.0/go/analysis/passes/httpresponse/httpresponse.go:62 +0x73
golang.org/x/tools/go/ast/inspector.(*Inspector).WithStack(0xc0164ed200, {0xc0022d7cb8?, 0x22ee1c0?, 0xc001208008?}, 0xc002155cc8)
        /home/ldez/sources/go/pkg/mod/golang.org/x/tools@v0.19.0/go/ast/inspector/inspector.go:148 +0x188
golang.org/x/tools/go/analysis/passes/httpresponse.run(0xc01e3fc0d0)
        /home/ldez/sources/go/pkg/mod/golang.org/x/tools@v0.19.0/go/analysis/passes/httpresponse/httpresponse.go:57 +0x112
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0xc00128e7e0)
        /home/ldez/sources/go/src/github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:190 +0xa02
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2()
        /home/ldez/sources/go/src/github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:112 +0x17
github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0xc001b5c3c0, {0x18596d7, 0xc}, 0xc002138f48)
        /home/ldez/sources/go/src/github.com/golangci/golangci-lint/pkg/timeutils/stopwatch.go:111 +0x44
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0xc001037e60?)
        /home/ldez/sources/go/src/github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:111 +0x7a
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0xc00128e7e0)
        /home/ldez/sources/go/src/github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_loadingpackage.go:80 +0xa8
created by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze in goroutine 204
        /home/ldez/sources/go/src/github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_loadingpackage.go:75 +0x205 
WARN [runner] Can't run linter goanalysis_metalinter: goanalysis_metalinter: httpresponse: package "main" (isInitialPkg: true, needAnalyzeSource: true): runtime error: invalid memory address or nil pointer dereference

What did you expect to see?

No panic.

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeToolsThis label describes issues relating to any tools in the x/tools repository.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy