You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
in Fn2, info.ObjectOf(Fn1) will return the parameterized Fn1. info.Instances[Fn1] will give us the type argument (int) and the resulting signature (func(int)) but no types.Object for this instantiation. It is essentially an anonymous function.
This is problematic for unused, because unused's graph consists of values from the go/types type system (so that we can serialize it and only need type information, not the IR).
Consider this example, which leads to a false negative:
In go/ir, we have three functions: Fn, uncalled, and a wrapper that calls Fn generically, with the type argument c1. But because we have no types.Object for the instance, the wrapper's Object is Fn. Thus, when we analyze the wrapper and see the use of c1, we associate that use with Fn, not with the wrapper. Thus, even though uncalled is unused, and Fn is never instantiated with c1, we still consider c1 used, because Fn is exported, and thus used.
We end up with the following graph, where the node (*types.Func) func command-line-arguments.Fn6[T any]() contains edges for both Fn and the wrapper representing Fn[c1].
In go/types, instantiated functions do not have an associated
types.Object
. Forin
Fn2
,info.ObjectOf(Fn1)
will return the parameterizedFn1
.info.Instances[Fn1]
will give us the type argument (int
) and the resulting signature (func(int)
) but notypes.Object
for this instantiation. It is essentially an anonymous function.This is problematic for
unused
, because unused's graph consists of values from the go/types type system (so that we can serialize it and only need type information, not the IR).Consider this example, which leads to a false negative:
In
go/ir
, we have three functions:Fn
,uncalled
, and a wrapper that callsFn
generically, with the type argumentc1
. But because we have no types.Object for the instance, the wrapper's Object isFn
. Thus, when we analyze the wrapper and see the use ofc1
, we associate that use withFn
, not with the wrapper. Thus, even thoughuncalled
is unused, andFn
is never instantiated withc1
, we still considerc1
used, becauseFn
is exported, and thus used.We end up with the following graph, where the node
(*types.Func) func command-line-arguments.Fn6[T any]()
contains edges for bothFn
and the wrapper representingFn[c1]
.The text was updated successfully, but these errors were encountered: