Repository navigation
Closed
Closed
Copy link
Labels
Description
Started in v0.4.0. v0.3.3 doesn't panic
$ cat test.go
package main
type Foo struct {
any
}
$ staticcheck test.go
panic: internal error: unhandled case *types.Interface
goroutine 55 [running]:
honnef.co/go/tools/analysis/lint.ExhaustiveTypeSwitch(...)
$GOPATH/pkg/mod/honnef.co/go/tools@v0.4.0/analysis/lint/lint.go:234
honnef.co/go/tools/unused.(*graph).embeddedField(0xc00059fcb0, {0xa25438?, 0xc0003fa5c0?}, {0xa2d098, 0xc00039d180})
$GOPATH/pkg/mod/honnef.co/go/tools@v0.4.0/unused/unused.go:1413 +0x58a
honnef.co/go/tools/unused.(*graph).namedType(0xc00059fcb0, 0xa252f8?, {0xa27298?, 0xc0004870b0?})
$GOPATH/pkg/mod/honnef.co/go/tools@v0.4.0/unused/unused.go:1502 +0x27c
honnef.co/go/tools/unused.(*graph).decl(0xc00059fcb0, {0xa26ed8?, 0xc000489140?}, {0x0, 0x0})
$GOPATH/pkg/mod/honnef.co/go/tools@v0.4.0/unused/unused.go:1099 +0xab2
honnef.co/go/tools/unused.(*graph).entry(0xc00059fcb0)
$GOPATH/pkg/mod/honnef.co/go/tools@v0.4.0/unused/unused.go:518 +0xc3c
honnef.co/go/tools/unused.run(0xc0002fa2d0)
$GOPATH/pkg/mod/honnef.co/go/tools@v0.4.0/unused/unused.go:219 +0x245
honnef.co/go/tools/lintcmd/runner.(*analyzerRunner).do(0xc0004e0030, {0xa28278?, 0xc0004cf4a0})
$GOPATH/pkg/mod/honnef.co/go/tools@v0.4.0/lintcmd/runner/runner.go:992 +0x63c
honnef.co/go/tools/lintcmd/runner.genericHandle({0xa28278?, 0xc0004cf4a0}, {0xa28278?, 0xc000390f00?}, 0x0?, 0xc000410740, 0xc0002828d0)
$GOPATH/pkg/mod/honnef.co/go/tools@v0.4.0/lintcmd/runner/runner.go:817 +0x102
created by honnef.co/go/tools/lintcmd/runner.(*subrunner).runAnalyzers
$GOPATH/pkg/mod/honnef.co/go/tools@v0.4.0/lintcmd/runner/runner.go:1061 +0x70a
$ staticcheck -debug.version
staticcheck 2023.1 (v0.4.0)
Compiled with Go version: go1.19.3
Main module:
honnef.co/go/tools@v0.4.0 (sum: h1:lyXVV1c8wUBJRKqI8JgIpT8TW1VDagfYYaxbKa/HoL8=)
Dependencies:
github.com/BurntSushi/toml@v1.2.1 (sum: h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=)
golang.org/x/exp/typeparams@v0.0.0-20221208152030-732eee02a75a (sum: h1:Jw5wfR+h9mnIYH+OtGT2im5wV1YGGDora5vTv/aa5bE=)
golang.org/x/mod@v0.7.0 (sum: h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA=)
golang.org/x/sys@v0.3.0 (sum: h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=)
golang.org/x/tools@v0.4.1-0.20221208213631-3f74d914ae6d (sum: h1:9ZNWAi4CYhNv60mXGgAncgq7SGc5qa7C8VZV8Tg7Ggs=)
Reacted by Kenji Shimizu, Rishov and Remi Matthey-Doret
Activity
dominikh commentedon Feb 3, 2023
Different reproducer showing the actual problem: embedding type aliases to unnamed types:
will fix.
james-johnston-thumbtack commentedon Feb 11, 2023
I also ran into this problem; our code also used a type alias for a struct, and I distilled a test case down to the exact same case that @dominikh came up with. Got the exact same panic and stack trace, too. Worked on 0.3.3, but not 0.4.0.
deefdragon commentedon Feb 15, 2023
I am also encountering this error, tho with
panic: internal error: unhandled case *types.Mapinstead of*types.Interface.dominikh commentedon Feb 15, 2023
Embedding any alias that resolves to an unnamed type (such as
type foo = map[...][...]) will run into this crash. The message will depend on the specific type used.rsdutta commentedon Feb 24, 2023
Will a fix for this be in the next release?
dominikh commentedon Feb 24, 2023
Hopefully, yes. But I can't put a precise date on when the next release will be.
rsdutta commentedon Feb 25, 2023
No worries, appreciate the quick response! 🙏
unused: handle embedded aliases
unused: handle embedded aliases