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
Usually, you can use array[:] to create a slice from array. However this will not work if array is the return value of a function call (which is unaddressable). For example md5.Sum returns a [16]byte but hex.EncodeToString requires a []byte. Make [16]byte conversible to []byte will allow people to call hex.EncodeToString with result of md5.Sum without assigning the result to an immediate variable:
fmt.Println(hex.EncodeToString([]byte(md5.Sum([]byte("test"))))) // this is currently invalid
Proposed: if array is addressable, converting it to slice equals to array[:]. Otherwise the value of array is assigned to a new temporary variable x and x[:] is returned.
The text was updated successfully, but these errors were encountered:
Proposal Details
This will be the inverse of #46505
Usually, you can use
array[:]
to create a slice from array. However this will not work ifarray
is the return value of a function call (which is unaddressable). For example md5.Sum returns a [16]byte but hex.EncodeToString requires a []byte. Make [16]byte conversible to []byte will allow people to call hex.EncodeToString with result of md5.Sum without assigning the result to an immediate variable:Proposed: if
array
is addressable, converting it to slice equals toarray[:]
. Otherwise the value ofarray
is assigned to a new temporary variablex
andx[:]
is returned.The text was updated successfully, but these errors were encountered: