Skip to content
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

x/tools/gopls: Completion: "ZeroString for unexpected type" panic #70744

Closed
adonovan opened this issue Dec 9, 2024 · 3 comments
Closed

x/tools/gopls: Completion: "ZeroString for unexpected type" panic #70744

adonovan opened this issue Dec 9, 2024 · 3 comments
Assignees
Labels
gopls/telemetry-wins gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@adonovan
Copy link
Member

adonovan commented Dec 9, 2024

#!stacks
"runtime.gopanic" && "ZeroString:+15"

Issue created by stacks.

Looks like an untyped or invalid BasicType:

func ZeroString(t types.Type, qf types.Qualifier) string {
	switch t := t.(type) {
	case *types.Basic:
		switch {
		case t.Info()&types.IsBoolean != 0:
			return "false"
		case t.Info()&types.IsNumeric != 0:
			return "0"
		case t.Info()&types.IsString != 0:
			return `""`
		case t.Kind() == types.UnsafePointer:
			fallthrough
		case t.Kind() == types.UntypedNil:
			return "nil"
		default:
			panic(fmt.Sprint("ZeroString for unexpected type:", t))
		}

This stack A4anUg was reported by telemetry:

golang.org/x/tools/gopls@v0.17.0-pre.3 go1.23.3 linux/amd64 other,vscode (3)
@adonovan adonovan added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. gopls/telemetry-wins labels Dec 9, 2024
@gopherbot gopherbot added this to the Unreleased milestone Dec 9, 2024
@adonovan adonovan modified the milestones: Unreleased, gopls/v0.17.0 Dec 9, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/634923 mentions this issue: internal/typesinternal: rollback of Zero{Value,Expr} for gopls

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/635215 mentions this issue: [gopls-release-branch.0.17] internal/typesinternal: rollback of Zero{Value,Expr} for gopls

gopherbot pushed a commit to golang/tools that referenced this issue Dec 11, 2024
…Value,Expr} for gopls

In CL 626537, the gopls behavior of formatting or generating a type
expression for the zero value of a types.Type was changed to panic in
the presence of invalid types. This leads to multiple panics in gopls
(see tests). Fix by selectively rolling back this aspect of the change,
as it relates to gopls.

Also, add back the replace directive for the release branch.

Fixes golang/go#70744

Change-Id: Ife9ae9a0fedf5a9d6b321cfb959f0d16eeec2986
Reviewed-on: https://go-review.googlesource.com/c/tools/+/634923
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
(cherry picked from commit 82b6f75)
Reviewed-on: https://go-review.googlesource.com/c/tools/+/635215
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
gopls/telemetry-wins gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants