x/tools/gopls: Implement interface methods cannot handle type if it was defined inside type() #56825
Labels
FrozenDueToAge
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
gopls version
:!gopls -v version [No write since last change] Build info ---------- golang.org/x/tools/gopls v0.10.1 golang.org/x/tools/gopls@v0.10.1 h1:JoHe17pdZ8Vsa24/GUO8iTVTKPh0EOBiWpPop7XJybI= github.com/BurntSushi/toml@v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0= github.com/google/go-cmp@v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= golang.org/x/exp@v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA= golang.org/x/exp/typeparams@v0.0.0-20220722155223-a9213eeb770e h1:7Xs2YCOpMlNqSQSmrrnhlzBXIE/bpMecZplbLePTJvE= golang.org/x/mod@v0.6.0 h1:b9gGHsz9/HhJ3HF5DHQytPpuwocVTChQJK3AvoLRD5I= golang.org/x/sync@v0.0.0-20220722155255-886fb9371eb4 h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw= golang.org/x/sys@v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= golang.org/x/text@v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg= golang.org/x/tools@v0.2.1-0.20221101170700-b5bc717366b2 h1:KBm+UwBaO/tdQ35tfGvxH1FUCiXRg4MoTzkznsdeab8= golang.org/x/vuln@v0.0.0-20221010193109-563322be2ea9 h1:KaYZQUtEEaV8aVADIHAuYBTjo77aUcCvC7KTGKM3J1I= honnef.co/go/tools@v0.3.3 h1:oDx7VAwstgpYpb3wv0oxiZlxY+foCpRAwY7Vk6XpAgA= mvdan.cc/gofumpt@v0.3.1 h1:avhhrOmv0IuvQVK7fvwV91oFSGAk5/6Po8GXTzICeu8= mvdan.cc/xurls/v2@v2.4.0 h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc= go: go1.19.2
go env
What did you do?
Wrote some code that I then wanted to generate stubs for a struct to impl an interface.
What did you expect to see?
B
onA
with the methods inserted AFTER the type() closure. I actually assumed this would create methods after the current closure i happen to be in that is part global package scope. Then because the methods are inserted right next to where my cursor/file i am viewing is, I can cut/copy them to where I need.What did you see instead?
When accepting to run the code action for implementing method stubs for the interface it fails with an error similar to.... Which is very confusing and makes no real mention or reference to the problem. Especially since we're not in a
func
or have one at the referenced line.gopls: 0: could not reparse file: main:#LINENO:1: expected 'IDENT', found 'func' (and #ERRS more errors)
with the #LINENO referencing the line after the type definition for the struct
(A)
we are trying to generate stubs for.There is also no file name listed.
If you have multiple files in the same package and the struct is in another file this error is useless.The #ERRS I am unsure of what additional issues it is complaining about, but irrelevant to the issue/solution.
Simply moving the type definition for the struct we want to generate stub methods for outside of the type() closure resolves the issue. It would seem the stubs are generated under the struct's definition expecting them to be in the global/outside any closure.
Editor and settings
Neovim v0.9.0-dev
All analyses and hints enabled through gopls.
Logs
THX U! I have struggled with this error for months only having recently spent a few hours to investigate why some types wouldn't work with this.
The text was updated successfully, but these errors were encountered: