]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/go.test/test/fixedbugs/bug027.go
Add Go frontend, libgo library, and Go testsuite.
[thirdparty/gcc.git] / gcc / testsuite / go.test / test / fixedbugs / bug027.go
1 // $G $D/$F.go && $L $F.$A && ./$A.out
2
3 // Copyright 2009 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 package main
8
9 type Element interface {
10 }
11
12 type Vector struct {
13 nelem int;
14 elem []Element;
15 }
16
17 func New() *Vector {
18 v := new(Vector);
19 v.nelem = 0;
20 v.elem = make([]Element, 10);
21 return v;
22 }
23
24 func (v *Vector) At(i int) Element {
25 return v.elem[i];
26 }
27
28 func (v *Vector) Insert(e Element) {
29 v.elem[v.nelem] = e;
30 v.nelem++;
31 }
32
33 func main() {
34 type I struct { val int; };
35 i0 := new(I); i0.val = 0;
36 i1 := new(I); i1.val = 11;
37 i2 := new(I); i2.val = 222;
38 i3 := new(I); i3.val = 3333;
39 i4 := new(I); i4.val = 44444;
40 v := New();
41 print("hi\n");
42 v.Insert(i4);
43 v.Insert(i3);
44 v.Insert(i2);
45 v.Insert(i1);
46 v.Insert(i0);
47 for i := 0; i < v.nelem; i++ {
48 var x *I;
49 x = v.At(i).(*I);
50 print(i, " ", x.val, "\n"); // prints correct list
51 }
52 for i := 0; i < v.nelem; i++ {
53 print(i, " ", v.At(i).(*I).val, "\n");
54 }
55 }
56 /*
57 bug027.go:50: illegal types for operand
58 (<Element>I{}) CONV (<I>{})
59 bug027.go:50: illegal types for operand
60 (<Element>I{}) CONV (<I>{})
61 */