summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2024-01-18 19:27:09 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2024-03-17 13:18:37 +0900
commitdf5ef282337764508a1e1d93459d7a280e46647c (patch)
tree4145697f9093d0b8a348cff0ee5b3e3e5f55fe52 /test
parent3605d6076dab516c7b483a8be6038d5b6da1845a (diff)
[Bug #19918] Reject block passing in index
Diffstat (limited to 'test')
-rw-r--r--test/prism/fixtures/arrays.txt10
-rw-r--r--test/prism/snapshots/arrays.txt147
-rw-r--r--test/ruby/test_compile_prism.rb18
-rw-r--r--test/ruby/test_parse.rb14
4 files changed, 6 insertions, 183 deletions
diff --git a/test/prism/fixtures/arrays.txt b/test/prism/fixtures/arrays.txt
index cd4e3046f7..6cb0c25e60 100644
--- a/test/prism/fixtures/arrays.txt
+++ b/test/prism/fixtures/arrays.txt
@@ -81,13 +81,13 @@ foo[bar] = baz
%w[\C:]
-foo[&bar] = 1
+# foo[&bar] = 1
-foo.foo[&bar] = 1
+# foo.foo[&bar] = 1
-def foo(&)
- bar[&] = 1
-end
+# def foo(&)
+# bar[&] = 1
+# end
foo[] += 1
diff --git a/test/prism/snapshots/arrays.txt b/test/prism/snapshots/arrays.txt
index 1cf6b22697..a2392f37e2 100644
--- a/test/prism/snapshots/arrays.txt
+++ b/test/prism/snapshots/arrays.txt
@@ -2,7 +2,7 @@
├── locals: []
└── statements:
@ StatementsNode (location: (1,0)-(142,32))
- └── body: (length: 59)
+ └── body: (length: 56)
├── @ ArrayNode (location: (1,0)-(1,4))
│ ├── flags: contains_splat
│ ├── elements: (length: 1)
@@ -942,151 +942,6 @@
│ │ └── unescaped: "\\C:"
│ ├── opening_loc: (82,0)-(82,3) = "%w["
│ └── closing_loc: (82,6)-(82,7) = "]"
- ├── @ CallNode (location: (84,0)-(84,13))
- │ ├── flags: attribute_write
- │ ├── receiver:
- │ │ @ CallNode (location: (84,0)-(84,3))
- │ │ ├── flags: variable_call, ignore_visibility
- │ │ ├── receiver: ∅
- │ │ ├── call_operator_loc: ∅
- │ │ ├── name: :foo
- │ │ ├── message_loc: (84,0)-(84,3) = "foo"
- │ │ ├── opening_loc: ∅
- │ │ ├── arguments: ∅
- │ │ ├── closing_loc: ∅
- │ │ └── block: ∅
- │ ├── call_operator_loc: ∅
- │ ├── name: :[]=
- │ ├── message_loc: (84,3)-(84,9) = "[&bar]"
- │ ├── opening_loc: (84,3)-(84,4) = "["
- │ ├── arguments:
- │ │ @ ArgumentsNode (location: (84,12)-(84,13))
- │ │ ├── flags: ∅
- │ │ └── arguments: (length: 1)
- │ │ └── @ IntegerNode (location: (84,12)-(84,13))
- │ │ ├── flags: decimal
- │ │ └── value: 1
- │ ├── closing_loc: (84,8)-(84,9) = "]"
- │ └── block:
- │ @ BlockArgumentNode (location: (84,4)-(84,8))
- │ ├── expression:
- │ │ @ CallNode (location: (84,5)-(84,8))
- │ │ ├── flags: variable_call, ignore_visibility
- │ │ ├── receiver: ∅
- │ │ ├── call_operator_loc: ∅
- │ │ ├── name: :bar
- │ │ ├── message_loc: (84,5)-(84,8) = "bar"
- │ │ ├── opening_loc: ∅
- │ │ ├── arguments: ∅
- │ │ ├── closing_loc: ∅
- │ │ └── block: ∅
- │ └── operator_loc: (84,4)-(84,5) = "&"
- ├── @ CallNode (location: (86,0)-(86,17))
- │ ├── flags: attribute_write
- │ ├── receiver:
- │ │ @ CallNode (location: (86,0)-(86,7))
- │ │ ├── flags: ∅
- │ │ ├── receiver:
- │ │ │ @ CallNode (location: (86,0)-(86,3))
- │ │ │ ├── flags: variable_call, ignore_visibility
- │ │ │ ├── receiver: ∅
- │ │ │ ├── call_operator_loc: ∅
- │ │ │ ├── name: :foo
- │ │ │ ├── message_loc: (86,0)-(86,3) = "foo"
- │ │ │ ├── opening_loc: ∅
- │ │ │ ├── arguments: ∅
- │ │ │ ├── closing_loc: ∅
- │ │ │ └── block: ∅
- │ │ ├── call_operator_loc: (86,3)-(86,4) = "."
- │ │ ├── name: :foo
- │ │ ├── message_loc: (86,4)-(86,7) = "foo"
- │ │ ├── opening_loc: ∅
- │ │ ├── arguments: ∅
- │ │ ├── closing_loc: ∅
- │ │ └── block: ∅
- │ ├── call_operator_loc: ∅
- │ ├── name: :[]=
- │ ├── message_loc: (86,7)-(86,13) = "[&bar]"
- │ ├── opening_loc: (86,7)-(86,8) = "["
- │ ├── arguments:
- │ │ @ ArgumentsNode (location: (86,16)-(86,17))
- │ │ ├── flags: ∅
- │ │ └── arguments: (length: 1)
- │ │ └── @ IntegerNode (location: (86,16)-(86,17))
- │ │ ├── flags: decimal
- │ │ └── value: 1
- │ ├── closing_loc: (86,12)-(86,13) = "]"
- │ └── block:
- │ @ BlockArgumentNode (location: (86,8)-(86,12))
- │ ├── expression:
- │ │ @ CallNode (location: (86,9)-(86,12))
- │ │ ├── flags: variable_call, ignore_visibility
- │ │ ├── receiver: ∅
- │ │ ├── call_operator_loc: ∅
- │ │ ├── name: :bar
- │ │ ├── message_loc: (86,9)-(86,12) = "bar"
- │ │ ├── opening_loc: ∅
- │ │ ├── arguments: ∅
- │ │ ├── closing_loc: ∅
- │ │ └── block: ∅
- │ └── operator_loc: (86,8)-(86,9) = "&"
- ├── @ DefNode (location: (88,0)-(90,3))
- │ ├── name: :foo
- │ ├── name_loc: (88,4)-(88,7) = "foo"
- │ ├── receiver: ∅
- │ ├── parameters:
- │ │ @ ParametersNode (location: (88,8)-(88,9))
- │ │ ├── requireds: (length: 0)
- │ │ ├── optionals: (length: 0)
- │ │ ├── rest: ∅
- │ │ ├── posts: (length: 0)
- │ │ ├── keywords: (length: 0)
- │ │ ├── keyword_rest: ∅
- │ │ └── block:
- │ │ @ BlockParameterNode (location: (88,8)-(88,9))
- │ │ ├── flags: ∅
- │ │ ├── name: ∅
- │ │ ├── name_loc: ∅
- │ │ └── operator_loc: (88,8)-(88,9) = "&"
- │ ├── body:
- │ │ @ StatementsNode (location: (89,2)-(89,12))
- │ │ └── body: (length: 1)
- │ │ └── @ CallNode (location: (89,2)-(89,12))
- │ │ ├── flags: attribute_write
- │ │ ├── receiver:
- │ │ │ @ CallNode (location: (89,2)-(89,5))
- │ │ │ ├── flags: variable_call, ignore_visibility
- │ │ │ ├── receiver: ∅
- │ │ │ ├── call_operator_loc: ∅
- │ │ │ ├── name: :bar
- │ │ │ ├── message_loc: (89,2)-(89,5) = "bar"
- │ │ │ ├── opening_loc: ∅
- │ │ │ ├── arguments: ∅
- │ │ │ ├── closing_loc: ∅
- │ │ │ └── block: ∅
- │ │ ├── call_operator_loc: ∅
- │ │ ├── name: :[]=
- │ │ ├── message_loc: (89,5)-(89,8) = "[&]"
- │ │ ├── opening_loc: (89,5)-(89,6) = "["
- │ │ ├── arguments:
- │ │ │ @ ArgumentsNode (location: (89,11)-(89,12))
- │ │ │ ├── flags: ∅
- │ │ │ └── arguments: (length: 1)
- │ │ │ └── @ IntegerNode (location: (89,11)-(89,12))
- │ │ │ ├── flags: decimal
- │ │ │ └── value: 1
- │ │ ├── closing_loc: (89,7)-(89,8) = "]"
- │ │ └── block:
- │ │ @ BlockArgumentNode (location: (89,6)-(89,7))
- │ │ ├── expression: ∅
- │ │ └── operator_loc: (89,6)-(89,7) = "&"
- │ ├── locals: []
- │ ├── def_keyword_loc: (88,0)-(88,3) = "def"
- │ ├── operator_loc: ∅
- │ ├── lparen_loc: (88,7)-(88,8) = "("
- │ ├── rparen_loc: (88,9)-(88,10) = ")"
- │ ├── equal_loc: ∅
- │ └── end_keyword_loc: (90,0)-(90,3) = "end"
├── @ IndexOperatorWriteNode (location: (92,0)-(92,10))
│ ├── flags: ∅
│ ├── receiver:
diff --git a/test/ruby/test_compile_prism.rb b/test/ruby/test_compile_prism.rb
index 3dbc634828..65f1d96f97 100644
--- a/test/ruby/test_compile_prism.rb
+++ b/test/ruby/test_compile_prism.rb
@@ -2012,24 +2012,6 @@ end
obj[*[1]] = 3
RUBY
- # Test passing block inside of []=
- assert_prism_eval(<<~RUBY)
- obj = Object.new
- def obj.[]=(a); end
-
- p = proc {}
- obj[&p] = 4
- RUBY
-
- # Test splat and block inside of []=
- assert_prism_eval(<<~RUBY)
- obj = Object.new
- def obj.[]=(a, b); end
-
- p = proc {}
- obj[*[1], &p] = 4
- RUBY
-
assert_prism_eval(<<-CODE)
def self.prism_opt_var_trail_hash(a = nil, *b, c, **d); end
prism_opt_var_trail_hash("a")
diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb
index a8abccb1f9..051fac274f 100644
--- a/test/ruby/test_parse.rb
+++ b/test/ruby/test_parse.rb
@@ -916,20 +916,6 @@ x = __ENCODING__
assert_syntax_error("$& = 1", /Can't set variable/)
end
- def test_arg_concat
- o = Object.new
- class << o; self; end.instance_eval do
- define_method(:[]=) {|*r, &b| b.call(r) }
- end
- r = nil
- assert_nothing_raised do
- eval <<-END, nil, __FILE__, __LINE__+1
- o[&proc{|x| r = x }] = 1
- END
- end
- assert_equal([1], r)
- end
-
def test_void_expr_stmts_value
x = 1
useless_use = /useless use/