From dc038396d1f0c0a0a161c594201b868c8d35c8fe Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Mon, 4 Nov 2019 14:35:09 -0500 Subject: [PATCH] internal/lsp: add additional check for analysis value Updates golang/go#35339 Change-Id: Ie990672b619d1844f66abf62010fe9a69daf00d9 Reviewed-on: https://go-review.googlesource.com/c/tools/+/205161 Run-TryBot: Rebecca Stambler TryBot-Result: Gobot Gobot Reviewed-by: Ian Cottrell --- internal/lsp/cache/analysis.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/internal/lsp/cache/analysis.go b/internal/lsp/cache/analysis.go index 84f18159131..2adc23f8daa 100644 --- a/internal/lsp/cache/analysis.go +++ b/internal/lsp/cache/analysis.go @@ -131,8 +131,7 @@ func (s *snapshot) actionHandle(ctx context.Context, id packageID, mode source.P err: err, } } - data := runAnalysis(ctx, fset, a, pkg, results) - return data + return runAnalysis(ctx, fset, a, pkg, results) }) ah.handle = h @@ -145,7 +144,10 @@ func (act *actionHandle) analyze(ctx context.Context) ([]*source.Error, interfac if v == nil { return nil, nil, errors.Errorf("no analyses for %s", act.pkg.ID()) } - data := v.(*actionData) + data, ok := v.(*actionData) + if !ok { + return nil, nil, errors.Errorf("unexpected type for %s:%s", act.pkg.ID(), act.analyzer.Name) + } return data.diagnostics, data.result, data.err } @@ -154,7 +156,10 @@ func (act *actionHandle) cached() ([]*source.Error, interface{}, error) { if v == nil { return nil, nil, errors.Errorf("no analyses for %s", act.pkg.ID()) } - data := v.(*actionData) + data, ok := v.(*actionData) + if !ok { + return nil, nil, errors.Errorf("unexpected type for %s:%s", act.pkg.ID(), act.analyzer.Name) + } return data.diagnostics, data.result, data.err }