2015-03-19 22:06:10 -06:00
|
|
|
// errorcheck -0 -d=typeassert
|
|
|
|
|
2016-04-10 15:32:26 -06:00
|
|
|
// Copyright 2015 The Go Authors. All rights reserved.
|
2015-03-19 22:06:10 -06:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package p
|
|
|
|
|
|
|
|
func assertptr(x interface{}) *int {
|
|
|
|
return x.(*int) // ERROR "type assertion inlined"
|
|
|
|
}
|
|
|
|
|
|
|
|
func assertptr2(x interface{}) (*int, bool) {
|
|
|
|
z, ok := x.(*int) // ERROR "type assertion inlined"
|
|
|
|
return z, ok
|
|
|
|
}
|
|
|
|
|
|
|
|
func assertfunc(x interface{}) func() {
|
|
|
|
return x.(func()) // ERROR "type assertion inlined"
|
|
|
|
}
|
|
|
|
|
|
|
|
func assertfunc2(x interface{}) (func(), bool) {
|
|
|
|
z, ok := x.(func()) // ERROR "type assertion inlined"
|
|
|
|
return z, ok
|
|
|
|
}
|
|
|
|
|
|
|
|
func assertstruct(x interface{}) struct{ *int } {
|
2016-10-28 12:37:45 -06:00
|
|
|
return x.(struct{ *int }) // ERROR "type assertion inlined"
|
2015-03-19 22:06:10 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func assertstruct2(x interface{}) (struct{ *int }, bool) {
|
2016-10-28 12:37:45 -06:00
|
|
|
z, ok := x.(struct{ *int }) // ERROR "type assertion inlined"
|
2015-03-19 22:06:10 -06:00
|
|
|
return z, ok
|
|
|
|
}
|
|
|
|
|
|
|
|
func assertbig(x interface{}) complex128 {
|
2016-10-28 12:37:45 -06:00
|
|
|
return x.(complex128) // ERROR "type assertion inlined"
|
2015-03-19 22:06:10 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func assertbig2(x interface{}) (complex128, bool) {
|
2016-10-28 12:37:45 -06:00
|
|
|
z, ok := x.(complex128) // ERROR "type assertion inlined"
|
2015-03-19 22:06:10 -06:00
|
|
|
return z, ok
|
|
|
|
}
|
|
|
|
|
|
|
|
func assertbig2ok(x interface{}) (complex128, bool) {
|
2016-10-28 12:37:45 -06:00
|
|
|
_, ok := x.(complex128) // ERROR "type assertion inlined"
|
2015-03-19 22:06:10 -06:00
|
|
|
return 0, ok
|
|
|
|
}
|
2016-06-06 13:38:19 -06:00
|
|
|
|
|
|
|
func assertslice(x interface{}) []int {
|
2016-10-28 12:37:45 -06:00
|
|
|
return x.([]int) // ERROR "type assertion inlined"
|
2016-06-06 13:38:19 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func assertslice2(x interface{}) ([]int, bool) {
|
2016-10-28 12:37:45 -06:00
|
|
|
z, ok := x.([]int) // ERROR "type assertion inlined"
|
2016-06-06 13:38:19 -06:00
|
|
|
return z, ok
|
|
|
|
}
|
|
|
|
|
|
|
|
func assertslice2ok(x interface{}) ([]int, bool) {
|
2016-10-28 12:37:45 -06:00
|
|
|
_, ok := x.([]int) // ERROR "type assertion inlined"
|
2016-06-06 13:38:19 -06:00
|
|
|
return nil, ok
|
|
|
|
}
|
2016-10-28 12:37:45 -06:00
|
|
|
|
|
|
|
type I interface {
|
|
|
|
foo()
|
|
|
|
}
|
|
|
|
|
|
|
|
func assertInter(x interface{}) I {
|
|
|
|
return x.(I) // ERROR "type assertion not inlined"
|
|
|
|
}
|
|
|
|
func assertInter2(x interface{}) (I, bool) {
|
|
|
|
z, ok := x.(I) // ERROR "type assertion not inlined"
|
|
|
|
return z, ok
|
|
|
|
}
|