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

x/text/cmd/gotext: gotext does not work with generics #67512

Open
taraktikos opened this issue May 19, 2024 · 1 comment
Open

x/text/cmd/gotext: gotext does not work with generics #67512

taraktikos opened this issue May 19, 2024 · 1 comment
Labels
WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@taraktikos
Copy link

taraktikos commented May 19, 2024

Go version

go version go1.22.3 darwin/arm6

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN='/Users/username/go/bin'
GOCACHE='/Users/username/Library/Caches/go-build'
GOENV='/Users/username/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/username/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/username/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.22.3/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.22.3/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.3'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/Users/username/Projects/pagoda/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 -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/gr/q21d720j6yg3q4fv0wh5vp680000gn/T/go-build986713848=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

I have the following generated code by ent library:

// withHooks invokes the builder operation with the given hooks, if any.
func withHooks[V Value, M any, PM interface {
	*M
	Mutation
}](ctx context.Context, exec func(context.Context) (V, error), mutation PM, hooks []Hook) (value V, err error) {
	if len(hooks) == 0 {
		return exec(ctx)
	}
	var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
		mutationT, ok := any(m).(PM)
		if !ok {
			return nil, fmt.Errorf("unexpected mutation type %T", m)
		}
		// Set the mutation to the builder.
		*mutation = *mutationT
		return exec(ctx)
	})
	for i := len(hooks) - 1; i >= 0; i-- {
		if hooks[i] == nil {
			return value, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
		}
		mut = hooks[i](mut)
	}
	v, err := mut.Mutate(ctx, mutation)
	if err != nil {
		return value, err
	}
	nv, ok := v.(V)
	if !ok {
		return value, fmt.Errorf("unexpected node type %T returned from %T", v, mutation)
	}
	return nv, nil
}

What did you see happen?

When I run gotext update I receive the following error:

panic: in ent.withHooks$1: cannot convert *t0 (M) to PM

goroutine 8095 [running]:
golang.org/x/tools/go/ssa.emitConv(0x140aebe5c80, {0x1032f4728, 0x140aee46660}, {0x1032f0980, 0x14061175800})
        /Users/username/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/emit.go:286 +0x9e4
golang.org/x/tools/go/ssa.emitStore(0x140aebe5c80, {0x1032f4728, 0x140aee465a0}, {0x1032f4728, 0x140aee46660}, 0x15be1eb)
        /Users/username/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/emit.go:377 +0x58
golang.org/x/tools/go/ssa.(*address).store(0x140aee39320, 0x140aebe5c80, {0x1032f4728?, 0x140aee46660?})
        /Users/username/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/lvalue.go:40 +0x4c
golang.org/x/tools/go/ssa.(*storebuf).emit(...)
        /Users/username/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:533
golang.org/x/tools/go/ssa.(*builder).assignStmt(0x140a62b7dd8, 0x140aebe5c80, {0x1401b0ae890, 0x1, 0x140aee42d10?}, {0x1401b0ae8a0, 0x1, 0x140aee39f80?}, 0x0)
        /Users/username/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:1207 +0x34c
golang.org/x/tools/go/ssa.(*builder).stmt(0x140a62b7dd8, 0x140aebe5c80, {0x1032f1548?, 0x1400989b9c0?})
        /Users/username/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:2181 +0x8b4
golang.org/x/tools/go/ssa.(*builder).stmtList(...)
        /Users/username/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:946
golang.org/x/tools/go/ssa.(*builder).stmt(0x140a62b7dd8, 0x140aebe5c80, {0x1032f1458?, 0x1401b08d200?})
        /Users/username/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:2277 +0xbf0
golang.org/x/tools/go/ssa.(*builder).buildFunctionBody(0x140a62b7dd8, 0x140aebe5c80)
        /Users/username/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:2391 +0x360
golang.org/x/tools/go/ssa.(*builder).expr0(0x140a62b7dd8, 0x1403e172f00, {0x1032f1878?, 0x1401b0ae8d0}, {0x7, {0x1032f0a70, 0x140679ca640}, {0x0, 0x0}})
        /Users/username/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:656 +0xaa8
golang.org/x/tools/go/ssa.(*builder).expr(0x140a62b7dd8, 0x1403e172f00, {0x1032f1878, 0x1401b0ae8d0})
        /Users/username/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:625 +0x11c
golang.org/x/tools/go/ssa.(*builder).expr0(0x140a62b7dd8, 0x1403e172f00, {0x1032f12d8?, 0x1400989bb40}, {0x7, {0x1032f0930, 0x1402d9a4d90}, {0x0, 0x0}})
        /Users/username/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:676 +0xf4
golang.org/x/tools/go/ssa.(*builder).expr(0x140a62b7dd8, 0x1403e172f00, {0x1032f12d8, 0x1400989bb40})
        /Users/username/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:625 +0x11c
golang.org/x/tools/go/ssa.(*builder).assign(0x140a62b7dd8?, 0x1403e172f00, {0x1032f20b0, 0x140aee39080}, {0x1032f12d8?, 0x1400989bb40?}, 0x8?, 0x0)
        /Users/username/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:598 +0x30c
golang.org/x/tools/go/ssa.(*builder).localValueSpec(0x140a62b7dd8, 0x1403e172f00, 0x1401abea960)
        /Users/username/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:1147 +0xc4
golang.org/x/tools/go/ssa.(*builder).stmt(0x140a62b7dd8, 0x1403e172f00, {0x1032f1398?, 0x1401b0ae910?})
        /Users/username/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:2147 +0xc48
golang.org/x/tools/go/ssa.(*builder).stmtList(...)
        /Users/username/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:946
golang.org/x/tools/go/ssa.(*builder).stmt(0x140a62b7dd8, 0x1403e172f00, {0x1032f1458?, 0x1401b08d440?})
        /Users/username/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:2277 +0xbf0
golang.org/x/tools/go/ssa.(*builder).buildFunctionBody(0x140a62b7dd8, 0x1403e172f00)
        /Users/username/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:2391 +0x360
golang.org/x/tools/go/ssa.(*builder).buildFunction(0x103071ce0?, 0x1403e172f00)
        /Users/username/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:2326 +0x30
golang.org/x/tools/go/ssa.(*builder).buildCreated(0x140a62b7dd8)
        /Users/username/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:2413 +0x2c
golang.org/x/tools/go/ssa.(*Package).build(0x1405154b580)
        /Users/username/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:2606 +0xa10
sync.(*Once).doSlow(0x343231202c353232?, 0x2c34343231202c30?)
        /opt/homebrew/opt/go/libexec/src/sync/once.go:74 +0x100
sync.(*Once).Do(...)
        /opt/homebrew/opt/go/libexec/src/sync/once.go:65
golang.org/x/tools/go/ssa.(*Package).Build(...)
        /Users/username/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:2477
golang.org/x/tools/go/ssa.(*Program).Build.func1(0x202c36373231202c?)
        /Users/username/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:2462 +0x54
created by golang.org/x/tools/go/ssa.(*Program).Build in goroutine 1
        /Users/username/go/pkg/mod/golang.org/x/tools@v0.6.0/go/ssa/builder.go:2461 +0x170

What did you expect to see?

Translation messages should generate successfully

@gopherbot gopherbot added this to the Unreleased milestone May 19, 2024
@seankhliao
Copy link
Member

What version of gotext?
Also, please provide a complete reproducer, your fragment is missing many type definitions.

@seankhliao seankhliao added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label May 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants