From 6a641547f55bb0ba5b791673786edddd743c030d Mon Sep 17 00:00:00 2001 From: Rob Findley Date: Thu, 5 Mar 2020 12:43:50 -0500 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Rohan Challa --- internal/lsp/cache/snapshot.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/lsp/cache/snapshot.go b/internal/lsp/cache/snapshot.go index 35ae021162..3b0d71ccb0 100644 --- a/internal/lsp/cache/snapshot.go +++ b/internal/lsp/cache/snapshot.go @@ -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