ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:117812] [Ruby master Bug#20478] Circular parameter syntax error rules
@ 2024-05-08 16:07 kddnewton (Kevin Newton) via ruby-core
  2024-05-10  7:48 ` [ruby-core:117825] " nobu (Nobuyoshi Nakada) via ruby-core
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: kddnewton (Kevin Newton) via ruby-core @ 2024-05-08 16:07 UTC (permalink / raw)
  To: ruby-core; +Cc: kddnewton (Kevin Newton)

Issue #20478 has been reported by kddnewton (Kevin Newton).

----------------------------------------
Bug #20478: Circular parameter syntax error rules
https://bugs.ruby-lang.org/issues/20478

* Author: kddnewton (Kevin Newton)
* Status: Open
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
I would like to revisit https://bugs.ruby-lang.org/issues/16343.

These cases are syntax errors:

```ruby
def foo(bar = -> { bar }) end       # no lambda parameters
def foo(bar = ->() { bar }) end     # no lambda parameters
def foo(bar = baz { bar }) end      # no block parameters
def foo(bar = baz { _1 + bar }) end # parameters, but no pipes
def foo(bar = baz { it + bar }) end # parameters, but no pipes
```

These cases are not syntax errors:

```ruby
def foo(bar = ->(baz) { bar }) end   # lambda parameters
def foo(bar = baz { || bar }) end    # no block parameters but empty pipes
def foo(bar = baz { |qux| bar }) end # block parameters
```

I don't think these rules are very intuitive, and they feel somewhat arbitrary. I would like to suggest we change them to be either:

* Syntax error is raised if the parameter is ever read in its default value at any scope depth
* Syntax error is raised if the parameter is ever read in its default value at depth 0

Either one is fine by me, but gating the syntax error based on the presence of pipes is really confusing.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:117825] [Ruby master Bug#20478] Circular parameter syntax error rules
  2024-05-08 16:07 [ruby-core:117812] [Ruby master Bug#20478] Circular parameter syntax error rules kddnewton (Kevin Newton) via ruby-core
@ 2024-05-10  7:48 ` nobu (Nobuyoshi Nakada) via ruby-core
  2024-05-10 13:44 ` [ruby-core:117829] " kddnewton (Kevin Newton) via ruby-core
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: nobu (Nobuyoshi Nakada) via ruby-core @ 2024-05-10  7:48 UTC (permalink / raw)
  To: ruby-core; +Cc: nobu (Nobuyoshi Nakada)

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


Given that these `Proc`s are only created if the argument `bar` is not assigned, should they all be syntax errors?

----------------------------------------
Bug #20478: Circular parameter syntax error rules
https://bugs.ruby-lang.org/issues/20478#change-108234

* Author: kddnewton (Kevin Newton)
* Status: Open
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
I would like to revisit https://bugs.ruby-lang.org/issues/16343.

These cases are syntax errors:

```ruby
def foo(bar = -> { bar }) end       # no lambda parameters
def foo(bar = ->() { bar }) end     # no lambda parameters
def foo(bar = baz { bar }) end      # no block parameters
def foo(bar = baz { _1 + bar }) end # parameters, but no pipes
def foo(bar = baz { it + bar }) end # parameters, but no pipes
```

These cases are not syntax errors:

```ruby
def foo(bar = ->(baz) { bar }) end   # lambda parameters
def foo(bar = baz { || bar }) end    # no block parameters but empty pipes
def foo(bar = baz { |qux| bar }) end # block parameters
```

I don't think these rules are very intuitive, and they feel somewhat arbitrary. I would like to suggest we change them to be either:

* Syntax error is raised if the parameter is ever read in its default value at any scope depth
* Syntax error is raised if the parameter is ever read in its default value at depth 0

Either one is fine by me, but gating the syntax error based on the presence of pipes is really confusing.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:117829] [Ruby master Bug#20478] Circular parameter syntax error rules
  2024-05-08 16:07 [ruby-core:117812] [Ruby master Bug#20478] Circular parameter syntax error rules kddnewton (Kevin Newton) via ruby-core
  2024-05-10  7:48 ` [ruby-core:117825] " nobu (Nobuyoshi Nakada) via ruby-core
@ 2024-05-10 13:44 ` kddnewton (Kevin Newton) via ruby-core
  2024-05-12  3:57 ` [ruby-core:117839] " nobu (Nobuyoshi Nakada) via ruby-core
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: kddnewton (Kevin Newton) via ruby-core @ 2024-05-10 13:44 UTC (permalink / raw)
  To: ruby-core; +Cc: kddnewton (Kevin Newton)

Issue #20478 has been updated by kddnewton (Kevin Newton).


Yes, I very much think they should all be syntax errors.

----------------------------------------
Bug #20478: Circular parameter syntax error rules
https://bugs.ruby-lang.org/issues/20478#change-108237

* Author: kddnewton (Kevin Newton)
* Status: Open
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
I would like to revisit https://bugs.ruby-lang.org/issues/16343.

These cases are syntax errors:

```ruby
def foo(bar = -> { bar }) end       # no lambda parameters
def foo(bar = ->() { bar }) end     # no lambda parameters
def foo(bar = baz { bar }) end      # no block parameters
def foo(bar = baz { _1 + bar }) end # parameters, but no pipes
def foo(bar = baz { it + bar }) end # parameters, but no pipes
```

These cases are not syntax errors:

```ruby
def foo(bar = ->(baz) { bar }) end   # lambda parameters
def foo(bar = baz { || bar }) end    # no block parameters but empty pipes
def foo(bar = baz { |qux| bar }) end # block parameters
```

I don't think these rules are very intuitive, and they feel somewhat arbitrary. I would like to suggest we change them to be either:

* Syntax error is raised if the parameter is ever read in its default value at any scope depth
* Syntax error is raised if the parameter is ever read in its default value at depth 0

Either one is fine by me, but gating the syntax error based on the presence of pipes is really confusing.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:117839] [Ruby master Bug#20478] Circular parameter syntax error rules
  2024-05-08 16:07 [ruby-core:117812] [Ruby master Bug#20478] Circular parameter syntax error rules kddnewton (Kevin Newton) via ruby-core
  2024-05-10  7:48 ` [ruby-core:117825] " nobu (Nobuyoshi Nakada) via ruby-core
  2024-05-10 13:44 ` [ruby-core:117829] " kddnewton (Kevin Newton) via ruby-core
@ 2024-05-12  3:57 ` nobu (Nobuyoshi Nakada) via ruby-core
  2024-05-13 16:42 ` [ruby-core:117864] " kddnewton (Kevin Newton) via ruby-core
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: nobu (Nobuyoshi Nakada) via ruby-core @ 2024-05-12  3:57 UTC (permalink / raw)
  To: ruby-core; +Cc: nobu (Nobuyoshi Nakada)

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


Even this should be a syntax error?

```ruby
def foo(bar = ->(baz = bar) {}) end
```

That means it needs to manage the list of yet-unusable variables, not only tracking single variable.

----------------------------------------
Bug #20478: Circular parameter syntax error rules
https://bugs.ruby-lang.org/issues/20478#change-108242

* Author: kddnewton (Kevin Newton)
* Status: Open
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
I would like to revisit https://bugs.ruby-lang.org/issues/16343.

These cases are syntax errors:

```ruby
def foo(bar = -> { bar }) end       # no lambda parameters
def foo(bar = ->() { bar }) end     # no lambda parameters
def foo(bar = baz { bar }) end      # no block parameters
def foo(bar = baz { _1 + bar }) end # parameters, but no pipes
def foo(bar = baz { it + bar }) end # parameters, but no pipes
```

These cases are not syntax errors:

```ruby
def foo(bar = ->(baz) { bar }) end   # lambda parameters
def foo(bar = baz { || bar }) end    # no block parameters but empty pipes
def foo(bar = baz { |qux| bar }) end # block parameters
```

I don't think these rules are very intuitive, and they feel somewhat arbitrary. I would like to suggest we change them to be either:

* Syntax error is raised if the parameter is ever read in its default value at any scope depth
* Syntax error is raised if the parameter is ever read in its default value at depth 0

Either one is fine by me, but gating the syntax error based on the presence of pipes is really confusing.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:117864] [Ruby master Bug#20478] Circular parameter syntax error rules
  2024-05-08 16:07 [ruby-core:117812] [Ruby master Bug#20478] Circular parameter syntax error rules kddnewton (Kevin Newton) via ruby-core
                   ` (2 preceding siblings ...)
  2024-05-12  3:57 ` [ruby-core:117839] " nobu (Nobuyoshi Nakada) via ruby-core
@ 2024-05-13 16:42 ` kddnewton (Kevin Newton) via ruby-core
  2024-05-20 14:05 ` [ruby-core:117943] " kddnewton (Kevin Newton) via ruby-core
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: kddnewton (Kevin Newton) via ruby-core @ 2024-05-13 16:42 UTC (permalink / raw)
  To: ruby-core; +Cc: kddnewton (Kevin Newton)

Issue #20478 has been updated by kddnewton (Kevin Newton).


I figured that was already happening for the "unused" warning.

----------------------------------------
Bug #20478: Circular parameter syntax error rules
https://bugs.ruby-lang.org/issues/20478#change-108273

* Author: kddnewton (Kevin Newton)
* Status: Open
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
I would like to revisit https://bugs.ruby-lang.org/issues/16343.

These cases are syntax errors:

```ruby
def foo(bar = -> { bar }) end       # no lambda parameters
def foo(bar = ->() { bar }) end     # no lambda parameters
def foo(bar = baz { bar }) end      # no block parameters
def foo(bar = baz { _1 + bar }) end # parameters, but no pipes
def foo(bar = baz { it + bar }) end # parameters, but no pipes
```

These cases are not syntax errors:

```ruby
def foo(bar = ->(baz) { bar }) end   # lambda parameters
def foo(bar = baz { || bar }) end    # no block parameters but empty pipes
def foo(bar = baz { |qux| bar }) end # block parameters
```

I don't think these rules are very intuitive, and they feel somewhat arbitrary. I would like to suggest we change them to be either:

* Syntax error is raised if the parameter is ever read in its default value at any scope depth
* Syntax error is raised if the parameter is ever read in its default value at depth 0

Either one is fine by me, but gating the syntax error based on the presence of pipes is really confusing.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:117943] [Ruby master Bug#20478] Circular parameter syntax error rules
  2024-05-08 16:07 [ruby-core:117812] [Ruby master Bug#20478] Circular parameter syntax error rules kddnewton (Kevin Newton) via ruby-core
                   ` (3 preceding siblings ...)
  2024-05-13 16:42 ` [ruby-core:117864] " kddnewton (Kevin Newton) via ruby-core
@ 2024-05-20 14:05 ` kddnewton (Kevin Newton) via ruby-core
  2024-05-23 17:37 ` [ruby-core:117986] " kddnewton (Kevin Newton) via ruby-core
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: kddnewton (Kevin Newton) via ruby-core @ 2024-05-20 14:05 UTC (permalink / raw)
  To: ruby-core; +Cc: kddnewton (Kevin Newton)

Issue #20478 has been updated by kddnewton (Kevin Newton).


@nobu another option would be to delete those tests and leave it up to the parser instead of forcing parse.y to implement it. Specifically I'm talking about:

```
    o = Object.new
    assert_warn("") do
      o.instance_eval("def foo(var: bar {| | var}) var end")
    end

    o = Object.new
    assert_warn("") do
      o.instance_eval("def foo(var: bar {|| var}) var end")
    end
```

and

```
    o = Object.new
    assert_warn("") do
      o.instance_eval("def foo(var = bar {| | var}) var end")
    end

    o = Object.new
    assert_warn("") do
      o.instance_eval("def foo(var = bar {|| var}) var end")
    end
```

If it's too complicated to implement in parse.y, then removing these tests would be a good compromise. These tests themselves are the issue blocking me.

----------------------------------------
Bug #20478: Circular parameter syntax error rules
https://bugs.ruby-lang.org/issues/20478#change-108360

* Author: kddnewton (Kevin Newton)
* Status: Open
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
I would like to revisit https://bugs.ruby-lang.org/issues/16343.

These cases are syntax errors:

```ruby
def foo(bar = -> { bar }) end       # no lambda parameters
def foo(bar = ->() { bar }) end     # no lambda parameters
def foo(bar = baz { bar }) end      # no block parameters
def foo(bar = baz { _1 + bar }) end # parameters, but no pipes
def foo(bar = baz { it + bar }) end # parameters, but no pipes
```

These cases are not syntax errors:

```ruby
def foo(bar = ->(baz) { bar }) end   # lambda parameters
def foo(bar = baz { || bar }) end    # no block parameters but empty pipes
def foo(bar = baz { |qux| bar }) end # block parameters
```

I don't think these rules are very intuitive, and they feel somewhat arbitrary. I would like to suggest we change them to be either:

* Syntax error is raised if the parameter is ever read in its default value at any scope depth
* Syntax error is raised if the parameter is ever read in its default value at depth 0

Either one is fine by me, but gating the syntax error based on the presence of pipes is really confusing.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:117986] [Ruby master Bug#20478] Circular parameter syntax error rules
  2024-05-08 16:07 [ruby-core:117812] [Ruby master Bug#20478] Circular parameter syntax error rules kddnewton (Kevin Newton) via ruby-core
                   ` (4 preceding siblings ...)
  2024-05-20 14:05 ` [ruby-core:117943] " kddnewton (Kevin Newton) via ruby-core
@ 2024-05-23 17:37 ` kddnewton (Kevin Newton) via ruby-core
  2024-05-23 17:39 ` [ruby-core:117987] " kddnewton (Kevin Newton) via ruby-core
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: kddnewton (Kevin Newton) via ruby-core @ 2024-05-23 17:37 UTC (permalink / raw)
  To: ruby-core; +Cc: kddnewton (Kevin Newton)

Issue #20478 has been updated by kddnewton (Kevin Newton).


If we go with only syntax errors at depth 0, then this:

```ruby
def foo(bar = baz { bar }) end
```

should not be a syntax error either. I think that makes sense, because the `baz` method could use `instance_exec`/`instance_eval` so we don't know if `bar` is going to be the same variable here or not.

----------------------------------------
Bug #20478: Circular parameter syntax error rules
https://bugs.ruby-lang.org/issues/20478#change-108410

* Author: kddnewton (Kevin Newton)
* Status: Open
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
I would like to revisit https://bugs.ruby-lang.org/issues/16343.

These cases are syntax errors:

```ruby
def foo(bar = -> { bar }) end       # no lambda parameters
def foo(bar = ->() { bar }) end     # no lambda parameters
def foo(bar = baz { bar }) end      # no block parameters
def foo(bar = baz { _1 + bar }) end # parameters, but no pipes
def foo(bar = baz { it + bar }) end # parameters, but no pipes
```

These cases are not syntax errors:

```ruby
def foo(bar = ->(baz) { bar }) end   # lambda parameters
def foo(bar = baz { || bar }) end    # no block parameters but empty pipes
def foo(bar = baz { |qux| bar }) end # block parameters
```

I don't think these rules are very intuitive, and they feel somewhat arbitrary. I would like to suggest we change them to be either:

* Syntax error is raised if the parameter is ever read in its default value at any scope depth
* Syntax error is raised if the parameter is ever read in its default value at depth 0

Either one is fine by me, but gating the syntax error based on the presence of pipes is really confusing.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:117987] [Ruby master Bug#20478] Circular parameter syntax error rules
  2024-05-08 16:07 [ruby-core:117812] [Ruby master Bug#20478] Circular parameter syntax error rules kddnewton (Kevin Newton) via ruby-core
                   ` (5 preceding siblings ...)
  2024-05-23 17:37 ` [ruby-core:117986] " kddnewton (Kevin Newton) via ruby-core
@ 2024-05-23 17:39 ` kddnewton (Kevin Newton) via ruby-core
  2024-06-06  9:10 ` [ruby-core:118200] " mame (Yusuke Endoh) via ruby-core
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: kddnewton (Kevin Newton) via ruby-core @ 2024-05-23 17:39 UTC (permalink / raw)
  To: ruby-core; +Cc: kddnewton (Kevin Newton)

Issue #20478 has been updated by kddnewton (Kevin Newton).


Also:

```ruby
def foo(bar = ->    { bar }) end
def foo(bar = ->( ) { bar }) end
def foo(bar = ->(_) { bar }) end
```

Two of these are a syntax error, but I think either all of them should be or none of them should be.

----------------------------------------
Bug #20478: Circular parameter syntax error rules
https://bugs.ruby-lang.org/issues/20478#change-108411

* Author: kddnewton (Kevin Newton)
* Status: Open
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
I would like to revisit https://bugs.ruby-lang.org/issues/16343.

These cases are syntax errors:

```ruby
def foo(bar = -> { bar }) end       # no lambda parameters
def foo(bar = ->() { bar }) end     # no lambda parameters
def foo(bar = baz { bar }) end      # no block parameters
def foo(bar = baz { _1 + bar }) end # parameters, but no pipes
def foo(bar = baz { it + bar }) end # parameters, but no pipes
```

These cases are not syntax errors:

```ruby
def foo(bar = ->(baz) { bar }) end   # lambda parameters
def foo(bar = baz { || bar }) end    # no block parameters but empty pipes
def foo(bar = baz { |qux| bar }) end # block parameters
```

I don't think these rules are very intuitive, and they feel somewhat arbitrary. I would like to suggest we change them to be either:

* Syntax error is raised if the parameter is ever read in its default value at any scope depth
* Syntax error is raised if the parameter is ever read in its default value at depth 0

Either one is fine by me, but gating the syntax error based on the presence of pipes is really confusing.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:118200] [Ruby master Bug#20478] Circular parameter syntax error rules
  2024-05-08 16:07 [ruby-core:117812] [Ruby master Bug#20478] Circular parameter syntax error rules kddnewton (Kevin Newton) via ruby-core
                   ` (6 preceding siblings ...)
  2024-05-23 17:39 ` [ruby-core:117987] " kddnewton (Kevin Newton) via ruby-core
@ 2024-06-06  9:10 ` mame (Yusuke Endoh) via ruby-core
  2024-06-06 20:30 ` [ruby-core:118222] " kddnewton (Kevin Newton) via ruby-core
  2024-12-20  9:16 ` [ruby-core:120344] " Earlopain (Earlopain _) via ruby-core
  9 siblings, 0 replies; 11+ messages in thread
From: mame (Yusuke Endoh) via ruby-core @ 2024-06-06  9:10 UTC (permalink / raw)
  To: ruby-core; +Cc: mame (Yusuke Endoh)

Issue #20478 has been updated by mame (Yusuke Endoh).


Discussed at the dev meeting. @matz said all cases should be accepted with no syntax error. So `def foo(bar = bar) = bar; foo` will return `nil` with no warning and error.

----------------------------------------
Bug #20478: Circular parameter syntax error rules
https://bugs.ruby-lang.org/issues/20478#change-108687

* Author: kddnewton (Kevin Newton)
* Status: Open
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
I would like to revisit https://bugs.ruby-lang.org/issues/16343.

These cases are syntax errors:

```ruby
def foo(bar = -> { bar }) end       # no lambda parameters
def foo(bar = ->() { bar }) end     # no lambda parameters
def foo(bar = baz { bar }) end      # no block parameters
def foo(bar = baz { _1 + bar }) end # parameters, but no pipes
def foo(bar = baz { it + bar }) end # parameters, but no pipes
```

These cases are not syntax errors:

```ruby
def foo(bar = ->(baz) { bar }) end   # lambda parameters
def foo(bar = baz { || bar }) end    # no block parameters but empty pipes
def foo(bar = baz { |qux| bar }) end # block parameters
```

I don't think these rules are very intuitive, and they feel somewhat arbitrary. I would like to suggest we change them to be either:

* Syntax error is raised if the parameter is ever read in its default value at any scope depth
* Syntax error is raised if the parameter is ever read in its default value at depth 0

Either one is fine by me, but gating the syntax error based on the presence of pipes is really confusing.



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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:118222] [Ruby master Bug#20478] Circular parameter syntax error rules
  2024-05-08 16:07 [ruby-core:117812] [Ruby master Bug#20478] Circular parameter syntax error rules kddnewton (Kevin Newton) via ruby-core
                   ` (7 preceding siblings ...)
  2024-06-06  9:10 ` [ruby-core:118200] " mame (Yusuke Endoh) via ruby-core
@ 2024-06-06 20:30 ` kddnewton (Kevin Newton) via ruby-core
  2024-12-20  9:16 ` [ruby-core:120344] " Earlopain (Earlopain _) via ruby-core
  9 siblings, 0 replies; 11+ messages in thread
From: kddnewton (Kevin Newton) via ruby-core @ 2024-06-06 20:30 UTC (permalink / raw)
  To: ruby-core; +Cc: kddnewton (Kevin Newton)

Issue #20478 has been updated by kddnewton (Kevin Newton).

Status changed from Open to Closed

Merged.

----------------------------------------
Bug #20478: Circular parameter syntax error rules
https://bugs.ruby-lang.org/issues/20478#change-108712

* Author: kddnewton (Kevin Newton)
* Status: Closed
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
I would like to revisit https://bugs.ruby-lang.org/issues/16343.

These cases are syntax errors:

```ruby
def foo(bar = -> { bar }) end       # no lambda parameters
def foo(bar = ->() { bar }) end     # no lambda parameters
def foo(bar = baz { bar }) end      # no block parameters
def foo(bar = baz { _1 + bar }) end # parameters, but no pipes
def foo(bar = baz { it + bar }) end # parameters, but no pipes
```

These cases are not syntax errors:

```ruby
def foo(bar = ->(baz) { bar }) end   # lambda parameters
def foo(bar = baz { || bar }) end    # no block parameters but empty pipes
def foo(bar = baz { |qux| bar }) end # block parameters
```

I don't think these rules are very intuitive, and they feel somewhat arbitrary. I would like to suggest we change them to be either:

* Syntax error is raised if the parameter is ever read in its default value at any scope depth
* Syntax error is raised if the parameter is ever read in its default value at depth 0

Either one is fine by me, but gating the syntax error based on the presence of pipes is really confusing.



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

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [ruby-core:120344] [Ruby master Bug#20478] Circular parameter syntax error rules
  2024-05-08 16:07 [ruby-core:117812] [Ruby master Bug#20478] Circular parameter syntax error rules kddnewton (Kevin Newton) via ruby-core
                   ` (8 preceding siblings ...)
  2024-06-06 20:30 ` [ruby-core:118222] " kddnewton (Kevin Newton) via ruby-core
@ 2024-12-20  9:16 ` Earlopain (Earlopain _) via ruby-core
  9 siblings, 0 replies; 11+ messages in thread
From: Earlopain (Earlopain _) via ruby-core @ 2024-12-20  9:16 UTC (permalink / raw)
  To: ruby-core; +Cc: Earlopain (Earlopain _)

Issue #20478 has been updated by Earlopain (Earlopain _).


This used to emit a warning since all the way back from Ruby 2.2, before it was invalid syntax. Should the warning be reintroduced?

----------------------------------------
Bug #20478: Circular parameter syntax error rules
https://bugs.ruby-lang.org/issues/20478#change-111118

* Author: kddnewton (Kevin Newton)
* Status: Closed
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
I would like to revisit https://bugs.ruby-lang.org/issues/16343.

These cases are syntax errors:

```ruby
def foo(bar = -> { bar }) end       # no lambda parameters
def foo(bar = ->() { bar }) end     # no lambda parameters
def foo(bar = baz { bar }) end      # no block parameters
def foo(bar = baz { _1 + bar }) end # parameters, but no pipes
def foo(bar = baz { it + bar }) end # parameters, but no pipes
```

These cases are not syntax errors:

```ruby
def foo(bar = ->(baz) { bar }) end   # lambda parameters
def foo(bar = baz { || bar }) end    # no block parameters but empty pipes
def foo(bar = baz { |qux| bar }) end # block parameters
```

I don't think these rules are very intuitive, and they feel somewhat arbitrary. I would like to suggest we change them to be either:

* Syntax error is raised if the parameter is ever read in its default value at any scope depth
* Syntax error is raised if the parameter is ever read in its default value at depth 0

Either one is fine by me, but gating the syntax error based on the presence of pipes is really confusing.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-12-20  9:16 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-08 16:07 [ruby-core:117812] [Ruby master Bug#20478] Circular parameter syntax error rules kddnewton (Kevin Newton) via ruby-core
2024-05-10  7:48 ` [ruby-core:117825] " nobu (Nobuyoshi Nakada) via ruby-core
2024-05-10 13:44 ` [ruby-core:117829] " kddnewton (Kevin Newton) via ruby-core
2024-05-12  3:57 ` [ruby-core:117839] " nobu (Nobuyoshi Nakada) via ruby-core
2024-05-13 16:42 ` [ruby-core:117864] " kddnewton (Kevin Newton) via ruby-core
2024-05-20 14:05 ` [ruby-core:117943] " kddnewton (Kevin Newton) via ruby-core
2024-05-23 17:37 ` [ruby-core:117986] " kddnewton (Kevin Newton) via ruby-core
2024-05-23 17:39 ` [ruby-core:117987] " kddnewton (Kevin Newton) via ruby-core
2024-06-06  9:10 ` [ruby-core:118200] " mame (Yusuke Endoh) via ruby-core
2024-06-06 20:30 ` [ruby-core:118222] " kddnewton (Kevin Newton) via ruby-core
2024-12-20  9:16 ` [ruby-core:120344] " Earlopain (Earlopain _) via ruby-core

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 NNTP newsgroup(s).