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/tools/gopls: struct filling breaks with generic items #54836

Closed
not-rusty opened this issue Sep 2, 2022 · 3 comments
Closed

x/tools/gopls: struct filling breaks with generic items #54836

not-rusty opened this issue Sep 2, 2022 · 3 comments
Assignees
Labels
FeatureRequest 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.

Comments

@not-rusty
Copy link

not-rusty commented Sep 2, 2022

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

$ go version
go version go1.19 linux/amd64
$ gopls version
golang.org/x/tools/gopls v0.9.4
    golang.org/x/tools/gopls@v0.9.4 h1:YhHOxVi++ILnY+QnH9FGtRKZZrunSaR7OW8/dCp7bBk=

Does this issue reproduce with the latest release?

Yes

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

GOHOSTARCH="amd64"
GOHOSTOS="linux"

What did you do?

Open a main.go file and try autofilling these structs:

package main

type GenericUser[T any] struct {
	Name  string
	Age   int
	Value T
}

type StructUsingAGeneric struct {
	User GenericUser[string]
	Age  int
}

func main() {
	// Fill anonymous struct breaks here.
	_ = GenericUser[string]{
	}

	// Here it isn't even an option.
	_ = StructUsingAGeneric{
		
	}
}

What did you expect to see?

I did expect gopls to autofill these structs without problem when the generic type is provided.

package main

type GenericUser[T any] struct {
	Name  string
	Age   int
	Value T
}

type StructUsingAGeneric struct {
	User GenericUser[string]
	Age  int
}

func main() {
	// Fill anonymous struct breaks here.
	_ = GenericUser[string]{
		Age: 0,
		Value: "",
	}

	// Here it isn't even an option.
	_ = StructUsingAGeneric{
		User: GenericUser[string]{},
		Age: 0,
	}
}

What did you see instead?

Error on the first case in my lsp client, no action suggested in the other case.

@not-rusty not-rusty changed the title affected/package: gopls struct filling breaks with generic items. golang.org/x/tools/gopls: gopls struct filling breaks with generic items. Sep 2, 2022
@gopherbot gopherbot added the gopls Issues related to the Go language server, gopls. label Sep 2, 2022
@not-rusty not-rusty changed the title golang.org/x/tools/gopls: gopls struct filling breaks with generic items. golang.org/x/tools/gopls: struct filling breaks with generic items Sep 2, 2022
@seankhliao seankhliao changed the title golang.org/x/tools/gopls: struct filling breaks with generic items x/tools/gopls: struct filling breaks with generic items Sep 2, 2022
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Sep 2, 2022
@gopherbot gopherbot added this to the Unreleased milestone Sep 2, 2022
@adonovan
Copy link
Member

adonovan commented Sep 8, 2022

The GenericUser example works for me (when I add a test case for it). But the lack of support for fields that contain type parameters appears to be a known limitation of the current information:

https://cs.opensource.google/go/x/tools/+/master:gopls/internal/lsp/analysis/fillstruct/fillstruct.go;l=100-101?q=ignore.*for.now%20&ss=go%2Fx%2Ftools

@adonovan adonovan added the NeedsFix The path to resolution is known, but the work has not been done. label Sep 8, 2022
@dle8 dle8 added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 16, 2022
@gopherbot gopherbot removed the NeedsFix The path to resolution is known, but the work has not been done. label Sep 16, 2022
@hyangah hyangah modified the milestones: Unreleased, gopls/unplanned Sep 23, 2022
@findleyr
Copy link
Contributor

findleyr commented Sep 29, 2022

There's still action to take here: either make it work, or don't suggest struct filling if it is known to not work.

@gopherbot
Copy link

gopherbot commented Sep 29, 2022

Change https://go.dev/cl/436777 mentions this issue: gopls/.../fillstruct: support generic types

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest 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

6 participants