Skip to content

Commit 14d81b4

Browse files
Ignoring functions returning functions.
1 parent 1e11675 commit 14d81b4

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

_examples/multireturn/multireturn.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,11 @@ func TripleWithInterfaceWithoutErrorFunc() (IntInterFace, IntStrUct, *IntStrUct)
100100

101101
return &i1700, s1800, &s1900
102102
}
103+
104+
//// Function returning function /////
105+
type FunctionType func(input int) int
106+
func FunctionReturningFunction() FunctionType {
107+
return func(input int) int{
108+
return input
109+
}
110+
}

_examples/multireturn/test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,6 @@
7272
############### Triple Interface Return Without Error ##############
7373
(interface1700, struct1800, ptr1900) = multireturn.TripleWithInterfaceWithoutErrorFunc()
7474
print("Triple WithoutError() Return (%r, %r, %r)" % (interface1700.Number(), struct1800.P, ptr1900.P))
75+
76+
############## Function Returning Functions ignored ##############
77+
assert("FunctionReturningFunction" not in dir(multireturn))

bind/symbols.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ func isPyCompatFunc(sig *types.Signature) (haserr, hasfun bool, err error) {
184184
if isErrorType(result.Type()) {
185185
haserr = true
186186
}
187+
if isFuncType(result.Type()) {
188+
err = fmt.Errorf("gopy: Result values of type function are not supported: %s", sig.String())
189+
return
190+
}
187191
}
188192
}
189193

bind/utils.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ func isErrorType(typ types.Type) bool {
2424
return typ == types.Universe.Lookup("error").Type()
2525
}
2626

27+
func isFuncType(typ types.Type) bool {
28+
_, ok := typ.Underlying().(*types.Signature)
29+
return ok
30+
}
31+
2732
func isStringer(obj types.Object) bool {
2833
switch obj := obj.(type) {
2934
case *types.Func:

0 commit comments

Comments
 (0)