| 1 |
package pkg |
| 2 |
|
| 3 |
import ( |
| 4 |
"context" |
| 5 |
"fmt" |
| 6 |
"net/http" |
| 7 |
"strings" |
| 8 |
) |
| 9 |
|
| 10 |
func fn1() { |
| 11 |
strings.Replace("", "", "", 1) //@ diag(`doesn't have side effects`) |
| 12 |
foo(1, 2) //@ diag(`doesn't have side effects`) |
| 13 |
baz(1, 2) //@ diag(`doesn't have side effects`) |
| 14 |
_, x := baz(1, 2) |
| 15 |
_ = x |
| 16 |
bar(1, 2) |
| 17 |
} |
| 18 |
|
| 19 |
func fn2() { |
| 20 |
r, _ := http.NewRequest("GET", "/", nil) |
| 21 |
r.WithContext(context.Background()) //@ diag(`doesn't have side effects`) |
| 22 |
} |
| 23 |
|
| 24 |
func foo(a, b int) int { return a + b } |
| 25 |
func baz(a, b int) (int, int) { return a + b, a + b } |
| 26 |
func bar(a, b int) int { |
| 27 |
println(a + b) |
| 28 |
return a + b |
| 29 |
} |
| 30 |
|
| 31 |
func empty() {} |
| 32 |
func stubPointer() *int { return nil } |
| 33 |
func stubInt() int { return 0 } |
| 34 |
|
| 35 |
func fn3() { |
| 36 |
empty() |
| 37 |
stubPointer() |
| 38 |
stubInt() |
| 39 |
} |
| 40 |
|
| 41 |
func fn4() error { |
| 42 |
// Test for https://github.com/dominikh/go-tools/issues/949 |
| 43 |
if true { |
| 44 |
return fmt.Errorf("") |
| 45 |
} |
| 46 |
for { |
| 47 |
} |
| 48 |
} |