Skip to content

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

New issue

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

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

Already on GitHub? # to your account

Closed
tux21b opened this issue Apr 25, 2022 · 6 comments
Closed

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

tux21b opened this issue Apr 25, 2022 · 6 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@tux21b
Copy link
Contributor

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 commented Apr 25, 2022

@rsc this is gotext issue 2/2

@cagedmantis
Copy link
Contributor

Also see #50558

@cagedmantis cagedmantis added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 28, 2022
@zpavlinovic
Copy link
Contributor

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 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?

@esote
Copy link

esote commented Nov 7, 2022

Can we get another release before closing this issue?

@tux21b x/text v0.3.8 and v0.4.0 have been released since your comment, is this issue good to close?

@tux21b
Copy link
Contributor Author

tux21b commented Nov 7, 2022

Ah, yes. Thanks for asking @esote. Everything is working fine now!

@tux21b tux21b closed this as completed Nov 7, 2022
@golang golang locked and limited conversation to collaborators Nov 7, 2023
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants