Oldes / Rebol-issues

Issue tracker for https://github.com/oldes/Rebol3
4 stars 0 forks source link

Use of `return:` keyword in a function specification may be confusing #2629

Open Oldes opened 2 weeks ago

Oldes commented 2 weeks ago

Use of return: keyword in a function specification may be confusing when used with functions which automatically collects set-words... like function, wrap which uses bind/set internally (reason why I noticed the issue) or even context.

>> f1: function[][ f2: func[return: [integer!]][ return 42 'oh-no! ] f2 ]
== func [/local f2 return][f2: func [return: [integer!]] [return 42 'oh-no!] f2] ;; return is collected as a local word!
>> f1
== oh-no! ;;<-- expected is 42

>> wrap [ f3: func[return: [integer!]][ return 42 'oh-no! ] f3 ]
== oh-no! ;;<-- expected is 42

>> context [ f4: func[return: [integer!]][ return 42 'oh-no! ] print f4 ] ()
oh-no! ;;<-- expected is 42

Maybe it would be better to use some other type than a set-word.

Red has the same issue: https://github.com/red/red/issues/5554

dockimbel commented 2 weeks ago

In Red:

>> context [ f4: func[return: [integer!]][ return 42 'oh-no! ] print f4 ] ()
42

Set-words collecting in object's body is done at root level only.

Oldes commented 2 weeks ago

I should not include the context example here as I already fixed this case as a part of this issue: https://github.com/Oldes/Rebol-issues/issues/2602.

But the case with function inside a function and wrap is still a problem.