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
go 1.3.1
http://play.golang.org/p/TgUG4cii2o
1. To prevent type error, is it possible add a check about this
func main() {
fruits := []string{"peach", "banana", "kiwi"}
fruits2 := make([]string, len(fruits))
copy(fruits2, fruits)
fmt.Println(fruits) // here is a type error, should be 2
fmt.Println("Origin:", fruits)
}
What happened?
What should have happened instead?
fruits2 declared(or assigned) and not used
Please provide any additional information below.
The text was updated successfully, but these errors were encountered:
fruits2 is used in line 10: `copy(fruits2, fruits)`.
As slices can share the backing array, the side effect of the copy could be what is
intended and the compiler has no way how to prove that in general case.
#WAI
The text was updated successfully, but these errors were encountered: