You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I believe I found an issue with Go 1.18 and generics, and I couldn't find this specific one at #2649, so I'm opening this issue. Sorry if it is the wrong approach.
The problem appears when I try to set a func variable from a generic version (e.g. func MyFunc[T any]() T) into a variable (e.g. var x func() string = MyFunc[string]), and golangci-lint fails.
From what I understand it is failing to even compile the project, so it is not even doing that in an specific lint, but I'm not sure of that.
You can find details with a minimalist sample code bellow.
Version of golangci-lint
$ golangci-lint --versiongolangci-lint has version v1.46.2 built from a3336890 on 2022-05-17T11:51:30Z
Configuration file
No config file used.
Go environment
$ go versiongo version go1.18.3 linux/amd64
Verbose output of running
$ docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.46.2 golangci-lint run -vlevel=info msg="[config_reader] Config search paths: [./ /app / /root]"level=info msg="[lintersdb] Active 10 linters: [deadcode errcheck gosimple govet ineffassign staticcheck structcheck typecheck unused varcheck]"level=info msg="[loader] Go packages loading at mode 575 (types_sizes|compiled_files|files|imports|deps|exports_file|name) took 149.583638ms"level=info msg="[runner/filename_unadjuster] Pre-built 0 adjustments in 133.082µs"level=info msg="[linters context/goanalysis] analyzers took 1.268340744s with top 10 stages: buildir: 887.014509ms, inspect: 72.124674ms, fact_purity: 69.883557ms, nilness: 58.739632ms, ctrlflow: 47.670682ms, fact_deprecated: 46.621729ms, printf: 35.930006ms, SA5012: 31.399724ms, typedness: 16.470586ms, S1030: 116.195µs"
level=error msg="[runner] Panic: buildir: package \"main\" (isInitialPkg: true, needAnalyzeSource: true): in lint-test.main: cannot convert lint-test.Foo (func[T any]() T) to func() string: goroutine 1160 [running]:\nruntime/debug.Stack()\n\truntime/debug/stack.go:24 +0x65\ngithub.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1()\n\tgithub.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:101 +0x155\npanic({0xea9680, 0xc00eb10f40})\n\truntime/panic.go:838 +0x207\nhonnef.co/go/tools/go/ir.emitConv(0xc001284000, {0x1270190, 0xc001281e00}, {0x12662a8?, 0xc003a38980}, {0x1265650, 0xc003a38480})\n\thonnef.co/go/tools@v0.3.1/go/ir/emit.go:293 +0xd29\nhonnef.co/go/tools/go/ir.emitStore(0xc001284000, {0x126fc48, 0xc001d21800}, {0x1270190, 0xc001281e00}, {0x1265650, 0xc003a38480})\n\thonnef.co/go/tools@v0.3.1/go/ir/emit.go:302 +0x7f\nhonnef.co/go/tools/go/ir.(*address).store(0xc0051826c0, 0x0?, {0x1270190?, 0xc001281e00?}, {0x1265650?, 0xc003a38480?})\n\thonnef.co/go/tools@v0.3.1/go/ir/lvalue.go:37 +0x53\nhonnef.co/go/tools/go/ir.(*storebuf).emit(0x1265650?, 0xc001284000)\n\thonnef.co/go/tools@v0.3.1/go/ir/builder.go:455 +0xeb\nhonnef.co/go/tools/go/ir.(*builder).assignStmt(0xc00d0b84b0?, 0xc001284000, {0xc001c921c0, 0x1, 0x0?}, {0xc001c921d0, 0x1, 0x0?}, 0x0, {0x1265650, ...})\n\thonnef.co/go/tools@v0.3.1/go/ir/builder.go:1113 +0x2de\nhonnef.co/go/tools/go/ir.(*builder).stmt(0x0?, 0xc001284000, {0x1268c20?, 0xc003a38480?})\n\thonnef.co/go/tools@v0.3.1/go/ir/builder.go:2245 +0xa0b\nhonnef.co/go/tools/go/ir.(*builder).stmtList(0x0?, 0x0?, {0xc003a38600?, 0x4, 0x0?})\n\thonnef.co/go/tools@v0.3.1/go/ir/builder.go:848 +0x67\nhonnef.co/go/tools/go/ir.(*builder).stmt(0xc001284000?, 0xc001284000, {0x1268d40?, 0xc0031d44b0?})\n\thonnef.co/go/tools@v0.3.1/go/ir/builder.go:2331 +0xd31\nhonnef.co/go/tools/go/ir.(*builder).buildFunction(0xc000adfa28, 0xc001284000)\n\thonnef.co/go/tools@v0.3.1/go/ir/builder.go:2443 +0x453\nhonnef.co/go/tools/go/ir.(*builder).buildFuncDecl(0xc00175a380?, 0xc00018da70, 0xc0031d4510)\n\thonnef.co/go/tools@v0.3.1/go/ir/builder.go:2481 +0x195\nhonnef.co/go/tools/go/ir.(*Package).build(0xc00018da70)\n\thonnef.co/go/tools@v0.3.1/go/ir/builder.go:2587 +0xc52\nsync.(*Once).doSlow(0xc00175a000?, 0xc00d0b8960?)\n\tsync/once.go:68 +0xc2\nsync.(*Once).Do(...)\n\tsync/once.go:59\nhonnef.co/go/tools/go/ir.(*Package).Build(...)\n\thonnef.co/go/tools@v0.3.1/go/ir/builder.go:2505\nhonnef.co/go/tools/internal/passes/buildir.run(0xc0000b8000)\n\thonnef.co/go/tools@v0.3.1/internal/passes/buildir/buildir.go:86 +0x368\ngithub.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0xc000725050)\n\tgithub.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:187 +0x9c4\ngithub.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2()\n\tgithub.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:105 +0x1d\ngithub.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0xc00035c3c0, {0x101a559, 0x7}, 0xc000620748)\n\tgithub.com/golangci/golangci-lint/pkg/timeutils/stopwatch.go:111 +0x4a\ngithub.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0xc001090360?)\n\tgithub.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:104 +0x85\ngithub.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0xc000725050)\n\tgithub.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_loadingpackage.go:80 +0xb4\ncreated by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze\n\tgithub.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_loadingpackage.go:75 +0x1eb\n"
level=warning msg="[runner] Can't run linter goanalysis_metalinter: goanalysis_metalinter: buildir: package \"main\" (isInitialPkg: true, needAnalyzeSource: true): in lint-test.main: cannot convert lint-test.Foo (func[T any]() T) to func() string"level=warning msg="[linters context] structcheck is disabled because of go1.18. You can track the evolution of the go1.18 support by following the https://github.com/golangci/golangci-lint/issues/2649."level=info msg="[runner] processing took 2.388µs with stages: max_same_issues: 385ns, skip_dirs: 332ns, nolint: 280ns, max_from_linter: 181ns, path_prettifier: 162ns, cgo: 120ns, uniq_by_line: 111ns, exclude: 110ns, autogenerated_exclude: 107ns, skip_files: 107ns, filename_unadjuster: 106ns, exclude-rules: 47ns, path_shortener: 45ns, source_code: 44ns, diff: 43ns, path_prefixer: 43ns, max_per_file_from_linter: 42ns, sort_results: 41ns, severity-rules: 41ns, identifier_marker: 41ns"level=info msg="[runner] linters took 1.076383933s with stages: goanalysis_metalinter: 1.076346034s, structcheck: 5.957µs"level=error msg="Running error: 1 error occurred:\n\t* can't run linter goanalysis_metalinter: goanalysis_metalinter: buildir: package \"main\" (isInitialPkg: true, needAnalyzeSource: true): in lint-test.main: cannot convert lint-test.Foo (func[T any]() T) to func() string\n\n"level=info msg="Memory: 14 samples, avg is 154.0MB, max is 258.8MB"level=info msg="Execution took 1.233650493s"
Code example or link to a public repository
Sample code (just called it main.go into a project named lint-test):
package main
import (
"fmt"
)
funcFoo[Tany]() T {
varretTreturnret
}
funcmain() {
varstrCallerfunc() stringstrCaller=Foo[string]
strCaller()
fmt.Println("OK")
}
The text was updated successfully, but these errors were encountered:
Welcome
Description of the problem
Hi all,
I believe I found an issue with Go 1.18 and generics, and I couldn't find this specific one at #2649, so I'm opening this issue. Sorry if it is the wrong approach.
The problem appears when I try to set a func variable from a generic version (e.g.
func MyFunc[T any]() T
) into a variable (e.g.var x func() string = MyFunc[string]
), and golangci-lint fails.From what I understand it is failing to even compile the project, so it is not even doing that in an specific lint, but I'm not sure of that.
You can find details with a minimalist sample code bellow.
Version of golangci-lint
Configuration file
No config file used.
Go environment
Verbose output of running
Code example or link to a public repository
Sample code (just called it main.go into a project named
lint-test
):The text was updated successfully, but these errors were encountered: