| 1 |
// Copyright 2021 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
package main |
| 6 |
|
| 7 |
import ( |
| 8 |
"sort" |
| 9 |
"strings" |
| 10 |
|
| 11 |
"issue20014.dir/a" |
| 12 |
) |
| 13 |
|
| 14 |
func main() { |
| 15 |
samePackage() |
| 16 |
crossPackage() |
| 17 |
|
| 18 |
// Print fields registered with field tracking. |
| 19 |
var fields []string |
| 20 |
for _, line := range strings.Split(fieldTrackInfo, "\n") { |
| 21 |
if line != "" { |
| 22 |
fields = append(fields, strings.Split(line, "\t")[0]) |
| 23 |
} |
| 24 |
} |
| 25 |
sort.Strings(fields) // for stable output, regardless of optimizations |
| 26 |
for _, field := range fields { |
| 27 |
println(field) |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
type T struct { |
| 32 |
X int `go:"track"` |
| 33 |
Y int `go:"track"` |
| 34 |
Z int // untracked |
| 35 |
} |
| 36 |
|
| 37 |
func (t *T) GetX() int { |
| 38 |
return t.X |
| 39 |
} |
| 40 |
func (t *T) GetY() int { |
| 41 |
return t.Y |
| 42 |
} |
| 43 |
func (t *T) GetZ() int { |
| 44 |
return t.Z |
| 45 |
} |
| 46 |
|
| 47 |
func samePackage() { |
| 48 |
var t T |
| 49 |
println(t.GetX()) |
| 50 |
println(t.GetZ()) |
| 51 |
} |
| 52 |
|
| 53 |
func crossPackage() { |
| 54 |
var t a.T |
| 55 |
println(t.GetX()) |
| 56 |
println(t.GetZ()) |
| 57 |
} |
| 58 |
|
| 59 |
// This global variable is set by the linker using the -k option. |
| 60 |
var fieldTrackInfo string |