github.com/powerman/golang-tools@v0.1.11-0.20220410185822-5ad214d8d803/go/pointer/testdata/another.go (about)

     1  //go:build ignore
     2  // +build ignore
     3  
     4  package main
     5  
     6  var unknown bool
     7  
     8  type S string
     9  
    10  func incr(x int) int { return x + 1 }
    11  
    12  func main() {
    13  	var i interface{}
    14  	i = 1
    15  	if unknown {
    16  		i = S("foo")
    17  	}
    18  	if unknown {
    19  		i = (func(int, int))(nil) // NB type compares equal to that below.
    20  	}
    21  	// Look, the test harness can handle equal-but-not-String-equal
    22  	// types because we parse types and using a typemap.
    23  	if unknown {
    24  		i = (func(x int, y int))(nil)
    25  	}
    26  	if unknown {
    27  		i = incr
    28  	}
    29  	print(i) // @types int | S | func(int, int) | func(int) int
    30  
    31  	// NB, an interface may never directly alias any global
    32  	// labels, even though it may contain pointers that do.
    33  	print(i)                 // @pointsto makeinterface:func(x int) int | makeinterface:func(x int, y int) | makeinterface:func(int, int) | makeinterface:int | makeinterface:command-line-arguments.S
    34  	print(i.(func(int) int)) // @pointsto command-line-arguments.incr
    35  
    36  	print() // regression test for crash
    37  }