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 #52553

Open
tux21b opened this issue Apr 25, 2022 · 4 comments
Open

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

tux21b opened this issue Apr 25, 2022 · 4 comments
Labels
NeedsInvestigation
Milestone

Comments

@tux21b
Copy link
Contributor

@tux21b tux21b commented Apr 25, 2022

The following minimal example produces an error with Go 1.18.1:

package main

import (
	"fmt"

	"golang.org/x/text/language"
	"golang.org/x/text/message"
)

func Print[T any](s T) {
	fmt.Println(s)
}

func main() {
	p := message.NewPrinter(language.English)
	Print(p.Sprintf("Hello World"))
}

Stacktrace:

❯ go run golang.org/x/text/cmd/gotext extract       
panic: T

goroutine 661 [running]:
golang.org/x/tools/go/ssa.(*Program).needMethods(0xc001659e10, {0x8d5e28?, 0xc007d56fc0?}, 0x0)
        /home/christoph/go/pkg/mod/golang.org/x/tools@v0.1.10/go/ssa/methods.go:237 +0x5b1
golang.org/x/tools/go/ssa.(*Program).needMethods(0xc001659e10, {0x8d5e00?, 0xc0045f6a50?}, 0x0)
        /home/christoph/go/pkg/mod/golang.org/x/tools@v0.1.10/go/ssa/methods.go:233 +0x708
golang.org/x/tools/go/ssa.(*Program).needMethods(0xc001659e10, {0x8d5d88?, 0xc0045fae00?}, 0x0)
        /home/christoph/go/pkg/mod/golang.org/x/tools@v0.1.10/go/ssa/methods.go:209 +0x448
golang.org/x/tools/go/ssa.(*Program).needMethodsOf(0xc001659e10, {0x8d5d88?, 0xc0045fae00?})
        /home/christoph/go/pkg/mod/golang.org/x/tools@v0.1.10/go/ssa/methods.go:145 +0x70
golang.org/x/tools/go/ssa.(*Package).build(0xc008ef0960)
        /home/christoph/go/pkg/mod/golang.org/x/tools@v0.1.10/go/ssa/builder.go:2284 +0x111
sync.(*Once).doSlow(0x628f00?, 0xc0026fb080?)
        /usr/lib/go/src/sync/once.go:68 +0xc2
sync.(*Once).Do(...)
        /usr/lib/go/src/sync/once.go:59
golang.org/x/tools/go/ssa.(*Package).Build(...)
        /home/christoph/go/pkg/mod/golang.org/x/tools@v0.1.10/go/ssa/builder.go:2272
golang.org/x/tools/go/ssa.(*Program).Build.func1(0x4d?)
        /home/christoph/go/pkg/mod/golang.org/x/tools@v0.1.10/go/ssa/builder.go:2256 +0x4c
created by golang.org/x/tools/go/ssa.(*Program).Build
        /home/christoph/go/pkg/mod/golang.org/x/tools@v0.1.10/go/ssa/builder.go:2255 +0x19c
exit status 2

The error itself seems to be related to this issue #48525. Please note that in order to trigger the error, one must manually update x/tools, otherwise another error is triggered. See #52552.

PS: and please ignore the misuse of generics in this example. I just needed some code that uses generics.

@gopherbot gopherbot added this to the Unreleased milestone Apr 25, 2022
@tux21b
Copy link
Contributor Author

@tux21b tux21b commented Apr 25, 2022

@rsc this is gotext issue 2/2

@cagedmantis
Copy link
Contributor

@cagedmantis cagedmantis commented Apr 28, 2022

Also see #50558

@cagedmantis cagedmantis added the NeedsInvestigation label Apr 28, 2022
@zpavlinovic
Copy link
Contributor

@zpavlinovic zpavlinovic commented May 13, 2022

Is this issue still present? It should go away with one of the newer versions of tools: https://github.com/golang/text/blob/master/go.mod

@tux21b
Copy link
Contributor Author

@tux21b tux21b commented May 13, 2022

It still does not work with the latest released version of /x/text (v0.3.7) and /x/tools (v0.1.10).

Updating /x/text to the latest commit on master (v0.3.8-0.20220509174342-b4bca84b0361, which also updates tools to v0.1.11-0.20220504162446-54c7ba520b92) seems to solve the problem. Can we get another release before closing this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation
Projects
None yet
Development

No branches or pull requests

4 participants