2012-02-17 04:51:04 +00:00
|
|
|
// errorcheck
|
2009-09-25 00:54:47 +00:00
|
|
|
|
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// Test that basic operations on named types are valid
|
|
|
|
// and preserve the type.
|
2012-02-24 00:48:19 +00:00
|
|
|
// Does not compile.
|
2009-09-25 00:54:47 +00:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
type Bool bool
|
|
|
|
|
|
|
|
type Map map[int]int
|
2010-06-09 01:50:02 +00:00
|
|
|
|
2009-09-25 00:54:47 +00:00
|
|
|
func (Map) M() {}
|
|
|
|
|
2010-06-09 01:50:02 +00:00
|
|
|
type Slice []byte
|
|
|
|
|
|
|
|
var slice Slice
|
|
|
|
|
|
|
|
func asBool(Bool) {}
|
|
|
|
func asString(String) {}
|
|
|
|
|
|
|
|
type String string
|
2009-09-25 00:54:47 +00:00
|
|
|
|
|
|
|
func main() {
|
|
|
|
var (
|
2012-02-22 03:54:07 +00:00
|
|
|
b Bool = true
|
2010-06-09 01:50:02 +00:00
|
|
|
i, j int
|
|
|
|
c = make(chan int)
|
|
|
|
m = make(Map)
|
2009-09-25 00:54:47 +00:00
|
|
|
)
|
|
|
|
|
2010-06-09 01:50:02 +00:00
|
|
|
asBool(b)
|
|
|
|
asBool(!b)
|
2012-02-22 03:54:07 +00:00
|
|
|
asBool(true)
|
2010-06-09 01:50:02 +00:00
|
|
|
asBool(*&b)
|
|
|
|
asBool(Bool(true))
|
2012-02-22 05:29:37 +00:00
|
|
|
asBool(1 != 2) // ok now
|
|
|
|
asBool(i < j) // ok now
|
2009-09-25 00:54:47 +00:00
|
|
|
|
2014-08-11 23:11:55 +00:00
|
|
|
_, b = m[2] // ok now
|
2009-09-25 00:54:47 +00:00
|
|
|
|
2010-06-09 01:50:02 +00:00
|
|
|
var inter interface{}
|
2014-08-11 23:11:55 +00:00
|
|
|
_, b = inter.(Map) // ok now
|
2010-06-09 01:50:02 +00:00
|
|
|
_ = b
|
2009-09-25 00:54:47 +00:00
|
|
|
|
2010-06-09 01:50:02 +00:00
|
|
|
var minter interface {
|
|
|
|
M()
|
|
|
|
}
|
2014-08-11 23:11:55 +00:00
|
|
|
_, b = minter.(Map) // ok now
|
2010-06-09 01:50:02 +00:00
|
|
|
_ = b
|
2009-09-25 00:54:47 +00:00
|
|
|
|
2011-03-11 19:47:44 +00:00
|
|
|
_, bb := <-c
|
|
|
|
asBool(bb) // ERROR "cannot use.*type bool.*as type Bool"
|
2014-08-11 23:11:55 +00:00
|
|
|
_, b = <-c // ok now
|
2010-06-09 01:50:02 +00:00
|
|
|
_ = b
|
2009-09-25 00:54:47 +00:00
|
|
|
|
2011-11-22 17:30:02 +00:00
|
|
|
asString(String(slice)) // ok
|
2010-06-09 01:50:02 +00:00
|
|
|
}
|