File: A1.go

package info (click to toggle)
golang-golang-x-tools 1%3A0.25.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 22,724 kB
  • sloc: javascript: 2,027; asm: 1,645; sh: 166; yacc: 155; makefile: 49; ansic: 8
file content (49 lines) | stat: -rw-r--r-- 1,153 bytes parent folder | download | duplicates (3)
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
package A1

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

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

	// Match, despite dot import.
	Errorf("%s", x)

	// Match: multiple matches in same function are possible.
	myfmt.Errorf("%s", 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, myfmt.Errorf("%s", 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.
	myfmt.Errorf("%s", myfmt.Errorf("%s", x+"foo").Error())

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

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