-
Notifications
You must be signed in to change notification settings - Fork 17.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Help people debug this error: "arguments to copy must be slices or array pointers" #539
Labels
Comments
The copy built-in function is explained in detail, with examples, in §Copying slices, The Go Programming Language Specification. http://golang.org/doc/go_spec.html#Copying_slices One of the rules given in the specification is: "The built-in function copy copies array or slice elements from a source src to a destination dst ..." The error message "arguments to copy must be slices or array pointers" indicates that your code broke this rule. You did not provide an example of your failing code. []byte is a slice type. Therefore, your proposed error messsage, "argument 1 is invalid because it is a []byte which is not a slice or an array pointer," after substitution, would read, "argument 1 is invalid because it is a slice[sic] which is not a slice or an array pointer." |
Labels changed: added compilerbug. Owner changed to r...@golang.org. Status changed to Accepted. |
Sorry for not providing examples. Here is one: package main func main() { var a [4]byte var b [4]byte copy(a,b) // fails copy(&a,&b) // works } It may be obvious to a go expert that an array is not a slice or an array pointer, but it is not necessarily obvious to an inexperienced go developer. The language does so much to hide the difference between pointer and reference and array that the inexperienced developer may not realize what to do to solve the problem. That's why a hint from the compiler as to which arguments are causing the problem and what the incorrect type is would help the developer correct their code. |
This issue was closed by revision 07fc145. Status changed to Fixed. Merged into issue #-. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: