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

Syntax error with generics #3474

Closed
lcarva opened this issue Dec 13, 2022 · 7 comments
Closed

Syntax error with generics #3474

lcarva opened this issue Dec 13, 2022 · 7 comments

Comments

@lcarva
Copy link

lcarva commented Dec 13, 2022

What did you do? (required: The issue will be closed when not provided)

Edited this go file:

package main

func test[T any](s []T) {
}

func main() {
}

What did you expect to happen?

I expected no errors since this is valid syntax.

What happened instead?

The following error is displayed on save:

main.go|3 col 10| expected '(', found '['

Configuration (MUST fill this out):

vim-go version:

v1.26

vimrc you used to reproduce:

The bare minimum:

$ cat ~/.vimrc
execute pathogen#infect()

vim-go is the only plugin installed.

Vim version (first three lines from :version):

vim --version Output:

VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Dec 05 2022 00:00:00)
Included patches: 1-1006
Modified by [email protected]
Compiled by [email protected]
Huge version without GUI. Features included (+) or not (-):
+acl +file_in_path +mouse_urxvt -tag_any_white
+arabic +find_in_path +mouse_xterm -tcl
+autocmd +float +multi_byte +termguicolors
+autochdir +folding +multi_lang +terminal
-autoservername -footer -mzscheme +terminfo
-balloon_eval +fork() +netbeans_intg +termresponse
+balloon_eval_term +gettext +num64 +textobjects
-browse -hangul_input +packages +textprop
++builtin_terms +iconv +path_extra +timers
+byte_offset +insert_expand +perl/dyn +title
+channel +ipv6 +persistent_undo -toolbar
+cindent +job +popupwin +user_commands
-clientserver +jumplist +postscript +vartabs
-clipboard +keymap +printer +vertsplit
+cmdline_compl +lambda +profile +vim9script
+cmdline_hist +langmap -python +viminfo
+cmdline_info +libcall +python3/dyn +virtualedit
+comments +linebreak +quickfix +visual
+conceal +lispindent +reltime +visualextra
+cryptv +listcmds +rightleft +vreplace
+cscope +localmap +ruby/dyn +wildignore
+cursorbind +lua/dyn +scrollbind +wildmenu
+cursorshape +menu +signs +windows
+dialog_con +mksession +smartindent +writebackup
+diff +modify_fname +sodium -X11
+digraphs +mouse -sound -xfontset
-dnd -mouseshape +spell -xim
-ebcdic +mouse_dec +startuptime -xpm
+emacs_tags +mouse_gpm +statusline -xsmp
+eval -mouse_jsbterm -sun_workshop -xterm_clipboard
+ex_extra +mouse_netterm +syntax -xterm_save
+extra_search +mouse_sgr +tag_binary
-farsi -mouse_sysmouse -tag_old_static
system vimrc file: "/etc/vimrc"
user vimrc file: "$HOME/.vimrc"
2nd user vimrc file: "~/.vim/vimrc"
user exrc file: "$HOME/.exrc"
defaults file: "$VIMRUNTIME/defaults.vim"
fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -DSYS_VIMRC_FILE=/etc/vimrc -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc -Wl,--enable-new-dtags -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -Wl,-dT,/builddir/build/BUILD/vim90/.package_note-vim-9.0.1006-1.fc36.x86_64.ld -L/usr/local/lib -o vim -lm -lselinux -lncurses -lsodium -lacl -lattr -lgpm -Wl,--enable-new-dtags -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -fstack-protector-strong -L/usr/local/lib -L/usr/lib64/perl5/CORE -lperl -lpthread -lresolv -ldl -lm -lcrypt -lutil -lc

Go version (go version):

go version go1.18.8 linux/amd64

Go environment

go env Output:

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/lucarval/.cache/go-build"
GOENV="/home/lucarval/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/lucarval/gocode/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/lucarval/gocode"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/golang"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18.8"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/tmp/test/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2404005566=/tmp/go-build -gno-record-gcc-switches"

gopls version

gopls version Output:
golang.org/x/tools/gopls v0.7.5
    golang.org/x/tools/[email protected] h1:8Az52YwcFXTWPvrRomns1C0N+zlgTyyPKWvRazO9GG8=

@lcarva
Copy link
Author

lcarva commented Dec 13, 2022

Similar to #3398 but in my case I have no other plugin installed, so it's coming from vim-go.

@bhcleek
Copy link
Collaborator

bhcleek commented Dec 14, 2022

What does :!go version output?

@bhcleek
Copy link
Collaborator

bhcleek commented Dec 14, 2022

Oh, you're running a very old version of gopls, so I suspect that it's not been compiled with a recent version of Go that supports generics. Try :GoUpdateBinaries gopls. Can you duplicate the problem after updating gopls?

@gucio321
Copy link

Hi!
I'm getting the same error. GoUpdateBinaries gopls doesn't help.
gopls version is

[bin (2) ]$ gopls version
golang.org/x/tools/gopls v0.10.1
    golang.org/x/tools/[email protected] h1:JoHe17pdZ8Vsa24/GUO8iTVTKPh0EOBiWpPop7XJybI=

go version: go version go1.19.3 linux/amd64

@lcarva
Copy link
Author

lcarva commented Dec 14, 2022

I think there's something up with my setup. When I run :GoUpdateBinaries gopls, I get a bunch of errors like this:

vim-go: Error installing golang.org/x/tools/gopls@latest: golang.org/x/exp/constraints
vim-go: golang.org/x/exp/maps
vim-go: # golang.org/x/exp/constraints
vim-go: /home/lucarval/gocode/pkg/mod/golang.org/x/[email protected]/constraints/constraints.go:13:2: emb
edding interface element ~int|~int8|~int16|~int32|~int64 requires go1.18 or later (-lang was set to go1.16; check go.mod)
vim-go: /home/lucarval/gocode/pkg/mod/golang.org/x/[email protected]/constraints/constraints.go:20:2: emb
edding interface element ~uint|~uint8|~uint16|~uint32|~uint64|~uintptr requires go1.18 or later (-lang was set to go1.16; chec
k go.mod)
vim-go: /home/lucarval/gocode/pkg/mod/golang.org/x/[email protected]/constraints/constraints.go:27:2: emb
edding interface element Signed|Unsigned requires go1.18 or later (-lang was set to go1.16; check go.mod)

But the output of :!go version is:

go version go1.18.8 linux/amd64

Is it possible that vim-go is using a different golang binary? Not sure how to check this.

@lcarva
Copy link
Author

lcarva commented Dec 14, 2022

Ok, the :GoUpdateBinaries command still fails. However, I was able to get around this by running:

$ go install golang.org/x/tools/gopls@latest

which now shows:

$ gopls version
golang.org/x/tools/gopls v0.10.1
    golang.org/x/tools/[email protected] h1:JoHe17pdZ8Vsa24/GUO8iTVTKPh0EOBiWpPop7XJybI=

@lcarva
Copy link
Author

lcarva commented Dec 14, 2022

I narrowed down the problem to the use of -mod=readonly. I can reproduce the error I see when running :GoUpdateBinaries like this:

go install -v -mod=readonly golang.org/x/tools/gopls@latest

Removing -mod=readonly fixes the issue. I noticed that #3449 changes this to -mod=mod which also fixes the issue.

So I'm all set here if I use the master branch.

To summarize, the initial issue I reported was due to an outdated gopls version being used. Running :GoUpdateBinaries fixes it. However, :GoUpdateBinaries seems to be broken in version 1.26 but already fixed in master.

@bhcleek bhcleek closed this as completed Dec 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants