internal/lsp/cache: pass UsesCgo to go/types

In CL 229779 I enabled Cgo type checking for go/packages, but we don't
actually type check there. We need to enable it in our own type checking
too.

No test updates because the negative effects are relatively subtle and
caught by an upcoming regtest.

Change-Id: I31691d69eb104cdabfd4fbe0a14b1f3c9741eabb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/234102
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Heschi Kreinick 2020-05-14 16:53:46 -04:00
parent d0dc4d41b7
commit 7d3b6ebf13
1 changed files with 7 additions and 0 deletions

View File

@ -12,6 +12,7 @@ import (
"go/token"
"go/types"
"path"
"reflect"
"sort"
"strings"
"sync"
@ -401,6 +402,12 @@ func typeCheck(ctx context.Context, fset *token.FileSet, m *metadata, mode sourc
return depPkg.types, nil
}),
}
// We want to type check cgo code if go/types supports it.
// We passed TypecheckCgo to go/packages when we Loaded.
if usescgo := reflect.ValueOf(cfg).Elem().FieldByName("UsesCgo"); usescgo.IsValid() {
usescgo.SetBool(true)
}
check := types.NewChecker(cfg, fset, pkg.types, pkg.typesInfo)
// Type checking errors are handled via the config, so ignore them here.