Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Oldes opened this issue Nov 1, 2024 · 2 comments
Open

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

Oldes opened this issue Nov 1, 2024 · 2 comments

Comments

@Oldes
Copy link
Owner

Oldes commented Nov 1, 2024

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: red/red#5554

@dockimbel
Copy link

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
Copy link
Owner Author

Oldes commented Nov 1, 2024

I should not include the context example here as I already fixed this case as a part of this issue: #2602.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants