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