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: "missing" syntax errors? #44736

Closed
myitcv opened this issue Mar 2, 2021 · 4 comments
Closed

x/tools/gopls: "missing" syntax errors? #44736

myitcv opened this issue Mar 2, 2021 · 4 comments

Comments

@myitcv
Copy link
Member

@myitcv myitcv commented Mar 2, 2021

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

$ go version
go version devel +f0be3cc547 Thu Feb 18 04:30:23 2021 +0000 linux/amd64
$ go list -m golang.org/x/tools
golang.org/x/tools v0.1.1-0.20210219012152-f3748ed8ec89
$ go list -m golang.org/x/tools/gopls
golang.org/x/tools/gopls v0.0.0-20210219012152-f3748ed8ec89

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/myitcv/.cache/go-build"
GOENV="/home/myitcv/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/myitcv/gostuff/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/myitcv/gostuff"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/myitcv/gos"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/myitcv/gos/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel +f0be3cc547 Thu Feb 18 04:30:23 2021 +0000"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/myitcv/gostuff/src/github.com/myitcv/govim/go.mod"
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-build1715314577=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Start with

-- go.mod --
module blah.com

go 1.16
-- main.go --
package main

import "fmt"

func main() {
	asdf
	fmt.Printf("This is a test %v")
	fdas
}
-- other.go --
package main

//
  • Observe that you get the following diagnostics as expected:
PublishDiagnostics callback: &protocol.PublishDiagnosticsParams{
    URI:         "file:///home/myitcv/gostuff/src/github.com/myitcv/playground/main.go",
    Version:     0,
    Diagnostics: {
        {
            Range: protocol.Range{
                Start: protocol.Position{Line:0x5, Character:0x1},
                End:   protocol.Position{Line:0x5, Character:0x5},
            },
            Severity:           1,
            Code:               "UndeclaredName",
            CodeDescription:    &protocol.CodeDescription{Href:"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#UndeclaredName"},
            Source:             "compiler",
            Message:            "undeclared name: asdf",
            Tags:               nil,
            RelatedInformation: nil,
            Data:               nil,
        },
        {
            Range: protocol.Range{
                Start: protocol.Position{Line:0x7, Character:0x1},
                End:   protocol.Position{Line:0x7, Character:0x5},
            },
            Severity:           1,
            Code:               "UndeclaredName",
            CodeDescription:    &protocol.CodeDescription{Href:"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#UndeclaredName"},
            Source:             "compiler",
            Message:            "undeclared name: fdas",
            Tags:               nil,
            RelatedInformation: nil,
            Data:               nil,
        },
    },
}
  • Modify other.go as follows:
package main

asdf

What did you expect to see?

The diagnostics for main.go and other.go

What did you see instead?

Just the diagnostics for other.go. The main.go diagnostics disappear and only a diagnostic for other.go remains:

PublishDiagnostics callback: &protocol.PublishDiagnosticsParams{
    URI:         "file:///home/myitcv/gostuff/src/github.com/myitcv/playground/other.go",
    Version:     6,
    Diagnostics: {
        {
            Range: protocol.Range{
                Start: protocol.Position{Line:0x2, Character:0x0},
                End:   protocol.Position{Line:0x2, Character:0x0},
            },
            Severity:           1,
            Code:               nil,
            CodeDescription:    (*protocol.CodeDescription)(nil),
            Source:             "syntax",
            Message:            "expected declaration, found asdf",
            Tags:               nil,
            RelatedInformation: nil,
            Data:               nil,
        },
    },
}

I'm not sure whether this was an intentional change or not? Bisected to eb48d3f608bba06c3bb4f5627f9fc2562cc84dd2 in any case.

Log files:


cc @stamblerre

FYI @leitzler

@findleyr
Copy link
Contributor

@findleyr findleyr commented Mar 2, 2021

Thanks for this report as well. (FWIW, our govim CI did break last night, but we had not yet investigated)

Per my understanding this is a bug, not an intended change.

CC @heschik

@gopherbot
Copy link

@gopherbot gopherbot commented Mar 2, 2021

Change https://golang.org/cl/297870 mentions this issue: gopls/internal/regtest: add a failing test for issue 44736

@findleyr
Copy link
Contributor

@findleyr findleyr commented Mar 2, 2021

Ah, I was wrong. These errors are actually coming from the type checker (I should have spotted this immediately based on the diagnostic), so this is nominally an intended change, though perhaps we didn't consider this case carefully enough.

@gopherbot
Copy link

@gopherbot gopherbot commented Mar 2, 2021

Change https://golang.org/cl/297872 mentions this issue: internal/lsp/cache: don't suppress type errors on parse errors

gopherbot pushed a commit to golang/tools that referenced this issue Mar 2, 2021
For golang/go#44736

Change-Id: I5c7cb83365d3542bb4a7cc391a68039fe81cf862
Reviewed-on: https://go-review.googlesource.com/c/tools/+/297870
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants