Skip to content

Commit

Permalink
internal/lsp/cache: add missing error checks
Browse files Browse the repository at this point in the history
I wrote this code as if there was going to be a final error check after
all the type checking attempts, but ended up using the result inside the
attempts, errors would likely have resulted in panics. Just do normal,
non-clever error checking.

Change-Id: I665f34f7e6d1a2c3465543cbdc39a723a22a1095
Reviewed-on: https://go-review.googlesource.com/c/tools/+/319371
Trust: Heschi Kreinick <[email protected]>
Run-TryBot: Heschi Kreinick <[email protected]>
gopls-CI: kokoro <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Reviewed-by: Rebecca Stambler <[email protected]>
  • Loading branch information
heschi committed May 12, 2021
1 parent be4aaae commit 9dfac01
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions internal/lsp/cache/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,11 @@ func (s *snapshot) parseGoHandles(ctx context.Context, files []span.URI, mode so
}

func typeCheck(ctx context.Context, snapshot *snapshot, m *metadata, mode source.ParseMode, deps map[packagePath]*packageHandle) (*pkg, error) {
var pkg *pkg
var err error

var filter *unexportedFilter
if mode == source.ParseExported {
filter = &unexportedFilter{uses: map[string]bool{}}
}
pkg, err = doTypeCheck(ctx, snapshot, m, mode, deps, filter)
pkg, err := doTypeCheck(ctx, snapshot, m, mode, deps, filter)
if err != nil {
return nil, err
}
Expand All @@ -322,11 +319,17 @@ func typeCheck(ctx context.Context, snapshot *snapshot, m *metadata, mode source
if len(unexpected) == 0 && len(missing) != 0 {
event.Log(ctx, fmt.Sprintf("discovered missing identifiers: %v", missing), tag.Package.Of(string(m.id)))
pkg, err = doTypeCheck(ctx, snapshot, m, mode, deps, filter)
if err != nil {
return nil, err
}
missing, unexpected = filter.ProcessErrors(pkg.typeErrors)
}
if len(unexpected) != 0 || len(missing) != 0 {
event.Log(ctx, fmt.Sprintf("falling back to safe trimming due to type errors: %v or still-missing identifiers: %v", unexpected, missing), tag.Package.Of(string(m.id)))
pkg, err = doTypeCheck(ctx, snapshot, m, mode, deps, nil)
if err != nil {
return nil, err
}
}
}

Expand Down

0 comments on commit 9dfac01

Please sign in to comment.