1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:04:44 -07:00

internal/lsp/cache: fix NPE in fileWasSaved

Reading the docstring, it looks like the sense of the type assertion was
accidentally inverted in this function. Fix it to what I believe was
intended.

Fixes golang/go#37687

Change-Id: Ief44a996f1a262527c2916d6b78b81dd35b2cf9e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/222217
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rohan Challa <rohan@golang.org>
This commit is contained in:
Rob Findley 2020-03-05 12:43:50 -05:00 committed by Robert Findley
parent d7d4448666
commit 6a641547f5

View File

@ -787,20 +787,20 @@ outer:
return result
}
// fileWasSaved returns true if the FileHandle passed in has been saved.
// It accomplishes this by checking to see if the original and current FileHandles
// are both overlays, and if the current FileHandles is saved while the original FileHandle
// was not saved.
// fileWasSaved reports whether the FileHandle passed in has been saved. It
// accomplishes this by checking to see if the original and current FileHandles
// are both overlays, and if the current FileHandle is saved while the original
// FileHandle was not saved.
func fileWasSaved(originalFH, currentFH source.FileHandle) bool {
c, ok := currentFH.(*overlay)
if ok {
if !ok || c == nil {
return true
}
if originalFH == nil {
o, ok := originalFH.(*overlay)
if !ok || o == nil {
return c.saved
}
o, ok := originalFH.(*overlay)
return ok && !o.saved && c.saved
return !o.saved && c.saved
}
// shouldInvalidateMetadata reparses a file's package and import declarations to