Skip to content

x/tools/go/ssa: ent.withHooks$1: cannot convert *t0 (M) to PM #58633

Closed
@Antonboom

Description

@Antonboom

What version of Go are you using (go version)?

$ go version
go version go1.20.1 darwin/arm64

Does this issue reproduce with the latest release?

Yes, and it's actual for x/tools master too.

What did you do?

Demo: https://github.com/Antonboom/golangci-vs-ent-generics

$ golangci-lint version    
golangci-lint has version 1.51.2 built from 3e8facb4 on 2023-02-19T21:43:54Z

$ golangci-lint run ./...

What did you expect to see?

No panics.

What did you see instead?

ERRO Running error: 1 error occurred:
        * can't run linter goanalysis_metalinter: goanalysis_metalinter: buildssa:
        package "ent" (isInitialPkg: true, needAnalyzeSource: true): in
        github.com/Antonboom/golangci-vs-ent-generics/ent.withHooks$1:
        cannot convert *t0 (M) to PM
Full stack trace
ERRO [runner] Panic: buildssa: package "ent" (isInitialPkg: true, needAnalyzeSource: true): in github.com/Antonboom/golangci-vs-ent-generics/ent.withHooks$1: cannot convert *t0 (M) to PM: goroutine 4179 [running]:
runtime/debug.Stack()
        /usr/local/go/src/runtime/debug/stack.go:24 +0x64
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1()
        /Users/anthony/golangci-lint/pkg/golinters/goanalysis/runner_action.go:102 +0x108
panic({0x101d904a0, 0x140058f16a0})
        /usr/local/go/src/runtime/panic.go:884 +0x1f4
golang.org/x/tools/go/ssa.emitConv(0x140058a9080, {0x101f72740, 0x140058f6d80}, {0x101f69d48?, 0x140033fb290})
        /Users/anthony/golang_workspace/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/emit.go:286 +0xb40
golang.org/x/tools/go/ssa.emitStore(0x140058a9080, {0x101f72740, 0x140058f6cc0}, {0x101f72740, 0x140058f6d80}, 0x2aa377f)
        /Users/anthony/golang_workspace/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/emit.go:377 +0x58
golang.org/x/tools/go/ssa.(*address).store(0x140058fa0f0, 0x140058a9080?, {0x101f72740?, 0x140058f6d80?})
        /Users/anthony/golang_workspace/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/lvalue.go:40 +0x4c
golang.org/x/tools/go/ssa.(*storebuf).emit(...)
        /Users/anthony/golang_workspace/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:533
golang.org/x/tools/go/ssa.(*builder).assignStmt(0x140058a9080?, 0x140058a9080, {0x140035bc870, 0x1, 0x101f06d60?}, {0x140035bc890, 0x1, 0x100fd9900?}, 0x0)
        /Users/anthony/golang_workspace/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:1207 +0x370
golang.org/x/tools/go/ssa.(*builder).stmt(0x14003852838?, 0x140058a9080, {0x101f6cbd0?, 0x14002ec1a40?})
        /Users/anthony/golang_workspace/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:2181 +0x380
golang.org/x/tools/go/ssa.(*builder).stmtList(0x140058e9ec0?, 0x14000a67520?, {0x14002ec1a80?, 0x4, 0x140058e9ec0?})
        /Users/anthony/golang_workspace/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:946 +0x48
golang.org/x/tools/go/ssa.(*builder).stmt(0x140058a9080?, 0x140058a9080, {0x101f6ccf0?, 0x1400347c0c0?})
        /Users/anthony/golang_workspace/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:2277 +0x718
golang.org/x/tools/go/ssa.(*builder).buildFunctionBody(0x0?, 0x140058a9080)
        /Users/anthony/golang_workspace/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:2391 +0x354
golang.org/x/tools/go/ssa.(*builder).expr0(0x140038539f8, 0x1400300de00, {0x101f6cf90?, 0x140035bc900?}, {0x7, {0x101f69c58, 0x14003340740}, {0x0, 0x0}})
        /Users/anthony/golang_workspace/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:656 +0x42c
golang.org/x/tools/go/ssa.(*builder).expr(0x101dfec00?, 0x1400300de00, {0x101f6cf90, 0x140035bc900})
        /Users/anthony/golang_workspace/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:625 +0x11c
golang.org/x/tools/go/ssa.(*builder).expr0(0x140038539f8, 0x1400300de00, {0x101f6cd50?, 0x14002ec1b00?}, {0x7, {0x101f69bb8, 0x14002587260}, {0x0, 0x0}})
        /Users/anthony/golang_workspace/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:676 +0x5f8
golang.org/x/tools/go/ssa.(*builder).expr(0x101ef8e60?, 0x1400300de00, {0x101f6cd50, 0x14002ec1b00})
        /Users/anthony/golang_workspace/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:625 +0x11c
golang.org/x/tools/go/ssa.(*builder).assign(0x1400300de00?, 0x1400300de00?, {0x101f6f668?, 0x140058e9e30}, {0x101f6cd50?, 0x14002ec1b00?}, 0x0?, 0x0)
        /Users/anthony/golang_workspace/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:598 +0x30c
golang.org/x/tools/go/ssa.(*builder).localValueSpec(0x1400300de00?, 0x1400300de00, 0x14002c46190)
        /Users/anthony/golang_workspace/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:1147 +0xb8
golang.org/x/tools/go/ssa.(*builder).stmt(0x14003853548?, 0x1400300de00, {0x101f6ce40?, 0x140035bc950?})
        /Users/anthony/golang_workspace/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:2147 +0x14b0
golang.org/x/tools/go/ssa.(*builder).stmtList(0x140038535c8?, 0x101014e70?, {0x14000a6c100?, 0x8, 0x10?})
        /Users/anthony/golang_workspace/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:946 +0x48
golang.org/x/tools/go/ssa.(*builder).stmt(0x1400300de00?, 0x1400300de00, {0x101f6ccf0?, 0x1400347c3f0?})
        /Users/anthony/golang_workspace/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:2277 +0x718
golang.org/x/tools/go/ssa.(*builder).buildFunctionBody(0x14002fe3500?, 0x1400300de00)
        /Users/anthony/golang_workspace/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:2391 +0x354
golang.org/x/tools/go/ssa.(*builder).buildFunction(0x101503cc0?, 0x1400300de00)
        /Users/anthony/golang_workspace/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:2326 +0x30
golang.org/x/tools/go/ssa.(*builder).buildCreated(0x140038539f8)
        /Users/anthony/golang_workspace/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:2413 +0x28
golang.org/x/tools/go/ssa.(*Package).build(0x14002726900)
        /Users/anthony/golang_workspace/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:2606 +0xa60
sync.(*Once).doSlow(0x140003c6480?, 0x14003c59ae0?)
        /usr/local/go/src/sync/once.go:74 +0x100
sync.(*Once).Do(...)
        /usr/local/go/src/sync/once.go:65
golang.org/x/tools/go/ssa.(*Package).Build(...)
        /Users/anthony/golang_workspace/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:2477
golang.org/x/tools/go/analysis/passes/buildssa.run(0x1400362c1e0)
        /Users/anthony/golang_workspace/pkg/mod/golang.org/x/tools@v0.6.0/go/analysis/passes/buildssa/buildssa.go:72 +0x13c
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0x140015f2310)
        /Users/anthony/golangci-lint/pkg/golinters/goanalysis/runner_action.go:188 +0x94c
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2()
        /Users/anthony/golangci-lint/pkg/golinters/goanalysis/runner_action.go:106 +0x20
github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0x140006e6050, {0x101a7e2c1, 0x8}, 0x14001138f30)
        /Users/anthony/golangci-lint/pkg/timeutils/stopwatch.go:111 +0x44
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0x14000580d00?)
        /Users/anthony/golangci-lint/pkg/golinters/goanalysis/runner_action.go:105 +0x74
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0x140015f2310)
        /Users/anthony/golangci-lint/pkg/golinters/goanalysis/runner_loadingpackage.go:80 +0xb0
created by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze
        /Users/anthony/golangci-lint/pkg/golinters/goanalysis/runner_loadingpackage.go:75 +0x17c 
WARN [runner] Can't run linter goanalysis_metalinter: goanalysis_metalinter: buildssa: package "ent" (isInitialPkg: true, needAnalyzeSource: true): in github.com/Antonboom/golangci-vs-ent-generics/ent.withHooks$1: cannot convert *t0 (M) to PM 
WARN [linters_context] rowserrcheck is disabled because of generics. You can track the evolution of the generics support by following the https://github.com/golangci/golangci-lint/issues/2649. 
WARN [linters_context] wastedassign is disabled because of generics. You can track the evolution of the generics support by following the https://github.com/golangci/golangci-lint/issues/2649. 
INFO [runner] processing took 2.622µs with stages: max_same_issues: 500ns, skip_dirs: 292ns, nolint: 250ns, source_code: 208ns, exclude-rules: 167ns, sort_results: 125ns, filename_unadjuster: 125ns, max_from_linter: 125ns, cgo: 125ns, path_prettifier: 84ns, path_shortener: 84ns, skip_files: 83ns, identifier_marker: 83ns, max_per_file_from_linter: 83ns, diff: 83ns, uniq_by_line: 41ns, severity-rules: 41ns, path_prefixer: 41ns, exclude: 41ns, autogenerated_exclude: 41ns 
INFO [runner] linters took 1.620278917s with stages: goanalysis_metalinter: 1.620215167s, rowserrcheck: 13.75µs, wastedassign: 6.792µs 
ERRO Running error: 1 error occurred:
        * can't run linter goanalysis_metalinter: goanalysis_metalinter: buildssa: package "ent" (isInitialPkg: true, needAnalyzeSource: true): in github.com/Antonboom/golangci-vs-ent-generics/ent.withHooks$1: cannot convert *t0 (M) to PM

Additional info

  1. Related to bodyclose: panic "interface conversion: interface {} is nil, not *buildssa.SSA" golangci/golangci-lint#3086

  2. Suggested problematic code:

func withHooks[V Value, M any, PM interface {
	*M
	Mutation
}](ctx context.Context, exec func(context.Context) (V, error), mutation PM, hooks []Hook) (value V, err error) {
    /* ... */
}

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis 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