1 // $G $D/$F.go && $L $F.$A && ./$A.out
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.
7 // Test that basic operations on named types are valid
8 // and preserve the type.
21 // Calling these functions checks at compile time that the argument
22 // can be converted implicitly to (used as) the given type.
23 func asArray(Array) {}
26 func asFloat(Float) {}
29 func asSlice(Slice) {}
30 func asString(String) {}
35 // These functions check at run time that the default type
36 // (in the absence of any implicit conversion hints)
38 func isArray(x interface{}) { _ = x.(Array) }
39 func isBool(x interface{}) { _ = x.(Bool) }
40 func isChan(x interface{}) { _ = x.(Chan) }
41 func isFloat(x interface{}) { _ = x.(Float) }
42 func isInt(x interface{}) { _ = x.(Int) }
43 func isMap(x interface{}) { _ = x.(Map) }
44 func isSlice(x interface{}) { _ = x.(Slice) }
45 func isString(x interface{}) { _ = x.(String) }
55 slice Slice = make(Slice, 10);
88 var inter interface{};
92 var minter interface{M()};
263 asSlice(make(Slice, 5));
264 isSlice(make(Slice, 5));
265 asSlice([]byte{1,2,3});
266 asSlice([]byte{1,2,3}[0:2]);
275 asSlice(Slice{1,2,3});
276 isSlice(Slice{1,2,3});
292 asString(String('a'));
293 isString(String('a'));
294 asString(String(slice));
295 isString(String(slice));
296 asString(String([]byte(nil)));
297 isString(String([]byte(nil)));
299 asString(String("hello"));
300 isString(String("hello"));