]> Cypherpunks repositories - gostls13.git/commit
go/types: infer correct type for y in append(bytes, y...)
authorAlan Donovan <adonovan@google.com>
Fri, 18 Jul 2025 17:16:21 +0000 (13:16 -0400)
committerAlan Donovan <adonovan@google.com>
Fri, 18 Jul 2025 18:13:45 +0000 (11:13 -0700)
commit34b70684ba2fc8c5cba900e9abdfb874c1bd8c0e
tree193beb57fdcb7df07b64f3cdbd230a1719108125
parent66536242fce34787230c42078a7bbd373ef8dcb0
go/types: infer correct type for y in append(bytes, y...)

The type-checking logic for append has a special case for
append(bytes, s...) where the typeset for s contains string.
However, this case was triggering even when the typeset contained
only []byte, causing the creation of Signature types of the form
func([]byte, Y) []byte, with the variadic flag set, where Y
is the type of Y (e.g. a type parameter constrained to ~[]byte).
This is an illegal combination: a variadic signature's last
parameter must be a slice, or its typeset must contain string.
This caused x/tools/go/ssa to crash.

This CL narrows the special case to only typesets that contain
string, and adds a test for the inferred signature.
(There's little point in testing that a subsequent NewSignatureType
call would succeed, because the inferred type plainly has
no free type parameters.)

Fixes #73871

Change-Id: Id7641104133371dd6b0077f281cdaa9db84cc1c7
Reviewed-on: https://go-review.googlesource.com/c/go/+/688815
Reviewed-by: Mark Freeman <mark@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
src/cmd/compile/internal/types2/builtins.go
src/go/types/api_test.go
src/go/types/builtins.go