* [ruby-core:83590] [Ruby trunk Bug#14062] Top-level return allows an argument
[not found] <redmine.issue-14062.20171027101020@ruby-lang.org>
@ 2017-10-27 10:10 ` eregontp
2017-10-27 11:12 ` [ruby-core:83591] " duerst
` (4 subsequent siblings)
5 siblings, 0 replies; 6+ messages in thread
From: eregontp @ 2017-10-27 10:10 UTC (permalink / raw
To: ruby-core
Issue #14062 has been reported by Eregon (Benoit Daloze).
----------------------------------------
Bug #14062: Top-level return allows an argument
https://bugs.ruby-lang.org/issues/14062
* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
* ruby -v: ruby 2.5.0dev (2017-10-26 trunk 60450) [x86_64-linux]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
~~~ ruby
puts "Here"
return 42 # or :foo, or any value
~~~
~~~
ruby test.rb
Here
~~~
Should it be a SyntaxError, as mentioned in https://bugs.ruby-lang.org/issues/4840#note-24 ?
It seems confusing to accept it silently, as one could expect the exact code to be affected by it (that should not be the case imho).
Discovered in https://github.com/ruby/spec/pull/530
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ruby-core:83591] [Ruby trunk Bug#14062] Top-level return allows an argument
[not found] <redmine.issue-14062.20171027101020@ruby-lang.org>
2017-10-27 10:10 ` [ruby-core:83590] [Ruby trunk Bug#14062] Top-level return allows an argument eregontp
@ 2017-10-27 11:12 ` duerst
2017-10-27 15:18 ` [ruby-core:83592] " eregontp
` (3 subsequent siblings)
5 siblings, 0 replies; 6+ messages in thread
From: duerst @ 2017-10-27 11:12 UTC (permalink / raw
To: ruby-core
Issue #14062 has been updated by duerst (Martin Dürst).
Wouldn't this be equivalent to C's return statement in main()?
It is used to tell the outer process (usually a shell) about the success (0) or failure (anything else than 0) of the program.
In the average shell, you should be able to test it with e.g.
```
ruby test.rb && echo "Previous process was successful."
```
which would not print the `"Previous process was successful."` text because the return value was something else than 0.
----------------------------------------
Bug #14062: Top-level return allows an argument
https://bugs.ruby-lang.org/issues/14062#change-67615
* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
* ruby -v: ruby 2.5.0dev (2017-10-26 trunk 60450) [x86_64-linux]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
~~~ ruby
puts "Here"
return 42 # or :foo, or any value
~~~
~~~
ruby test.rb
Here
~~~
Should it be a SyntaxError, as mentioned in https://bugs.ruby-lang.org/issues/4840#note-24 ?
It seems confusing to accept it silently, as one could expect the exact code to be affected by it (that should not be the case imho).
Discovered in https://github.com/ruby/spec/pull/530
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ruby-core:83592] [Ruby trunk Bug#14062] Top-level return allows an argument
[not found] <redmine.issue-14062.20171027101020@ruby-lang.org>
2017-10-27 10:10 ` [ruby-core:83590] [Ruby trunk Bug#14062] Top-level return allows an argument eregontp
2017-10-27 11:12 ` [ruby-core:83591] " duerst
@ 2017-10-27 15:18 ` eregontp
2018-02-20 7:12 ` [ruby-core:85675] " matz
` (2 subsequent siblings)
5 siblings, 0 replies; 6+ messages in thread
From: eregontp @ 2017-10-27 15:18 UTC (permalink / raw
To: ruby-core
Issue #14062 has been updated by Eregon (Benoit Daloze).
Currently the argument is ignored.
And I think it would make little sense in a file loaded by #require to affect the global exist status if it does a "return 1".
"exit 1" can be used for that, top-level return is to avoid loading anything further in the file when it's not needed in my understanding.
----------------------------------------
Bug #14062: Top-level return allows an argument
https://bugs.ruby-lang.org/issues/14062#change-67619
* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
* ruby -v: ruby 2.5.0dev (2017-10-26 trunk 60450) [x86_64-linux]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
~~~ ruby
puts "Here"
return 42 # or :foo, or any value
~~~
~~~
ruby test.rb
Here
~~~
Should it be a SyntaxError, as mentioned in https://bugs.ruby-lang.org/issues/4840#note-24 ?
It seems confusing to accept it silently, as one could expect the exact code to be affected by it (that should not be the case imho).
Discovered in https://github.com/ruby/spec/pull/530
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ruby-core:85675] [Ruby trunk Bug#14062] Top-level return allows an argument
[not found] <redmine.issue-14062.20171027101020@ruby-lang.org>
` (2 preceding siblings ...)
2017-10-27 15:18 ` [ruby-core:83592] " eregontp
@ 2018-02-20 7:12 ` matz
2019-07-26 22:16 ` [ruby-core:93939] [Ruby master " merch-redmine
2019-07-27 11:10 ` [ruby-core:93949] " eregontp
5 siblings, 0 replies; 6+ messages in thread
From: matz @ 2018-02-20 7:12 UTC (permalink / raw
To: ruby-core
Issue #14062 has been updated by matz (Yukihiro Matsumoto).
I am against making it a syntax error. Adding warnings is OK (but maybe we can rely on Rubocop etc. to detect them).
Matz.
----------------------------------------
Bug #14062: Top-level return allows an argument
https://bugs.ruby-lang.org/issues/14062#change-70469
* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
* ruby -v: ruby 2.5.0dev (2017-10-26 trunk 60450) [x86_64-linux]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
~~~ ruby
puts "Here"
return 42 # or :foo, or any value
~~~
~~~
ruby test.rb
Here
~~~
Should it be a SyntaxError, as mentioned in https://bugs.ruby-lang.org/issues/4840#note-24 ?
It seems confusing to accept it silently, as one could expect the exact code to be affected by it (that should not be the case imho).
Discovered in https://github.com/ruby/spec/pull/530
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ruby-core:93939] [Ruby master Bug#14062] Top-level return allows an argument
[not found] <redmine.issue-14062.20171027101020@ruby-lang.org>
` (3 preceding siblings ...)
2018-02-20 7:12 ` [ruby-core:85675] " matz
@ 2019-07-26 22:16 ` merch-redmine
2019-07-27 11:10 ` [ruby-core:93949] " eregontp
5 siblings, 0 replies; 6+ messages in thread
From: merch-redmine @ 2019-07-26 22:16 UTC (permalink / raw
To: ruby-core
Issue #14062 has been updated by jeremyevans0 (Jeremy Evans).
File top-level-return-warn-argument.patch added
Attached is a patch that adds a warning when using a top-level return with an argument.
----------------------------------------
Bug #14062: Top-level return allows an argument
https://bugs.ruby-lang.org/issues/14062#change-80111
* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
* ruby -v: ruby 2.5.0dev (2017-10-26 trunk 60450) [x86_64-linux]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
~~~ ruby
puts "Here"
return 42 # or :foo, or any value
~~~
~~~
ruby test.rb
Here
~~~
Should it be a SyntaxError, as mentioned in https://bugs.ruby-lang.org/issues/4840#note-24 ?
It seems confusing to accept it silently, as one could expect the exact code to be affected by it (that should not be the case imho).
Discovered in https://github.com/ruby/spec/pull/530
---Files--------------------------------
top-level-return-warn-argument.patch (1.32 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ruby-core:93949] [Ruby master Bug#14062] Top-level return allows an argument
[not found] <redmine.issue-14062.20171027101020@ruby-lang.org>
` (4 preceding siblings ...)
2019-07-26 22:16 ` [ruby-core:93939] [Ruby master " merch-redmine
@ 2019-07-27 11:10 ` eregontp
5 siblings, 0 replies; 6+ messages in thread
From: eregontp @ 2019-07-27 11:10 UTC (permalink / raw
To: ruby-core
Issue #14062 has been updated by Eregon (Benoit Daloze).
jeremyevans0 (Jeremy Evans) wrote:
> Attached is a patch that adds a warning when using a top-level return with an argument.
Thank you, it looks good to me.
Although, I would suggest to change the warning message to one of these:
```
argument of top-level return is ignored
argument of return at top-level is ignored
```
Could you commit it?
----------------------------------------
Bug #14062: Top-level return allows an argument
https://bugs.ruby-lang.org/issues/14062#change-80136
* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
* ruby -v: ruby 2.5.0dev (2017-10-26 trunk 60450) [x86_64-linux]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
~~~ ruby
puts "Here"
return 42 # or :foo, or any value
~~~
~~~
ruby test.rb
Here
~~~
Should it be a SyntaxError, as mentioned in https://bugs.ruby-lang.org/issues/4840#note-24 ?
It seems confusing to accept it silently, as one could expect the exit code to be affected by it (that should not be the case imho).
Discovered in https://github.com/ruby/spec/pull/530
---Files--------------------------------
top-level-return-warn-argument.patch (1.32 KB)
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-07-27 11:10 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <redmine.issue-14062.20171027101020@ruby-lang.org>
2017-10-27 10:10 ` [ruby-core:83590] [Ruby trunk Bug#14062] Top-level return allows an argument eregontp
2017-10-27 11:12 ` [ruby-core:83591] " duerst
2017-10-27 15:18 ` [ruby-core:83592] " eregontp
2018-02-20 7:12 ` [ruby-core:85675] " matz
2019-07-26 22:16 ` [ruby-core:93939] [Ruby master " merch-redmine
2019-07-27 11:10 ` [ruby-core:93949] " eregontp
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).