From 7d3b6ebf133df879df3e448a8625b7029daa8954 Mon Sep 17 00:00:00 2001 From: Heschi Kreinick Date: Thu, 14 May 2020 16:53:46 -0400 Subject: [PATCH] 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 Reviewed-by: Rebecca Stambler TryBot-Result: Gobot Gobot --- internal/lsp/cache/check.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/internal/lsp/cache/check.go b/internal/lsp/cache/check.go index 6d16b319d1..166d1a64e7 100644 --- a/internal/lsp/cache/check.go +++ b/internal/lsp/cache/check.go @@ -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.