Skip to content
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

*Slice: don't mutate the underlying default value #1170

Merged
merged 1 commit into from Aug 26, 2020

Commits on Aug 5, 2020

  1. *Slice: don't mutate the underlying default value

    If the default value is present, we shouldn't mutate it. Appending slices
    as the code was before mutates the underlying value:
    
    package main
    
    import (
    	"fmt"
    )
    
    func main() {
    	slice := []string{"a", "b", "c"}
    
    	fmt.Println(append(slice[:1], slice[2:]...))
    	fmt.Println(slice)
    }
    ~ go run tester2.go
    [a c]
    [a c c]
    
    Let's fix this by creating and returning an entirely new slice.
    
    Closes urfave#1169
    
    Signed-off-by: Tycho Andersen <tycho@tycho.ws>
    tych0 committed Aug 5, 2020
    Copy the full SHA
    7c493f6 View commit details
    Browse the repository at this point in the history