I don't known what the error comes from in your code but I do know that it is a result of trying to copy from one slice to another that overlap. Someone has a copy function that works in this cases (look at cashew)