golang.org/x/tools/gopls@v0.15.3/internal/test/marker/testdata/completion/issue51783.txt (about) 1 Regression test for "completion gives unneeded generic type 2 instantiation snippet", #51783. 3 4 Type parameters that can be inferred from the arguments 5 are not part of the offered completion snippet. 6 7 -- flags -- 8 -ignore_extra_diags 9 10 -- a.go -- 11 package a 12 13 // identity has a single simple type parameter. 14 // The completion omits the instantiation. 15 func identity[T any](x T) T 16 17 // clone has a second type parameter that is nonetheless constrained by the parameter. 18 // The completion omits the instantiation. 19 func clone[S ~[]E, E any](s S) S 20 21 // unconstrained has a type parameter constrained only by the result. 22 // The completion suggests instantiation. 23 func unconstrained[X, Y any](x X) Y 24 25 // partial has three type parameters, 26 // only the last two of which may be omitted as they 27 // are constrained by the arguments. 28 func partial[R any, S ~[]E, E any](s S) R 29 30 //@item(identity, "identity", "details", "kind") 31 //@item(clone, "clone", "details", "kind") 32 //@item(unconstrained, "unconstrained", "details", "kind") 33 //@item(partial, "partial", "details", "kind") 34 35 func _() { 36 _ = identity //@snippet("identity", identity, "identity(${1:})") 37 38 _ = clone //@snippet("clone", clone, "clone(${1:})") 39 40 _ = unconstrained //@snippet("unconstrained", unconstrained, "unconstrained[${1:}](${2:})") 41 42 _ = partial //@snippet("partial", partial, "partial[${1:}](${2:})") 43 44 // Result-type inference permits us to omit Y in this (rare) case, 45 // but completion doesn't support that. 46 var _ int = unconstrained //@snippet("unconstrained", unconstrained, "unconstrained[${1:}](${2:})") 47 }