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

+ ruby{33,34}.y: allow blocks inherit anonymous args. #1010

Merged
merged 1 commit into from Apr 26, 2024

Conversation

iliabylich
Copy link
Collaborator

This commit tracks upstream commit ruby/ruby@596db9c.

Closes #963.

Unfortunately there are 0 tests for anonymous <PARAM> parameter is also used within block error message in the ruby/ruby repo.

A small script to verify this behaviour
set -x

$RUN 'def b(&) ->(&) {c(&)} end'
$RUN 'def b(*) ->(*) {c(*)} end'
$RUN 'def b(a, *) ->(*) {c(1, *)} end'
$RUN 'def b(*) ->(a, *) {c(*)} end'
$RUN 'def b(**) ->(**) {c(**)} end'
$RUN 'def b(k:, **) ->(**) {c(k: 1, **)} end'
$RUN 'def b(**) ->(k:, **) {c(**)} end'
echo

$RUN 'def b(&) ->(&) {c()} end'
$RUN 'def b(*) ->(*) {c()} end'
$RUN 'def b(**) ->(**) {c()} end'
echo

$RUN 'def b(&) ->() {c(&)} end'
$RUN 'def b(*) ->() {c(*)} end'
$RUN 'def b(a, *) ->() {c(1, *)} end'
$RUN 'def b(*) ->(a) {c(*)} end'
$RUN 'def b(**) ->() {c(**)} end'
$RUN 'def b(k:, **) ->() {c(k: 1, **)} end'
$RUN 'def b(**) ->(k:) {c(**)} end'

Ruby 3.3.0 (only inputs in the 2nd group are valid):

Details
+ ruby -cve 'def b(&) ->(&) {c(&)} end'
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
-e:1: anonymous block parameter is also used within block
-e: compile error (SyntaxError)
+ ruby -cve 'def b(*) ->(*) {c(*)} end'
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
-e:1: anonymous rest parameter is also used within block
-e: compile error (SyntaxError)
+ ruby -cve 'def b(a, *) ->(*) {c(1, *)} end'
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
-e:1: anonymous rest parameter is also used within block
-e: compile error (SyntaxError)
+ ruby -cve 'def b(*) ->(a, *) {c(*)} end'
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
-e:1: anonymous rest parameter is also used within block
-e: compile error (SyntaxError)
+ ruby -cve 'def b(**) ->(**) {c(**)} end'
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
-e:1: anonymous keyword rest parameter is also used within block
-e: compile error (SyntaxError)
+ ruby -cve 'def b(k:, **) ->(**) {c(k: 1, **)} end'
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
-e:1: anonymous keyword rest parameter is also used within block
-e: compile error (SyntaxError)
+ ruby -cve 'def b(**) ->(k:, **) {c(**)} end'
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
-e:1: anonymous keyword rest parameter is also used within block
-e: compile error (SyntaxError)
+ echo

+ ruby -cve 'def b(&) ->(&) {c()} end'
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
Syntax OK
+ ruby -cve 'def b(*) ->(*) {c()} end'
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
Syntax OK
+ ruby -cve 'def b(**) ->(**) {c()} end'
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
Syntax OK
+ echo

+ ruby -cve 'def b(&) ->() {c(&)} end'
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
-e:1: anonymous block parameter is also used within block
-e: compile error (SyntaxError)
+ ruby -cve 'def b(*) ->() {c(*)} end'
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
-e:1: anonymous rest parameter is also used within block
-e: compile error (SyntaxError)
+ ruby -cve 'def b(a, *) ->() {c(1, *)} end'
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
-e:1: anonymous rest parameter is also used within block
-e: compile error (SyntaxError)
+ ruby -cve 'def b(*) ->(a) {c(*)} end'
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
-e:1: anonymous rest parameter is also used within block
-e: compile error (SyntaxError)
+ ruby -cve 'def b(**) ->() {c(**)} end'
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
-e:1: anonymous keyword rest parameter is also used within block
-e: compile error (SyntaxError)
+ ruby -cve 'def b(k:, **) ->() {c(k: 1, **)} end'
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
-e:1: anonymous keyword rest parameter is also used within block
-e: compile error (SyntaxError)
+ ruby -cve 'def b(**) ->(k:) {c(**)} end'
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
-e:1: anonymous keyword rest parameter is also used within block
-e: compile error (SyntaxError)

Ruby 3.3.1 (the 2nd and the 3rd groups are valid):

Details
+ ruby -cve 'def b(&) ->(&) {c(&)} end'
ruby 3.3.1 (2024-04-23 revision c56cd86388) [arm64-darwin23]
-e:1: anonymous block parameter is also used within block
-e: compile error (SyntaxError)
+ ruby -cve 'def b(*) ->(*) {c(*)} end'
ruby 3.3.1 (2024-04-23 revision c56cd86388) [arm64-darwin23]
-e:1: anonymous rest parameter is also used within block
-e: compile error (SyntaxError)
+ ruby -cve 'def b(a, *) ->(*) {c(1, *)} end'
ruby 3.3.1 (2024-04-23 revision c56cd86388) [arm64-darwin23]
-e:1: anonymous rest parameter is also used within block
-e: compile error (SyntaxError)
+ ruby -cve 'def b(*) ->(a, *) {c(*)} end'
ruby 3.3.1 (2024-04-23 revision c56cd86388) [arm64-darwin23]
-e:1: anonymous rest parameter is also used within block
-e: compile error (SyntaxError)
+ ruby -cve 'def b(**) ->(**) {c(**)} end'
ruby 3.3.1 (2024-04-23 revision c56cd86388) [arm64-darwin23]
-e:1: anonymous keyword rest parameter is also used within block
-e: compile error (SyntaxError)
+ ruby -cve 'def b(k:, **) ->(**) {c(k: 1, **)} end'
ruby 3.3.1 (2024-04-23 revision c56cd86388) [arm64-darwin23]
-e:1: anonymous keyword rest parameter is also used within block
-e: compile error (SyntaxError)
+ ruby -cve 'def b(**) ->(k:, **) {c(**)} end'
ruby 3.3.1 (2024-04-23 revision c56cd86388) [arm64-darwin23]
-e:1: anonymous keyword rest parameter is also used within block
-e: compile error (SyntaxError)
+ echo

+ ruby -cve 'def b(&) ->(&) {c()} end'
ruby 3.3.1 (2024-04-23 revision c56cd86388) [arm64-darwin23]
Syntax OK
+ ruby -cve 'def b(*) ->(*) {c()} end'
ruby 3.3.1 (2024-04-23 revision c56cd86388) [arm64-darwin23]
Syntax OK
+ ruby -cve 'def b(**) ->(**) {c()} end'
ruby 3.3.1 (2024-04-23 revision c56cd86388) [arm64-darwin23]
Syntax OK
+ echo

+ ruby -cve 'def b(&) ->() {c(&)} end'
ruby 3.3.1 (2024-04-23 revision c56cd86388) [arm64-darwin23]
Syntax OK
+ ruby -cve 'def b(*) ->() {c(*)} end'
ruby 3.3.1 (2024-04-23 revision c56cd86388) [arm64-darwin23]
Syntax OK
+ ruby -cve 'def b(a, *) ->() {c(1, *)} end'
ruby 3.3.1 (2024-04-23 revision c56cd86388) [arm64-darwin23]
Syntax OK
+ ruby -cve 'def b(*) ->(a) {c(*)} end'
ruby 3.3.1 (2024-04-23 revision c56cd86388) [arm64-darwin23]
Syntax OK
+ ruby -cve 'def b(**) ->() {c(**)} end'
ruby 3.3.1 (2024-04-23 revision c56cd86388) [arm64-darwin23]
Syntax OK
+ ruby -cve 'def b(k:, **) ->() {c(k: 1, **)} end'
ruby 3.3.1 (2024-04-23 revision c56cd86388) [arm64-darwin23]
Syntax OK
+ ruby -cve 'def b(**) ->(k:) {c(**)} end'
ruby 3.3.1 (2024-04-23 revision c56cd86388) [arm64-darwin23]
Syntax OK

This patch (mirrors 3.3.1, thus also groups 2 and 3 are valid):

Details
+ bin/ruby-parse --33 -e 'def b(&) ->(&) {c(&)} end'
(fragment:0):1:19: error: anonymous block parameter is also used within block
(fragment:0):1: def b(&) ->(&) {c(&)} end
(fragment:0):1:                   ^
+ bin/ruby-parse --33 -e 'def b(*) ->(*) {c(*)} end'
(fragment:0):1:19: error: anonymous rest parameter is also used within block
(fragment:0):1: def b(*) ->(*) {c(*)} end
(fragment:0):1:                   ^
+ bin/ruby-parse --33 -e 'def b(a, *) ->(*) {c(1, *)} end'
(fragment:0):1:25: error: anonymous rest parameter is also used within block
(fragment:0):1: def b(a, *) ->(*) {c(1, *)} end
(fragment:0):1:                         ^
+ bin/ruby-parse --33 -e 'def b(*) ->(a, *) {c(*)} end'
(fragment:0):1:22: error: anonymous rest parameter is also used within block
(fragment:0):1: def b(*) ->(a, *) {c(*)} end
(fragment:0):1:                      ^
+ bin/ruby-parse --33 -e 'def b(**) ->(**) {c(**)} end'
(fragment:0):1:21: error: anonymous keyword rest parameter is also used within block
(fragment:0):1: def b(**) ->(**) {c(**)} end
(fragment:0):1:                     ^~
+ bin/ruby-parse --33 -e 'def b(k:, **) ->(**) {c(k: 1, **)} end'
(fragment:0):1:31: error: anonymous keyword rest parameter is also used within block
(fragment:0):1: def b(k:, **) ->(**) {c(k: 1, **)} end
(fragment:0):1:                               ^~
+ bin/ruby-parse --33 -e 'def b(**) ->(k:, **) {c(**)} end'
(fragment:0):1:25: error: anonymous keyword rest parameter is also used within block
(fragment:0):1: def b(**) ->(k:, **) {c(**)} end
(fragment:0):1:                         ^~
+ echo

+ bin/ruby-parse --33 -e 'def b(&) ->(&) {c()} end'
(def :b
  (args
    (blockarg nil))
  (block
    (lambda)
    (args
      (blockarg nil))
    (send nil :c)))
+ bin/ruby-parse --33 -e 'def b(*) ->(*) {c()} end'
(def :b
  (args
    (restarg))
  (block
    (lambda)
    (args
      (restarg))
    (send nil :c)))
+ bin/ruby-parse --33 -e 'def b(**) ->(**) {c()} end'
(def :b
  (args
    (kwrestarg))
  (block
    (lambda)
    (args
      (kwrestarg))
    (send nil :c)))
+ echo

+ bin/ruby-parse --33 -e 'def b(&) ->() {c(&)} end'
(def :b
  (args
    (blockarg nil))
  (block
    (lambda)
    (args)
    (send nil :c
      (block-pass nil))))
+ bin/ruby-parse --33 -e 'def b(*) ->() {c(*)} end'
(def :b
  (args
    (restarg))
  (block
    (lambda)
    (args)
    (send nil :c
      (forwarded-restarg))))
+ bin/ruby-parse --33 -e 'def b(a, *) ->() {c(1, *)} end'
(def :b
  (args
    (arg :a)
    (restarg))
  (block
    (lambda)
    (args)
    (send nil :c
      (int 1)
      (forwarded-restarg))))
+ bin/ruby-parse --33 -e 'def b(*) ->(a) {c(*)} end'
(def :b
  (args
    (restarg))
  (block
    (lambda)
    (args
      (arg :a))
    (send nil :c
      (forwarded-restarg))))
+ bin/ruby-parse --33 -e 'def b(**) ->() {c(**)} end'
(def :b
  (args
    (kwrestarg))
  (block
    (lambda)
    (args)
    (send nil :c
      (kwargs
        (forwarded-kwrestarg)))))
+ bin/ruby-parse --33 -e 'def b(k:, **) ->() {c(k: 1, **)} end'
(def :b
  (args
    (kwarg :k)
    (kwrestarg))
  (block
    (lambda)
    (args)
    (send nil :c
      (kwargs
        (pair
          (sym :k)
          (int 1))
        (forwarded-kwrestarg)))))
+ bin/ruby-parse --33 -e 'def b(**) ->(k:) {c(**)} end'
(def :b
  (args
    (kwrestarg))
  (block
    (lambda)
    (args
      (kwarg :k))
    (send nil :c
      (kwargs
        (forwarded-kwrestarg)))))

@iliabylich iliabylich merged commit 8af86b0 into whitequark:master Apr 26, 2024
9 checks passed
@iliabylich iliabylich deleted the ruby-bug-19370 branch April 26, 2024 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ruby/ruby@596db9c
1 participant