File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Expand file tree Collapse file tree 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
1111type typesTable map [string ]Type
1212
1313var (
14+ nilType = reflect .TypeOf (nil )
1415 boolType = reflect .TypeOf (true )
1516 numberType = reflect .TypeOf (float64 (0 ))
1617 textType = reflect .TypeOf ("" )
@@ -393,7 +394,10 @@ func funcType(ntype Type) (Type, bool) {
393394 case reflect .Interface :
394395 return interfaceType , true
395396 case reflect .Func :
396- return ntype , true
397+ if ntype .NumOut () > 0 {
398+ return ntype .Out (0 ), true
399+ }
400+ return nilType , true
397401 }
398402
399403 return nil , false
Original file line number Diff line number Diff line change @@ -71,6 +71,8 @@ var typeTests = []typeTest{
7171 "Int in Int..Int" ,
7272 "FieldStr == ''" ,
7373 "FieldStr2 == ''" ,
74+ "OkFn() and OkFn()" ,
75+ "Foo.Fn() or Foo.Fn()" ,
7476}
7577
7678var typeErrorTests = []typeErrorTest {
@@ -262,6 +264,10 @@ var typeErrorTests = []typeErrorTest{
262264 "Int .. Ok" ,
263265 "invalid operation: Int .. Ok (mismatched types int and bool)" ,
264266 },
267+ {
268+ "NilFn() and OkFn()" ,
269+ "invalid operation: NilFn() and OkFn() (mismatched types <nil> and bool)" ,
270+ },
265271}
266272
267273type abc interface {
@@ -272,7 +278,7 @@ type bar struct {
272278}
273279type foo struct {
274280 Bar bar
275- Fn func ()
281+ Fn func () bool
276282 Abc abc
277283}
278284
@@ -304,6 +310,8 @@ type payload struct {
304310 IntPtr * int
305311 StrPtr * string
306312 Foo2p * * foo
313+ OkFn func () bool
314+ NilFn func ()
307315}
308316
309317func TestType (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments