1
0
mirror of https://github.com/golang/go synced 2024-10-01 13:18:33 -06:00
go/pointer/testdata/another.go
Alan Donovan 6b75c15eec go.tools/pointer: replace Pointer, PointsToSet interfaces with their sole implementations.
(Elminate premature abstraction.)

The test probes used Pointer!=nil for the "is pointerlike"
predicate. Now that Pointer is a struct, they check the type
of the expression, which is more accurate.  Two probes on
non-pointerlike values have beem removed.

R=crawshaw
CC=golang-dev
https://golang.org/cl/38420043
2013-12-06 12:52:04 -05:00

35 lines
863 B
Go

// +build ignore
package main
var unknown bool
type S string
func incr(x int) int { return x + 1 }
func main() {
var i interface{}
i = 1
if unknown {
i = S("foo")
}
if unknown {
i = (func(int, int))(nil) // NB type compares equal to that below.
}
// Look, the test harness can handle equal-but-not-String-equal
// types because we parse types and using a typemap.
if unknown {
i = (func(x int, y int))(nil)
}
if unknown {
i = incr
}
print(i) // @types int | S | func(int, int) | func(int) int
// NB, an interface may never directly alias any global
// labels, even though it may contain pointers that do.
print(i) // @pointsto makeinterface:func(x int) int | makeinterface:func(x int, y int) | makeinterface:func(int, int) | makeinterface:int | makeinterface:main.S
print(i.(func(int) int)) // @pointsto main.incr
}