Skip to content

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

Closed

Description

@tulir

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=)

Activity

  1. added
    needs-triage
    on Feb 3, 2023
  2. removed
    needs-triage
    on Feb 3, 2023
  3. dominikh commented on Feb 3, 2023

    @dominikh
    Owner

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

    package pkg
    
    type S = struct{}
    
    type Foo struct {
    	S
    }
    

    will fix.

  4. james-johnston-thumbtack commented on Feb 11, 2023

    @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.

  5. deefdragon commented on Feb 15, 2023

    @deefdragon

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

  6. dominikh commented on Feb 15, 2023

    @dominikh
    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.

  7. rsdutta commented on Feb 24, 2023

    @rsdutta

    Will a fix for this be in the next release?

  8. dominikh commented on Feb 24, 2023

    @dominikh
    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.

  9. rsdutta commented on Feb 25, 2023

    @rsdutta

    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! 🙏

  10. added a commit that references this issue on Mar 15, 2023
    3cd466f
  11. added a commit that references this issue on Feb 27, 2024
    d717045
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions