diff options
| author | Koichi Sasada <ko1@atdot.net> | 2024-04-15 14:22:40 +0900 |
|---|---|---|
| committer | Koichi Sasada <ko1@atdot.net> | 2024-04-15 14:53:41 +0900 |
| commit | 145cced9bcb6a52fccfa0c669121bd07d3b3ff74 (patch) | |
| tree | 6475987e99be7f57c14684e2ac1695388527d706 | |
| parent | b6a10a15180250cef9ec2bacedb71fa392ac0b8d (diff) | |
fix incorrect warning.
`super()` (not zsuper) passes the passed block and
it can be used.
```ruby
class C0
def foo; yield; end
end
class C1 < C0
def foo; super(); end
end
C1.new.foo{p :block} #=> :block
```
| -rw-r--r-- | compile.c | 4 | ||||
| -rw-r--r-- | test/ruby/test_method.rb | 11 |
2 files changed, 10 insertions, 5 deletions
@@ -9372,6 +9372,8 @@ compile_super(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, i INIT_ANCHOR(args); ISEQ_COMPILE_DATA(iseq)->current_block = NULL; + ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->param.flags.use_block = 1; + if (type == NODE_SUPER) { VALUE vargc = setup_args(iseq, args, RNODE_SUPER(node)->nd_args, &flag, &keywords); CHECK(!NIL_P(vargc)); @@ -9382,8 +9384,6 @@ compile_super(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, i } else { /* NODE_ZSUPER */ - ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->param.flags.use_block = 1; - int i; const rb_iseq_t *liseq = body->local_iseq; const struct rb_iseq_constant_body *const local_body = ISEQ_BODY(liseq); diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb index 67b3e03e10..34b58a1f51 100644 --- a/test/ruby/test_method.rb +++ b/test/ruby/test_method.rb @@ -1666,20 +1666,25 @@ class TestMethod < Test::Unit::TestCase def foo = nil def bar = nil def baz = nil + def qux = nil end class C1 < C0 def foo = super def bar = super() def baz(&_) = super(&_) + def qux = super(&nil) end C1.new.foo{} # no warning - C1.new.bar{} # warning + C1.new.bar{} # no warning C1.new.baz{} # no warning + # C1.new.qux{} # TODO: warning line:16 but not supported yet. RUBY - assert_equal 1, err.size - assert_match(/-:14: warning.+bar/, err.join) + assert_equal 0, err.size + # TODO + # assert_equal 1, err.size + # assert_match(/-:16: warning.+qux/, err.join) end end end |
