1// run
2
3// Copyright 2010 The Go Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6
7// https://golang.org/issue/807
8
9package main
10
11type Point struct {
12	X, Y int64
13}
14
15type Rect struct {
16	Min, Max Point
17}
18
19func (p Point) Sub(q Point) Point {
20	return Point{p.X-q.X, p.Y-q.Y}
21}
22
23type Obj struct {
24	bbox Rect
25}
26
27func (o *Obj) Bbox() Rect {
28	return o.bbox
29}
30
31func (o *Obj) Points() [2]Point{
32	return [2]Point{o.bbox.Min, o.bbox.Max}
33}
34
35var x = 0
36
37func main() {
38	o := &Obj{Rect{Point{800, 0}, Point{}}}
39	p := Point{800, 300}
40	q := p.Sub(o.Bbox().Min)
41	if q.X != 0 || q.Y != 300 {
42		println("BUG dot: ", q.X, q.Y)
43		return
44	}
45
46	q = p.Sub(o.Points()[0])
47	if q.X != 0 || q.Y != 300 {
48		println("BUG index const: ", q.X, q.Y)
49	}
50
51	q = p.Sub(o.Points()[x])
52	if q.X != 0 || q.Y != 300 {
53		println("BUG index var: ", q.X, q.Y)
54	}
55}
56