diff --git a/type.go b/type.go index 3d7eae81c..f4d03f99a 100644 --- a/type.go +++ b/type.go @@ -11,6 +11,7 @@ type Type = reflect.Type type typesTable map[string]Type var ( + nilType = reflect.TypeOf(nil) boolType = reflect.TypeOf(true) numberType = reflect.TypeOf(float64(0)) textType = reflect.TypeOf("") @@ -393,7 +394,10 @@ func funcType(ntype Type) (Type, bool) { case reflect.Interface: return interfaceType, true case reflect.Func: - return ntype, true + if ntype.NumOut() > 0 { + return ntype.Out(0), true + } + return nilType, true } return nil, false diff --git a/type_test.go b/type_test.go index cde1ce7ec..e902bdfcc 100644 --- a/type_test.go +++ b/type_test.go @@ -71,6 +71,8 @@ var typeTests = []typeTest{ "Int in Int..Int", "FieldStr == ''", "FieldStr2 == ''", + "OkFn() and OkFn()", + "Foo.Fn() or Foo.Fn()", } var typeErrorTests = []typeErrorTest{ @@ -262,6 +264,10 @@ var typeErrorTests = []typeErrorTest{ "Int .. Ok", "invalid operation: Int .. Ok (mismatched types int and bool)", }, + { + "NilFn() and OkFn()", + "invalid operation: NilFn() and OkFn() (mismatched types and bool)", + }, } type abc interface { @@ -272,7 +278,7 @@ type bar struct { } type foo struct { Bar bar - Fn func() + Fn func() bool Abc abc } @@ -304,6 +310,8 @@ type payload struct { IntPtr *int StrPtr *string Foo2p **foo + OkFn func() bool + NilFn func() } func TestType(t *testing.T) {