aboutsummaryrefslogtreecommitdiff
path: root/refactor/eg/testdata/A1.golden
blob: 4f7ba82857f4c9a5941d3dec5d17956379f2ed54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// +build ignore

package A1

import (
	. "fmt"
	"errors"
	myfmt "fmt"
	"os"
	"strings"
)

func example(n int) {
	x := "foo" + strings.Repeat("\t", n)
	// Match, despite named import.
	errors.New(x)

	// Match, despite dot import.
	errors.New(x)

	// Match: multiple matches in same function are possible.
	errors.New(x)

	// No match: wildcarded operand has the wrong type.
	myfmt.Errorf("%s", 3)

	// No match: function operand doesn't match.
	myfmt.Printf("%s", x)

	// No match again, dot import.
	Printf("%s", x)

	// Match.
	myfmt.Fprint(os.Stderr, errors.New(x+"foo"))

	// No match: though this literally matches the template,
	// fmt doesn't resolve to a package here.
	var fmt struct{ Errorf func(string, string) }
	fmt.Errorf("%s", x)

	// Recursive matching:

	// Match: both matches are well-typed, so both succeed.
	errors.New(errors.New(x + "foo").Error())

	// Outer match succeeds, inner doesn't: 3 has wrong type.
	errors.New(myfmt.Errorf("%s", 3).Error())

	// Inner match succeeds, outer doesn't: the inner replacement
	// has the wrong type (error not string).
	myfmt.Errorf("%s", errors.New(x+"foo"))
}