Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Internal error: unhandled case *types.Interface" when embedding any in a struct #1361

Closed
tulir opened this issue Feb 3, 2023 · 7 comments
Closed
Labels

Comments

@tulir
Copy link

tulir commented Feb 3, 2023

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=)
@tulir tulir added bug needs-triage Newly filed issue that needs triage labels Feb 3, 2023
@dominikh dominikh removed the needs-triage Newly filed issue that needs triage label Feb 3, 2023
@dominikh
Copy link
Owner

dominikh commented Feb 3, 2023

Different reproducer showing the actual problem: embedding type aliases to unnamed types:

package pkg

type S = struct{}

type Foo struct {
	S
}

will fix.

@james-johnston-thumbtack

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
Copy link

I am also encountering this error, tho with panic: internal error: unhandled case *types.Map instead of *types.Interface.

@dominikh
Copy link
Owner

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
Copy link

rsdutta commented Feb 24, 2023

Will a fix for this be in the next release?

@dominikh
Copy link
Owner

Will a fix for this be in the next release?

Hopefully, yes. But I can't put a precise date on when the next release will be.

@rsdutta
Copy link

rsdutta commented Feb 25, 2023

Will a fix for this be in the next release?

Hopefully, yes. But I can't put a precise date on when the next release will be.

No worries, appreciate the quick response! 🙏

dominikh added a commit that referenced this issue Mar 15, 2023
Closes: gh-1361
Closes: gh-1365
(cherry picked from commit d717045)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants