File tree 2 files changed +14
-2
lines changed
2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ type Type = reflect.Type
11
11
type typesTable map [string ]Type
12
12
13
13
var (
14
+ nilType = reflect .TypeOf (nil )
14
15
boolType = reflect .TypeOf (true )
15
16
numberType = reflect .TypeOf (float64 (0 ))
16
17
textType = reflect .TypeOf ("" )
@@ -393,7 +394,10 @@ func funcType(ntype Type) (Type, bool) {
393
394
case reflect .Interface :
394
395
return interfaceType , true
395
396
case reflect .Func :
396
- return ntype , true
397
+ if ntype .NumOut () > 0 {
398
+ return ntype .Out (0 ), true
399
+ }
400
+ return nilType , true
397
401
}
398
402
399
403
return nil , false
Original file line number Diff line number Diff line change @@ -71,6 +71,8 @@ var typeTests = []typeTest{
71
71
"Int in Int..Int" ,
72
72
"FieldStr == ''" ,
73
73
"FieldStr2 == ''" ,
74
+ "OkFn() and OkFn()" ,
75
+ "Foo.Fn() or Foo.Fn()" ,
74
76
}
75
77
76
78
var typeErrorTests = []typeErrorTest {
@@ -262,6 +264,10 @@ var typeErrorTests = []typeErrorTest{
262
264
"Int .. Ok" ,
263
265
"invalid operation: Int .. Ok (mismatched types int and bool)" ,
264
266
},
267
+ {
268
+ "NilFn() and OkFn()" ,
269
+ "invalid operation: NilFn() and OkFn() (mismatched types <nil> and bool)" ,
270
+ },
265
271
}
266
272
267
273
type abc interface {
@@ -272,7 +278,7 @@ type bar struct {
272
278
}
273
279
type foo struct {
274
280
Bar bar
275
- Fn func ()
281
+ Fn func () bool
276
282
Abc abc
277
283
}
278
284
@@ -304,6 +310,8 @@ type payload struct {
304
310
IntPtr * int
305
311
StrPtr * string
306
312
Foo2p * * foo
313
+ OkFn func () bool
314
+ NilFn func ()
307
315
}
308
316
309
317
func TestType (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments