File: typdef.go

package info (click to toggle)
golang-golang-x-tools 1%3A0.5.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 16,592 kB
  • sloc: javascript: 2,011; asm: 1,635; sh: 192; yacc: 155; makefile: 52; ansic: 8
file content (65 lines) | stat: -rw-r--r-- 1,582 bytes parent folder | download
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
53
54
55
56
57
58
59
60
61
62
63
64
65
package typdef

type Struct struct { //@item(Struct, "Struct", "struct{...}", "struct")
	Field string
}

type Int int //@item(Int, "Int", "int", "type")

func _() {
	var (
		value Struct
		point *Struct
	)
	_ = value //@typdef("value", Struct)
	_ = point //@typdef("point", Struct)

	var (
		array   [3]Struct
		slice   []Struct
		ch      chan Struct
		complex [3]chan *[5][]Int
	)
	_ = array   //@typdef("array", Struct)
	_ = slice   //@typdef("slice", Struct)
	_ = ch      //@typdef("ch", Struct)
	_ = complex //@typdef("complex", Int)

	var s struct {
		x struct {
			xx struct {
				field1 []Struct
				field2 []Int
			}
		}
	}
	s.x.xx.field1 //@typdef("field1", Struct)
	s.x.xx.field2 //@typdef("field2", Int)
}

func F1() Int                              { return 0 }
func F2() (Int, float64)                   { return 0, 0 }
func F3() (Struct, int, bool, error)       { return Struct{}, 0, false, nil }
func F4() (**int, Int, bool, *error)       { return nil, Struct{}, false, nil }
func F5() (int, float64, error, Struct)    { return 0, 0, nil, Struct{} }
func F6() (int, float64, ***Struct, error) { return 0, 0, nil, nil }

func _() {
	F1() //@typdef("F1", Int)
	F2() //@typdef("F2", Int)
	F3() //@typdef("F3", Struct)
	F4() //@typdef("F4", Int)
	F5() //@typdef("F5", Struct)
	F6() //@typdef("F6", Struct)

	f := func() Int { return 0 }
	f() //@typdef("f", Int)
}

// https://github.com/golang/go/issues/38589#issuecomment-620350922
func _() {
	type myFunc func(int) Int //@item(myFunc, "myFunc", "func", "type")

	var foo myFunc
	bar := foo() //@typdef("foo", myFunc)
}