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

some number literals forms introduced in Go 1.13 do not highlight correctly #3430

Closed
sedyh opened this issue Jul 14, 2022 · 1 comment · Fixed by #3440
Closed

some number literals forms introduced in Go 1.13 do not highlight correctly #3430

sedyh opened this issue Jul 14, 2022 · 1 comment · Fixed by #3440

Comments

@sedyh
Copy link

sedyh commented Jul 14, 2022

What did you expect to happen?

That the plugin will highlight all number literals.
The full list of literals is taken from here.

What happened instead?

The plugin does not highlight some valid number literals in Go.
All listed numbers below should be highlighted:

image

Configuration:

vim-go version: v1.26

vimrc you used to reproduce:

call plug#begin()
Plug 'fatih/vim-go', {'do': ':GoUpdateBinaries'}
call plug#end()

nnoremap <C-Left> :tabprevious<CR>
nnoremap <C-Right> :tabnext<CR>

Vim version (first three lines from :version):

VIM - Vi IMproved 8.1 (2018 May 18, compiled Feb 01 2022 09:16:32)
Included patches: 1-2269, 3612, 3625, 3669, 3741
Modified by [email protected]

Go version (go version):

go version go1.19beta1 linux/amd64

Go environment

go env Output:
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/sedyh/.cache/go-build"
GOENV="/home/sedyh/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/sedyh/.local/share/go/path-workspace/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/sedyh/.local/share/go/path-workspace"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/sedyh/.local/share/go/root-sdk/go1.19beta1"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/sedyh/.local/share/go/root-sdk/go1.19beta1/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19beta1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3452671431=/tmp/go-build -gno-record-gcc-switches"

gopls version

gopls version Output:
golang.org/x/tools/gopls v0.9.1
    golang.org/x/tools/[email protected] h1:SigsTL4Hpv3a6b/a7oPCLRv5QUeSM6PZNdta1oKY4B0=
@bhcleek
Copy link
Collaborator

bhcleek commented Jul 14, 2022

The problems here are with a few specific and odd scenarios for number literals that were released in Go 1.13

  1. non-decimal floating point representations (e.g. 0010e-2, 0x1p, etc.)
  2. non-decimal imaginary number representations (e.g. 0x11i).

Here's a useful code block to demonstrate the highlighting:

_ = 1.23
_ = 01.23 // == 1.23
_ = .23
_ = 1.
// An "e" or "E" starts the exponent part (10-based).
_ = 1.23e2  // == 123.0
_ = 123E2   // == 12300.0
_ = 123.E+2 // == 12300.0
_ = 1e-1    // == 0.1
_ = .1e0    // == 0.1
_ = 0010e-2 // == 0.1
_ = 0e+5    // == 0.0

_ = 0x1p-2     // == 1.0/4 = 0.25
_ = 0x2.p10    // == 2.0 * 1024 == 2048.0
_ = 0x1.Fp+0   // == 1+15.0/16 == 1.9375
_ = 0X.8p1     // == 8.0/16 * 2 == 1.0
_ = 0X1FFFP-16 // == 0.1249847412109375

_ = 1.23i
_ = 1.i
_ = .23i
_ = 123i
_ = 0123i   // == 123i (for backward-compatibility. See below.)
_ = 1.23E2i // == 123i
_ = 1e-1i
_ = 011i   // == 11i (for backward-compatibility. See below.)
_ = 00011i // == 11i (for backward-compatibility. See below.)

// The following lines only compile okay since Go 1.13.
_ = 0o11i    // == 9i
_ = 0x11i    // == 17i
_ = 0b11i    // == 3i
_ = 0X.8p-0i // == 0.5i

_ = 1 + 2i       // == 1.0 + 2.0i
_ = 1. - .1i     // == 1.0 + -0.1i
_ = 1.23i - 7.89 // == -7.89 + 1.23i
_ = 1.23i        // == 0.0 + 1.23i

_ = 6_9          // == 69
_ = 0_33_77_22   // == 0337722
_ = 0x_Bad_Face  // == 0xBadFace
_ = 0X_1F_FFP-16 // == 0X1FFFP-16
_ = 0b1011_0111 + 0xA_B.Fp2i

@bhcleek bhcleek changed the title Incorrect highlighting of number literals some number literals forms introduced in Go 1.13 do not highlight correctly Jul 14, 2022
bhcleek added a commit to bhcleek/vim-go that referenced this issue Aug 8, 2022
* Add tests for float and imaginary matches.
* Match floats that start with or end with a decimal point with no
  digits preceding or following, respectively.
* Match hexadecimal floats.
* Match imaginary binary, octal, and hexadecimal numbers.

Fixes fatih#3430
bhcleek added a commit to bhcleek/vim-go that referenced this issue Aug 8, 2022
* Add tests for float and imaginary matches.
* Match floats that start with or end with a decimal point with no
  digits preceding or following, respectively.
* Match hexadecimal floats.
* Match imaginary binary, octal, and hexadecimal numbers.

Fixes fatih#3430
bhcleek added a commit to bhcleek/vim-go that referenced this issue Aug 8, 2022
* Add tests for float and imaginary matches.
* Match floats that start with or end with a decimal point with no
  digits preceding or following, respectively.
* Match hexadecimal floats.
* Match imaginary binary, octal, and hexadecimal numbers.

Fixes fatih#3430
bhcleek added a commit to bhcleek/vim-go that referenced this issue Aug 8, 2022
* Add tests for float and imaginary matches.
* Match floats that start with or end with a decimal point with no
  digits preceding or following, respectively.
* Match hexadecimal floats.
* Match imaginary binary, octal, and hexadecimal numbers.

Fixes fatih#3430
mjolk pushed a commit to mjolk/vim-go that referenced this issue Oct 4, 2022
* Add tests for float and imaginary matches.
* Match floats that start with or end with a decimal point with no
  digits preceding or following, respectively.
* Match hexadecimal floats.
* Match imaginary binary, octal, and hexadecimal numbers.

Fixes fatih#3430
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

Successfully merging a pull request may close this issue.

2 participants