func is[T any](x any) bool { … } // TODO(adonovan): use go1.21's slices.Clone. func clone[T any](slice []T) []T { … } // TODO(adonovan): use go1.21's slices.Index. func index[T comparable](slice []T, x T) int { … } func btoi(b bool) int { … } func offsetOf(fset *token.FileSet, pos token.Pos) int { … } // objectKind returns an object's kind (e.g. var, func, const, typename). func objectKind(obj types.Object) string { … } // within reports whether pos is within the half-open interval [n.Pos, n.End). func within(pos token.Pos, n ast.Node) bool { … } // trivialConversion reports whether it is safe to omit the implicit // value-to-variable conversion that occurs in argument passing or // result return. The only case currently allowed is converting from // untyped constant to its default type (e.g. 0 to int). // // The reason for this check is that converting from A to B to C may // yield a different result than converting A directly to C: consider // 0 to int32 to any. // // trivialConversion under-approximates trivial conversions, as unfortunately // go/types does not record the type of an expression *before* it is implicitly // converted, and therefore it cannot distinguish typed constant // expressions from untyped constant expressions. For example, in the // expression `c + 2`, where c is a uint32 constant, trivialConversion does not // detect that the default type of this expression is actually uint32, not untyped // int. // // We could, of course, do better here by reverse engineering some of go/types' // constant handling. That may or may not be worthwhile. // // Example: in func f() int32 { return 0 }, // the type recorded for 0 is int32, not untyped int; // although it is Identical to the result var, // the conversion is non-trivial. func trivialConversion(fromValue constant.Value, from, to types.Type) bool { … } func checkInfoFields(info *types.Info) { … } func funcHasTypeParams(decl *ast.FuncDecl) bool { … } // intersects reports whether the maps' key sets intersect. func intersects[K comparable, T1, T2 any](x map[K]T1, y map[K]T2) bool { … } // convert returns syntax for the conversion T(x). func convert(T, x ast.Expr) *ast.CallExpr { … } // isPointer reports whether t's core type is a pointer. func isPointer(t types.Type) bool { … } // indirectSelection is like seln.Indirect() without bug #8353. func indirectSelection(seln *types.Selection) bool { … } // effectiveReceiver returns the effective type of the method // receiver after all implicit field selections (but not implicit * or // & operations) have been applied. // // The boolean indicates whether any implicit field selection was indirect. func effectiveReceiver(seln *types.Selection) (types.Type, bool) { … }