github.com/april1989/origin-go-tools@v0.0.32/refactor/eg/testdata/C1.go (about)

     1  // +build ignore
     2  
     3  package C1
     4  
     5  import "strings"
     6  
     7  func example() {
     8  	x := "foo"
     9  	println(x[:len(x)])
    10  
    11  	// Match, but the transformation is not sound w.r.t. possible side effects.
    12  	println(strings.Repeat("*", 3)[:len(strings.Repeat("*", 3))])
    13  
    14  	// No match, since second use of wildcard doesn't match first.
    15  	println(strings.Repeat("*", 3)[:len(strings.Repeat("*", 2))])
    16  
    17  	// Recursive match demonstrating bottom-up rewrite:
    18  	// only after the inner replacement occurs does the outer syntax match.
    19  	println((x[:len(x)])[:len(x[:len(x)])])
    20  	// -> (x[:len(x)])
    21  	// -> x
    22  }