[Bug #19918] Reject block passing in index
This commit is contained in:
parent
3605d6076d
commit
df5ef28233
@ -340,24 +340,6 @@ assert_equal '1', %q( class C; def m() 7 end; private :m end
|
|||||||
assert_equal '1', %q( class C; def m() 1 end; private :m end
|
assert_equal '1', %q( class C; def m() 1 end; private :m end
|
||||||
C.new.send(:m) )
|
C.new.send(:m) )
|
||||||
|
|
||||||
# with block
|
|
||||||
assert_equal '[[:ok1, :foo], [:ok2, :foo, :bar]]',
|
|
||||||
%q{
|
|
||||||
class C
|
|
||||||
def [](a)
|
|
||||||
$ary << [yield, a]
|
|
||||||
end
|
|
||||||
def []=(a, b)
|
|
||||||
$ary << [yield, a, b]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
$ary = []
|
|
||||||
C.new[:foo, &lambda{:ok1}]
|
|
||||||
C.new[:foo, &lambda{:ok2}] = :bar
|
|
||||||
$ary
|
|
||||||
}
|
|
||||||
|
|
||||||
# with
|
# with
|
||||||
assert_equal '[:ok1, [:ok2, 11]]', %q{
|
assert_equal '[:ok1, [:ok2, 11]]', %q{
|
||||||
class C
|
class C
|
||||||
@ -404,7 +386,6 @@ $result
|
|||||||
|
|
||||||
# aset and splat
|
# aset and splat
|
||||||
assert_equal '4', %q{class Foo;def []=(a,b,c,d);end;end;Foo.new[1,*a=[2,3]]=4}
|
assert_equal '4', %q{class Foo;def []=(a,b,c,d);end;end;Foo.new[1,*a=[2,3]]=4}
|
||||||
assert_equal '4', %q{class Foo;def []=(a,b,c,d);end;end;def m(&blk)Foo.new[1,*a=[2,3],&blk]=4;end;m{}}
|
|
||||||
|
|
||||||
# post test
|
# post test
|
||||||
assert_equal %q{[1, 2, :o1, :o2, [], 3, 4, NilClass, nil, nil]}, %q{
|
assert_equal %q{[1, 2, :o1, :o2, [], 3, 4, NilClass, nil, nil]}, %q{
|
||||||
|
3
parse.y
3
parse.y
@ -13875,6 +13875,9 @@ new_bv(struct parser_params *p, ID name)
|
|||||||
static NODE *
|
static NODE *
|
||||||
aryset(struct parser_params *p, NODE *recv, NODE *idx, const YYLTYPE *loc)
|
aryset(struct parser_params *p, NODE *recv, NODE *idx, const YYLTYPE *loc)
|
||||||
{
|
{
|
||||||
|
if (idx && nd_type_p(idx, NODE_BLOCK_PASS)) {
|
||||||
|
compile_error(p, "block arg given in index");
|
||||||
|
}
|
||||||
return NEW_ATTRASGN(recv, tASET, idx, loc);
|
return NEW_ATTRASGN(recv, tASET, idx, loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,13 +81,13 @@ foo[bar] = baz
|
|||||||
|
|
||||||
%w[\C:]
|
%w[\C:]
|
||||||
|
|
||||||
foo[&bar] = 1
|
# foo[&bar] = 1
|
||||||
|
|
||||||
foo.foo[&bar] = 1
|
# foo.foo[&bar] = 1
|
||||||
|
|
||||||
def foo(&)
|
# def foo(&)
|
||||||
bar[&] = 1
|
# bar[&] = 1
|
||||||
end
|
# end
|
||||||
|
|
||||||
foo[] += 1
|
foo[] += 1
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
├── locals: []
|
├── locals: []
|
||||||
└── statements:
|
└── statements:
|
||||||
@ StatementsNode (location: (1,0)-(142,32))
|
@ StatementsNode (location: (1,0)-(142,32))
|
||||||
└── body: (length: 59)
|
└── body: (length: 56)
|
||||||
├── @ ArrayNode (location: (1,0)-(1,4))
|
├── @ ArrayNode (location: (1,0)-(1,4))
|
||||||
│ ├── flags: contains_splat
|
│ ├── flags: contains_splat
|
||||||
│ ├── elements: (length: 1)
|
│ ├── elements: (length: 1)
|
||||||
@ -942,151 +942,6 @@
|
|||||||
│ │ └── unescaped: "\\C:"
|
│ │ └── unescaped: "\\C:"
|
||||||
│ ├── opening_loc: (82,0)-(82,3) = "%w["
|
│ ├── opening_loc: (82,0)-(82,3) = "%w["
|
||||||
│ └── closing_loc: (82,6)-(82,7) = "]"
|
│ └── 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))
|
├── @ IndexOperatorWriteNode (location: (92,0)-(92,10))
|
||||||
│ ├── flags: ∅
|
│ ├── flags: ∅
|
||||||
│ ├── receiver:
|
│ ├── receiver:
|
||||||
|
@ -2012,24 +2012,6 @@ end
|
|||||||
obj[*[1]] = 3
|
obj[*[1]] = 3
|
||||||
RUBY
|
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)
|
assert_prism_eval(<<-CODE)
|
||||||
def self.prism_opt_var_trail_hash(a = nil, *b, c, **d); end
|
def self.prism_opt_var_trail_hash(a = nil, *b, c, **d); end
|
||||||
prism_opt_var_trail_hash("a")
|
prism_opt_var_trail_hash("a")
|
||||||
|
@ -916,20 +916,6 @@ x = __ENCODING__
|
|||||||
assert_syntax_error("$& = 1", /Can't set variable/)
|
assert_syntax_error("$& = 1", /Can't set variable/)
|
||||||
end
|
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
|
def test_void_expr_stmts_value
|
||||||
x = 1
|
x = 1
|
||||||
useless_use = /useless use/
|
useless_use = /useless use/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user