aboutsummaryrefslogtreecommitdiff
path: root/go/pointer/testdata/typeparams.go
blob: 461ba443768599b1605c34c2550f0102eda18b09 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//go:build ignore
// +build ignore

package main

import (
	"fmt"
	"os"
)

type S[T any] struct{ t T }

var theSint S[int]
var theSbool S[bool]

func (s *S[T]) String() string {
	print(s) // @pointsto command-line-arguments.theSbool | command-line-arguments.theSint
	return ""
}

func Type[T any]() {
	var x *T
	print(x) // @types *int | *bool
}

func Caller[T any]() {
	var s *S[T]
	_ = s.String()
}

var a int
var b bool

type t[T any] struct {
	a *map[string]chan *T
}

func fn[T any](a *T) {
	m := make(map[string]chan *T)
	m[""] = make(chan *T, 1)
	m[""] <- a
	x := []t[T]{t[T]{a: &m}}
	print(x) // @pointstoquery <-(*x[i].a)[key] command-line-arguments.a | command-line-arguments.b
}

func main() {
	// os.Args is considered intrinsically allocated,
	// but may also be set explicitly (e.g. on Windows), hence '...'.
	print(os.Args) // @pointsto <command-line args> | ...
	fmt.Println("Hello!", &theSint)
	fmt.Println("World!", &theSbool)

	Type[int]()      // call
	f := Type[bool]  // call through a variable
	_ = Type[string] // not called so will not appear in Type's print.
	f()

	Caller[int]()
	Caller[bool]()

	fn(&a)
	fn(&b)
}

// @calls (*fmt.pp).handleMethods -> (*command-line-arguments.S[int]).String[int]
// @calls (*fmt.pp).handleMethods -> (*command-line-arguments.S[bool]).String[bool]
// @calls command-line-arguments.Caller[int] -> (*command-line-arguments.S[int]).String[int]
// @calls command-line-arguments.Caller[bool] -> (*command-line-arguments.S[bool]).String[bool]