blob: df3e2e435bb26051215cad9a85550f65d820f05a [file] [log] [blame]
Russ Coxd2cc9882012-02-16 23:50:37 -05001// errorcheck
Russ Coxbee2d5b2010-09-30 14:59:41 -04002
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
Rob Pike13514d42012-02-19 17:33:41 +11007// Test methods derived from embedded interface and *interface values.
Russ Coxbee2d5b2010-09-30 14:59:41 -04008
9package main
10
11import "os"
12
13const Value = 1e12
14
David Chased4bb72b2015-05-05 13:25:58 -040015type Inter interface {
16 M() int64
17}
Russ Coxbee2d5b2010-09-30 14:59:41 -040018
19type T int64
David Chased4bb72b2015-05-05 13:25:58 -040020
Russ Coxbee2d5b2010-09-30 14:59:41 -040021func (t T) M() int64 { return int64(t) }
David Chased4bb72b2015-05-05 13:25:58 -040022
Russ Coxbee2d5b2010-09-30 14:59:41 -040023var t = T(Value)
24var pt = &t
25var ti Inter = t
26var pti = &ti
27
David Chased4bb72b2015-05-05 13:25:58 -040028type S struct{ Inter }
29
30var s = S{ti}
Russ Coxbee2d5b2010-09-30 14:59:41 -040031var ps = &s
32
David Chased4bb72b2015-05-05 13:25:58 -040033type SP struct{ *Inter } // ERROR "interface"
Russ Coxbee2d5b2010-09-30 14:59:41 -040034
35var i Inter
36var pi = &i
37
38var ok = true
39
40func check(s string, v int64) {
41 if v != Value {
42 println(s, v)
43 ok = false
44 }
45}
46
47func main() {
48 check("t.M()", t.M())
49 check("pt.M()", pt.M())
50 check("ti.M()", ti.M())
David Chased4bb72b2015-05-05 13:25:58 -040051 check("pti.M()", pti.M()) // ERROR "pointer to interface, not interface"
Russ Coxbee2d5b2010-09-30 14:59:41 -040052 check("s.M()", s.M())
53 check("ps.M()", ps.M())
54
55 i = t
56 check("i = t; i.M()", i.M())
David Chased4bb72b2015-05-05 13:25:58 -040057 check("i = t; pi.M()", pi.M()) // ERROR "pointer to interface, not interface"
Russ Coxbee2d5b2010-09-30 14:59:41 -040058
59 i = pt
60 check("i = pt; i.M()", i.M())
David Chased4bb72b2015-05-05 13:25:58 -040061 check("i = pt; pi.M()", pi.M()) // ERROR "pointer to interface, not interface"
Russ Coxbee2d5b2010-09-30 14:59:41 -040062
63 i = s
64 check("i = s; i.M()", i.M())
David Chased4bb72b2015-05-05 13:25:58 -040065 check("i = s; pi.M()", pi.M()) // ERROR "pointer to interface, not interface"
Russ Coxbee2d5b2010-09-30 14:59:41 -040066
67 i = ps
68 check("i = ps; i.M()", i.M())
David Chased4bb72b2015-05-05 13:25:58 -040069 check("i = ps; pi.M()", pi.M()) // ERROR "pointer to interface, not interface"
Russ Coxbee2d5b2010-09-30 14:59:41 -040070
71 if !ok {
72 println("BUG: interface10")
73 os.Exit(1)
74 }
75}