Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ and adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- In Go, a call through a variable that holds the result of a type assertion, like `st.Fetch(key)` after `st := v.(storage.Store)` or `rc.Read(p)` after `rc, ok := v.(ReadCloser)`, now links to that method of the asserted type, as a call made through the assertion itself does, including one the type gets from a struct or interface it embeds, and to nothing when the type comes from outside your project. Before, such a call linked to whichever method shared the name or to nothing, and a variable named like a standard-library package, like grpc-go's `parser, ok := builder.(balancer.ConfigParser)`, was taken for that package. Re-index Go projects after upgrading.
- In Go, a method called on an element of a slice, array or map, like kubectl's `schemas[ix].ValidateBytes(data)`, `pods[i].DeepCopy()`, `m.Items[len(m.Items)-1].Unmarshal(…)` in generated protobuf code or `(*in)[i].DeepCopyInto(&(*out)[i])` in every deepcopy file, now links to that method of the element's type. The type is read from what is indexed: a parameter, a variable, a struct field or a named slice type like `type ConjunctiveSchema []Schema`, and an element held by pointer, like `[]*Item`, reaches `Item`'s methods. Before, such a call linked to whichever method shared its name, often one in an unrelated package, or to nothing when many types declare it, as with Kubernetes' `DeepCopyInto`. An element whose type comes from outside your project, like `[]*net.IPNet`, or is a built-in one like `[]error`, now links to nothing rather than to a project method of that name. Re-index Go projects after upgrading.
- In Go, a method called further along a chain now links to that method of the type the chain has reached, like `Where` and `First` in a GORM-generated query such as `query.Card.WithContext(ctx).Where(…).First()`, a method called on what a function returns, like the client from `store.New(…)`, or one called on a composite literal, like `GitOracle{}.Worktree()`. The type is read from a function's or method's results, a conversion, a literal or an embedded field. Before, such a call was matched by its method's name alone, so a query's `Where` linked to another table's query type, a literal's method to a type that only shares its name, and `time.Now().UTC().Format(…)` to the one project method named `Format`. A chain whose type comes from outside your project, or can't be worked out, now links to nothing rather than to a guess. Re-index Go projects after upgrading. Thanks @BX-D for the report and @inth3shadows for the extra cases. (#2543)
- In Go, a method called on a variable that holds what a call returns, like `r.Reset()` after `r := newRing()`, `v1.GET(…)` after `v1 := router.Group("/v1")`, `w.Stop()` after `w := NewWatcher()` from a dot-imported package, or the second value of `c, r := CreateTestContext(w)`, now links to that method of the type the call returns, and so does one called after a conversion, like `list.Usernames()` after `list := web.Users(names)`, or through a field that holds a function. A value of a type from outside your project, like `c, _ := net.Dial(…)`, an `*os.File` or an `http.Handler` a project function returns, now links to nothing instead of to a project method that only shares the name. Before, such calls were matched by the method's name alone, so etcd's `lg := s.Logger()` linked its `lg.Info(…)` calls to a project logger's `Info`, and prometheus's `NewWriteHandler(…)` results to the read handler's `ServeHTTP`. Re-index Go projects after upgrading. Thanks @danusha2345. (#1954)
- In Go, three kinds of call now link where Go says they go. A conversion like `Category(s)`, `(*Pair)(p)` or `model.Kind(3)` is recorded as a use of the type rather than a call to it or a new instance of it. A call in a package's external tests (`package a_test`) reaches the helper those tests declare, not a same-named one in `package a` beside them, which they can't see. And a function, method or type a package defines once per platform or build tag, like `sep` in `sep_unix.go` and `sep_other.go`, now links to the definition a default build on Linux uses, or the one for the platform the calling file is written for, like Windows code reaching the Windows definition. Before, the second and third picked whichever definition came first, so a Linux caller could reach the Windows or `!unix` code. Re-index Go projects after upgrading. Thanks @inth3shadows for the report. (#2581)
- In Go, a method a type declares in a file too large to index, like the `String`, `Marshal` and `Unmarshal` every Kubernetes API type has in `core/v1/generated.pb.go`, is no longer replaced by the method of that name a type it embeds has. Before, `pod.String()` on a `*v1.Pod` linked to `TypeMeta`'s `String`, a method the call never runs; it now links to nothing, since the pod's own method isn't in the graph. A method the type really gets from a type it embeds, like `GetName` from `ObjectMeta`, still links. Re-index Go projects after upgrading.
- In Go, calls into a module whose `go.mod` is not at the project root now resolve, whether it is a `server/` backend next to a `web/` frontend or one of several modules side by side as in etcd, so calls like `store.New()` and `s.db.CreateItem()` find their targets instead of being treated as calls into a third-party package. A name written through a package, like a `job.OPCommand` result type or a field of type `artifact.Manager`, now links to that package's symbol rather than a same-named one elsewhere, which also corrects links in projects with a single `go.mod`. Re-index Go projects after upgrading. Thanks @GoDiao for the report and @danusha2345 for the fix. (#2322)
Expand Down
3 changes: 2 additions & 1 deletion __tests__/go-chained-receivers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ func useLiteral() {
func main() { use(holder{}); useLiteral() }
`,
});
expect(callees(graph, 'use')).toEqual([]);
// A func-typed field's call gives the result its type declares: `h.get()` is an A.
expect(callees(graph, 'use')).toEqual(['calls method A::Run']);
expect(callees(graph, 'useLiteral')).toEqual([]);
});
});
Loading