Russ Cox | 4224d81 | 2015-03-20 00:06:10 -0400 | [diff] [blame] | 1 | // errorcheck -0 -d=typeassert |
| 2 | |
Emmanuel Odeke | 53fd522 | 2016-04-10 14:32:26 -0700 | [diff] [blame] | 3 | // Copyright 2015 The Go Authors. All rights reserved. |
Russ Cox | 4224d81 | 2015-03-20 00:06:10 -0400 | [diff] [blame] | 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 p |
| 8 | |
| 9 | func assertptr(x interface{}) *int { |
| 10 | return x.(*int) // ERROR "type assertion inlined" |
| 11 | } |
| 12 | |
| 13 | func assertptr2(x interface{}) (*int, bool) { |
| 14 | z, ok := x.(*int) // ERROR "type assertion inlined" |
| 15 | return z, ok |
| 16 | } |
| 17 | |
| 18 | func assertfunc(x interface{}) func() { |
| 19 | return x.(func()) // ERROR "type assertion inlined" |
| 20 | } |
| 21 | |
| 22 | func assertfunc2(x interface{}) (func(), bool) { |
| 23 | z, ok := x.(func()) // ERROR "type assertion inlined" |
| 24 | return z, ok |
| 25 | } |
| 26 | |
Russ Cox | 4224d81 | 2015-03-20 00:06:10 -0400 | [diff] [blame] | 27 | func assertstruct(x interface{}) struct{ *int } { |
Keith Randall | 688995d | 2016-10-28 11:37:45 -0700 | [diff] [blame] | 28 | return x.(struct{ *int }) // ERROR "type assertion inlined" |
Russ Cox | 4224d81 | 2015-03-20 00:06:10 -0400 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | func assertstruct2(x interface{}) (struct{ *int }, bool) { |
Keith Randall | 688995d | 2016-10-28 11:37:45 -0700 | [diff] [blame] | 32 | z, ok := x.(struct{ *int }) // ERROR "type assertion inlined" |
Russ Cox | 4224d81 | 2015-03-20 00:06:10 -0400 | [diff] [blame] | 33 | return z, ok |
| 34 | } |
| 35 | |
| 36 | func assertbig(x interface{}) complex128 { |
Keith Randall | 688995d | 2016-10-28 11:37:45 -0700 | [diff] [blame] | 37 | return x.(complex128) // ERROR "type assertion inlined" |
Russ Cox | 4224d81 | 2015-03-20 00:06:10 -0400 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | func assertbig2(x interface{}) (complex128, bool) { |
Keith Randall | 688995d | 2016-10-28 11:37:45 -0700 | [diff] [blame] | 41 | z, ok := x.(complex128) // ERROR "type assertion inlined" |
Russ Cox | 4224d81 | 2015-03-20 00:06:10 -0400 | [diff] [blame] | 42 | return z, ok |
| 43 | } |
| 44 | |
| 45 | func assertbig2ok(x interface{}) (complex128, bool) { |
Keith Randall | 688995d | 2016-10-28 11:37:45 -0700 | [diff] [blame] | 46 | _, ok := x.(complex128) // ERROR "type assertion inlined" |
Russ Cox | 4224d81 | 2015-03-20 00:06:10 -0400 | [diff] [blame] | 47 | return 0, ok |
| 48 | } |
Josh Bleecher Snyder | 615a52b | 2016-06-06 12:38:19 -0700 | [diff] [blame] | 49 | |
| 50 | func assertslice(x interface{}) []int { |
Keith Randall | 688995d | 2016-10-28 11:37:45 -0700 | [diff] [blame] | 51 | return x.([]int) // ERROR "type assertion inlined" |
Josh Bleecher Snyder | 615a52b | 2016-06-06 12:38:19 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | func assertslice2(x interface{}) ([]int, bool) { |
Keith Randall | 688995d | 2016-10-28 11:37:45 -0700 | [diff] [blame] | 55 | z, ok := x.([]int) // ERROR "type assertion inlined" |
Josh Bleecher Snyder | 615a52b | 2016-06-06 12:38:19 -0700 | [diff] [blame] | 56 | return z, ok |
| 57 | } |
| 58 | |
| 59 | func assertslice2ok(x interface{}) ([]int, bool) { |
Keith Randall | 688995d | 2016-10-28 11:37:45 -0700 | [diff] [blame] | 60 | _, ok := x.([]int) // ERROR "type assertion inlined" |
Josh Bleecher Snyder | 615a52b | 2016-06-06 12:38:19 -0700 | [diff] [blame] | 61 | return nil, ok |
| 62 | } |
Keith Randall | 688995d | 2016-10-28 11:37:45 -0700 | [diff] [blame] | 63 | |
| 64 | type I interface { |
| 65 | foo() |
| 66 | } |
| 67 | |
| 68 | func assertInter(x interface{}) I { |
| 69 | return x.(I) // ERROR "type assertion not inlined" |
| 70 | } |
| 71 | func assertInter2(x interface{}) (I, bool) { |
| 72 | z, ok := x.(I) // ERROR "type assertion not inlined" |
| 73 | return z, ok |
| 74 | } |