blob: 227fe70d87de6435eefcf08d0a64d2cdc80c5d3d [file] [log] [blame]
Russ Cox4224d812015-03-20 00:06:10 -04001// errorcheck -0 -d=typeassert
2
Emmanuel Odeke53fd5222016-04-10 14:32:26 -07003// Copyright 2015 The Go Authors. All rights reserved.
Russ Cox4224d812015-03-20 00:06:10 -04004// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6
7package p
8
9func assertptr(x interface{}) *int {
10 return x.(*int) // ERROR "type assertion inlined"
11}
12
13func assertptr2(x interface{}) (*int, bool) {
14 z, ok := x.(*int) // ERROR "type assertion inlined"
15 return z, ok
16}
17
18func assertfunc(x interface{}) func() {
19 return x.(func()) // ERROR "type assertion inlined"
20}
21
22func assertfunc2(x interface{}) (func(), bool) {
23 z, ok := x.(func()) // ERROR "type assertion inlined"
24 return z, ok
25}
26
27// TODO(rsc): struct{*int} is stored directly in the interface
28// and should be possible to fetch back out of the interface,
29// but more of the general data movement code needs to
30// realize that before we can inline the assertion.
31
32func assertstruct(x interface{}) struct{ *int } {
33 return x.(struct{ *int }) // ERROR "type assertion not inlined"
34}
35
36func assertstruct2(x interface{}) (struct{ *int }, bool) {
37 z, ok := x.(struct{ *int }) // ERROR "type assertion not inlined"
38 return z, ok
39}
40
41func assertbig(x interface{}) complex128 {
42 return x.(complex128) // ERROR "type assertion not inlined"
43}
44
45func assertbig2(x interface{}) (complex128, bool) {
46 z, ok := x.(complex128) // ERROR "type assertion not inlined"
47 return z, ok
48}
49
50func assertbig2ok(x interface{}) (complex128, bool) {
51 _, ok := x.(complex128) // ERROR "type assertion [(]ok only[)] inlined"
52 return 0, ok
53}