Skip to content

Panic when checking code with a pointer to a type alias #256

@mihaip

Description

@mihaip

We're using errcheck v1.7.0 via golangci-lint on Go 1.23.2, and encountered this error when upgrading a dependency:

level=error msg="[runner] Panic: errcheck: package \"voice\" (isInitialPkg: true, needAnalyzeSource: true): cannot get Field of a type that is not a struct, got a *types.Alias: goroutine 54856 [running]:
runtime/debug.Stack()
	/opt/hostedtoolcache/go/1.23.2/x64/src/runtime/debug/stack.go:26 +0x5e
github.com/golangci/golangci-lint/pkg/goanalysis.(*action).analyzeSafe.func1()
	/tmp/custom-gcl2417513237/golangci-lint/pkg/goanalysis/runner_action.go:109 +0x277
panic({0x190e000?, 0xc02638d2c0?})
	/opt/hostedtoolcache/go/1.23.2/x64/src/runtime/panic.go:785 +0x132
github.com/kisielk/errcheck/errcheck.getTypeAtFieldIndex({0x1e5dce0?, 0xc058a61920?}, 0x49?)
	/home/runner/go/pkg/mod/github.com/kisielk/[email protected]/errcheck/embedded_walker.go:90 +0xdd
github.com/kisielk/errcheck/errcheck.walkThroughEmbeddedInterfaces(0x19a42a0?)
	/home/runner/go/pkg/mod/github.com/kisielk/[email protected]/errcheck/embedded_walker.go:49 +0x8e
github.com/kisielk/errcheck/errcheck.(*visitor).namesForExcludeCheck(0xc04338fa90, 0xc00f90c380?)
	/home/runner/go/pkg/mod/github.com/kisielk/[email protected]/errcheck/errcheck.go:362 +0x165
github.com/kisielk/errcheck/errcheck.(*visitor).excludeCall(0xc04338fa90, 0xc04338fa90?)
	/home/runner/go/pkg/mod/github.com/kisielk/[email protected]/errcheck/errcheck.go:401 +0x72
github.com/kisielk/errcheck/errcheck.(*visitor).ignoreCall(0xc04338fa90, 0xc00f90c380)
	/home/runner/go/pkg/mod/github.com/kisielk/[email protected]/errcheck/errcheck.go:413 +0x2c
github.com/kisielk/errcheck/errcheck.(*visitor).Visit(0xc04338fa90, {0x1e5d5b8?, 0xc060ef9f50})
	/home/runner/go/pkg/mod/github.com/kisielk/[email protected]/errcheck/errcheck.go:560 +0x137
go/ast.Walk({0x1e572e0?, 0xc04338fa90?}, {0x1e5d5b8, 0xc060ef9f50})
	/opt/hostedtoolcache/go/1.23.2/x64/src/go/ast/walk.go:34 +0x4c
go/ast.walkList[...](...)
	/opt/hostedtoolcache/go/1.23.2/x64/src/go/ast/walk.go:21
go/ast.Walk({0x1e572e0?, 0xc04338fa90?}, {0x1e5d090, 0xc01dbd8a50})
	/opt/hostedtoolcache/go/1.23.2/x64/src/go/ast/walk.go:211 +0x30ad
go/ast.Walk({0x1e572e0?, 0xc04338fa90?}, {0x1e5b8a8, 0xc01dbd8a80})
	/opt/hostedtoolcache/go/1.23.2/x64/src/go/ast/walk.go:332 +0xf7c
go/ast.walkList[...](...)
	/opt/hostedtoolcache/go/1.23.2/x64/src/go/ast/walk.go:21
go/ast.Walk({0x1e572e0?, 0xc04338fa90?}, {0x1e5b6e0, 0xc02238d180})
	/opt/hostedtoolcache/go/1.23.2/x64/src/go/ast/walk.go:341 +0x3585
github.com/kisielk/errcheck/errcheck.(*Checker).CheckPackage(0xc0003782a0, 0xc002f1cad8)
	/home/runner/go/pkg/mod/github.com/kisielk/[email protected]/errcheck/errcheck.go:235 +0x425
github.com/golangci/golangci-lint/pkg/golinters/errcheck.runErrCheck(0xc0002fcd20, 0xc058336620, 0xc0003782a0?)
	/tmp/custom-gcl2417513237/golangci-lint/pkg/golinters/errcheck/errcheck.go:82 +0xab
github.com/golangci/golangci-lint/pkg/golinters/errcheck.New.func1.1(0x19a4000?)
	/tmp/custom-gcl2417513237/golangci-lint/pkg/golinters/errcheck/errcheck.go:54 +0x49
github.com/golangci/golangci-lint/pkg/goanalysis.(*action).analyze(0xc007659d30)
	/tmp/custom-gcl2417513237/golangci-lint/pkg/goanalysis/runner_action.go:191 +0x9cd
github.com/golangci/golangci-lint/pkg/goanalysis.(*action).analyzeSafe.func2()
	/tmp/custom-gcl2417513237/golangci-lint/pkg/goanalysis/runner_action.go:113 +0x17
github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0xc0028e2a00, {0x1b65691, 0x8}, 0xc0034aef48)
	/tmp/custom-gcl2417513237/golangci-lint/pkg/timeutils/stopwatch.go:111 +0x44
github.com/golangci/golangci-lint/pkg/goanalysis.(*action).analyzeSafe(0xc005a4a660?)
	/tmp/custom-gcl2417513237/golangci-lint/pkg/goanalysis/runner_action.go:112 +0x6e
github.com/golangci/golangci-lint/pkg/goanalysis.(*loadingPackage).analyze.func2(0xc007659d30)
	/tmp/custom-gcl2417513237/golangci-lint/pkg/goanalysis/runner_loadingpackage.go:82 +0xa5
created by github.com/golangci/golangci-lint/pkg/goanalysis.(*loadingPackage).analyze in goroutine 1034
	/tmp/custom-gcl2417513237/golangci-lint/pkg/goanalysis/runner_loadingpackage.go:77 +0x1e9
"

The dependency https://github.com/deepgram/deepgram-go-sdk, and we were bumping it from v1.4.0 to v.1.6.0. As part of that a type was deprecated and became an alias (source):

package websocketv1

...
// Client is an alias for WSCallback
// Deprecated: use WSCallback instead
type Client = WSCallback
package voice

import (
	listenapi "github.com/deepgram/deepgram-go-sdk/pkg/client/listen/v1/websocket"
)
...
type deepgramTranscriptionRequest struct {
	client *listenapi.Callback
}

#248 added support for type aliases - which is in the version that we're using, but perhaps there's an additional edge case here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions