OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [go.test/] [test/] [ken/] [interfun.go] - Blame information for rev 700

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 700 jeremybenn
// $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 S struct {
10
        a,b     int;
11
}
12
 
13
type I1 interface {
14
        f       ()int;
15
}
16
 
17
type I2 interface {
18
        g() int;
19
        f() int;
20
}
21
 
22
func (this *S) f()int {
23
        return this.a;
24
}
25
 
26
func (this *S) g()int {
27
        return this.b;
28
}
29
 
30
func
31
main() {
32
        var i1 I1;
33
        var i2 I2;
34
        var g *S;
35
 
36
        s := new(S);
37
        s.a = 5;
38
        s.b = 6;
39
 
40
        // call structure
41
        if s.f() != 5 { panic(11); }
42
        if s.g() != 6 { panic(12); }
43
 
44
        i1 = s;         // convert S to I1
45
        i2 = i1.(I2);   // convert I1 to I2
46
 
47
        // call interface
48
        if i1.f() != 5 { panic(21); }
49
        if i2.f() != 5 { panic(22); }
50
        if i2.g() != 6 { panic(23); }
51
 
52
        g = i1.(*S);            // convert I1 to S
53
        if g != s { panic(31); }
54
 
55
        g = i2.(*S);            // convert I2 to S
56
        if g != s { panic(32); }
57
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.