ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: nobu@ruby-lang.org
To: ruby-core@ruby-lang.org
Subject: [ruby-core:95718] [Ruby master Bug#16293] Numbered parameter confirmation in Ruby 2.7
Date: Wed, 06 Nov 2019 03:45:37 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-82505.20191106034537.900c841a42a9f739@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-16293.20191105121436@ruby-lang.org

Issue #16293 has been updated by nobu (Nobuyoshi Nakada).

Backport set to 2.5: UNKNOWN, 2.6: UNKNOWN
Tracker changed from Feature to Bug

> ```ruby
> def _1; end
> 
> # expected: warning: `_1' is used as numbered parameter
> # actual: No warning
> # reason: Because "`x = _0 # expect _0()` outside block. → force warning on Ruby 2.7 and syntax error on Ruby 3" is written in the log
> x = _1

The "outside block" warning is shown at assignment to a local variable looks like a numbered parameter.
There is no assignment.

> ```ruby
> # expected: warning: `_1' is used as numbered parameter
> #           and call to _1()
> # actual: Error: numbered parameter outside block (SyntaxError)
> # reason: Because hoge() method is called with `eval("hoge")`
> eval("_1")
> ```

This is a bug.
As numbered parameter looks like an ordinary variable now, the warning doesn't make sense.

> ```ruby
> def _1; end
> 
> # expected: warning: `_1' is used as numbered parameter
> #           and call to _1()
> # actual: Error: ordinary parameter is defined
> # reason: Because "`1.times{|i| _0 }` → force warning on Ruby 2.7 and syntax error on Ruby 3." is written in the log
> proc { |i| _1 }.call 42
> ```

The method is irrelevant, Ruby doesn't know if it is defined or not until calling it.
And `_1` in a block is considered as a numbered parameter, it conflicts with `|i|`.

> ```ruby
> # expected: warning: `_1' is used as numbered parameter
> # actual: No warning
> # reason: Because define local variable _1 is warning
> def hgoe(_1)
> end
> ```

It is outside block.

> ```ruby
> proc {
>   # Warning
>   _1 = 42
> }
> 
> proc {
>   _1
>   # expected: warning: `_1' is used as numbered parameter
>   # actual: No warning
>   # reason: Because define local variable _1 is warning
>   _1 = 42
> }
> ```

This is a bug.
It must be a syntax error.
It was a syntax error in old versions actually.


----------------------------------------
Bug #16293: Numbered parameter confirmation in Ruby 2.7
https://bugs.ruby-lang.org/issues/16293#change-82505

* Author: osyo (manga osyo)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------

## Overview

I want to make a final check on the behavior of Numbered parameter( No warning or Warning or Error).
There is a difference in [DevelopersMeeting20190829Japan logs](https://docs.google.com/document/d/1XypDO1crRV9uNg1_ajxkljVdN8Vdyl5hnz462bDQw34/edit) and behavior.


## Ruby version

```ruby
p RUBY_VERSION
# => "2.7.0"
p RUBY_DESCRIPTION
# => "ruby 2.7.0dev (2019-11-02T06:32:49Z trunk 772b0613c5) [x86_64-linux]"
p RUBY_RELEASE_DATE
# => "2019-11-02"
p RUBY_REVISION
# => "772b0613c583773cd2eda23bce8275926a351e79"
```


## [DevelopersMeeting20190829Japan logs](https://docs.google.com/document/d/1XypDO1crRV9uNg1_ajxkljVdN8Vdyl5hnz462bDQw34/edit)

* local variables (parameters and assigned variable) → force warning (Don’t use) on Ruby 2.7 and syntax error on Ruby 3.
* method invocation
  * vcall: `x = _0 # expect _0()` outside block. → force warning on Ruby 2.7 and syntax error on Ruby 3.
  * vcall: `1.times{ _0 }` → block parameter (incompatibility)
  * vcall: `1.times{|i| _0 }` → force warning on Ruby 2.7 and syntax error on Ruby 3.
* method invocation (`x = _0(), x = foo._0`) → no warning
* method name (`def _0(); end`) → no warning


## Proposal

```ruby
def _1; end

# expected: warning: `_1' is used as numbered parameter
# actual: No warning
# reason: Because "`x = _0 # expect _0()` outside block. → force warning on Ruby 2.7 and syntax error on Ruby 3" is written in the log
x = _1

# expected: warning: `_1' is used as numbered parameter
#           and call to _1()
# actual: Error: numbered parameter outside block (SyntaxError)
# reason: Because hoge() method is called with `eval("hoge")`
eval("_1")
```

```ruby
def _1; end

# expected: warning: `_1' is used as numbered parameter
#           and call to _1()
# actual: Error: ordinary parameter is defined
# reason: Because "`1.times{|i| _0 }` → force warning on Ruby 2.7 and syntax error on Ruby 3." is written in the log
proc { |i| _1 }.call 42
```

```ruby
# expected: warning: `_1' is used as numbered parameter
# actual: No warning
# reason: Because define local variable _1 is warning
def hgoe(_1)
end
```

```ruby
proc {
  # Warning
  _1 = 42
}

proc {
  _1
  # expected: warning: `_1' is used as numbered parameter
  # actual: No warning
  # reason: Because define local variable _1 is warning
  _1 = 42
}
```

## :MEMO: Other behavior

* Other current behavior : https://gist.github.com/osyo-manga/f332ba1f31dbc3a437acd4d86d7986dc
* Is there any other syntax to change `No warning` `Warning` `Error` ?
* Considering compatibility, make it Warning instead of Error ?


Are there other edge cases for Numbered parameter?
Thank you :)





-- 
https://bugs.ruby-lang.org/

      parent reply	other threads:[~2019-11-06  3:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-16293.20191105121436@ruby-lang.org>
2019-11-05 12:14 ` [ruby-core:95696] [Ruby master Feature#16293] Numbered parameter confirmation in Ruby 2.7 manga.osyo
2019-11-05 12:56 ` [ruby-core:95698] " hsbt
2019-11-05 13:05 ` [ruby-core:95700] " mame
2019-11-05 16:18 ` [ruby-core:95703] " shevegen
2019-11-06  0:58 ` [ruby-core:95716] " manga.osyo
2019-11-06  3:45 ` nobu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-82505.20191106034537.900c841a42a9f739@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).