Skip to content

x/tools/go/ssa: panic: cannot convert interface #62085

@krhubert

Description

@krhubert

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

$ go version
go version go1.21.0 linux/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

GO111MODULE='auto'
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/user/.cache/go-build'
GOENV='/home/user/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/user/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/user'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/user/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/user/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.0'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/user/src/krhubert/govulncheck-issue/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1585313549=/tmp/go-build -gno-record-gcc-switches'

What did you do?

https://go.dev/play/p/iu87Idtjb5D

package main

import (
  "golang.org/x/tools/go/packages"
  "golang.org/x/tools/go/ssa"
)

func fn[I interface{ *any }](i I) {
  // panic: in main.fn: cannot convert *t0 (any) to I
  *i = *any(i).(I)
}

func main() {
  cfg := &packages.Config{
    Dir: "",
    Mode: packages.NeedImports |
      packages.NeedModule |
      packages.NeedSyntax |
      packages.NeedTypes |
      packages.NeedTypesInfo,
  }
  pkgs, err := packages.Load(cfg, "")
  if err != nil {
    panic(err)
  }
  pkg := pkgs[0]

  prog := ssa.NewProgram(pkg.Fset, ssa.InstantiateGenerics)
  for _, p := range pkg.Imports {
    prog.CreatePackage(p.Types, p.Syntax, p.TypesInfo, true)
  }

  prog.CreatePackage(pkg.Types, pkg.Syntax, pkg.TypesInfo, false)
  prog.Build()
}

What did you expect to see?

Success ssa program build.

What did you see instead?

panic: in main.fn: cannot convert *t0 (any) to I

goroutine 677 [running]:
golang.org/x/tools/go/ssa.emitConv(0xc0003a2900, {0x70bd60, 0xc000147ce0}, {0x709be8?, 0xc000405a70})
        /home/user/pkg/mod/golang.org/x/[email protected]/go/ssa/emit.go:286 +0xd79
golang.org/x/tools/go/ssa.emitStore(0xc0003a2900, {0x70bd60, 0xc000147c20}, {0x70bd60, 0xc000147ce0}, 0x640120)
        /home/user/pkg/mod/golang.org/x/[email protected]/go/ssa/emit.go:377 +0x58
golang.org/x/tools/go/ssa.(*address).store(0xc00011a720, 0xc0003a2900?, {0x70bd60?, 0xc000147ce0?})
        /home/user/pkg/mod/golang.org/x/[email protected]/go/ssa/lvalue.go:40 +0x45
golang.org/x/tools/go/ssa.(*storebuf).emit(...)
        /home/user/pkg/mod/golang.org/x/[email protected]/go/ssa/builder.go:533
golang.org/x/tools/go/ssa.(*builder).assignStmt(0xc000605840?, 0xc0003a2900, {0xc000116530, 0x1, 0x0?}, {0xc000116550, 0x1, 0x414668?}, 0x0)
        /home/user/pkg/mod/golang.org/x/[email protected]/go/ssa/builder.go:1207 +0x422
golang.org/x/tools/go/ssa.(*builder).stmt(0x1?, 0xc0003a2900, {0x70aae0?, 0xc0000f3880?})
        /home/user/pkg/mod/golang.org/x/[email protected]/go/ssa/builder.go:2179 +0x42d
golang.org/x/tools/go/ssa.(*builder).stmtList(...)
        /home/user/pkg/mod/golang.org/x/[email protected]/go/ssa/builder.go:946
golang.org/x/tools/go/ssa.(*builder).stmt(0xc0003a2900?, 0xc0003a2900, {0x70a990?, 0xc0004053b0?})
        /home/user/pkg/mod/golang.org/x/[email protected]/go/ssa/builder.go:2275 +0xe30
golang.org/x/tools/go/ssa.(*builder).buildFunctionBody(0x61ce6e?, 0xc0003a2900)
        /home/user/pkg/mod/golang.org/x/[email protected]/go/ssa/builder.go:2389 +0x410
golang.org/x/tools/go/ssa.(*builder).buildFunction(0x61cec0?, 0xc0003a2900)
        /home/user/pkg/mod/golang.org/x/[email protected]/go/ssa/builder.go:2324 +0x28
golang.org/x/tools/go/ssa.(*builder).buildCreated(0xc00005be18)
        /home/user/pkg/mod/golang.org/x/[email protected]/go/ssa/builder.go:2411 +0x25
golang.org/x/tools/go/ssa.(*Package).build(0xc0001fee00)
        /home/user/pkg/mod/golang.org/x/[email protected]/go/ssa/builder.go:2604 +0xc58
sync.(*Once).doSlow(0x0?, 0x0?)
        /home/user/go/src/sync/once.go:74 +0xbf
sync.(*Once).Do(...)
        /home/user/go/src/sync/once.go:65
golang.org/x/tools/go/ssa.(*Package).Build(...)
        /home/user/pkg/mod/golang.org/x/[email protected]/go/ssa/builder.go:2475
golang.org/x/tools/go/ssa.(*Program).Build.func1(0x0?)
        /home/user/pkg/mod/golang.org/x/[email protected]/go/ssa/builder.go:2460 +0x46
created by golang.org/x/tools/go/ssa.(*Program).Build in goroutine 1
        /home/user/pkg/mod/golang.org/x/[email protected]/go/ssa/builder.go:2459 +0x187
exit status 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeToolsThis 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