Professional Web Applications Themes

1.8.0 change to super and nil block argument - Ruby

A slight surprise: class A def foo x yield if block_given? end end class B < A def foo x super(x, &nil) # super(x) {} end end B.new.foo(3) {puts "Executed block!"} This code now causes the block to be executed. $ ruby-1.7.3 change.rb $ ruby-1.8.0 change.rb Executed block! If you use the commented super-call instead, neither case executes the block. I didn't see this in the change docs. It's not a big problem for this code, since I know the block passed to super should be empty, But I can imagine it would be a problem when the block is ...

  1. #1

    Default 1.8.0 change to super and nil block argument


    A slight surprise:

    class A
    def foo x
    yield if block_given?
    end
    end

    class B < A
    def foo x
    super(x, &nil)
    # super(x) {}
    end
    end

    B.new.foo(3) {puts "Executed block!"}

    This code now causes the block to be executed.

    $ ruby-1.7.3 change.rb
    $ ruby-1.8.0 change.rb
    Executed block!

    If you use the commented super-call instead, neither case executes the
    block.

    I didn't see this in the change docs.

    It's not a big problem for this code, since I know the block passed to
    super should be empty,

    But I can imagine it would be a problem when the block is in some variable:

    def foo
    bl = get_a_block_maybe()
    super(x, &bl)
    end

    Since bl may be nil or not, you have strange behavior. If bl == nil,
    then the wrong block is propagated to super.


    Joel VanderWerf Guest

  2. #2

    Default Re: 1.8.0 change to super and nil block argument

    Hi,

    In message "1.8.0 change to super and nil block argument"
    on 03/08/11, Joel VanderWerf <vjoelPATH.Berkeley.EDU> writes:
    |A slight surprise:

    You've found a bug. Thanks.

    matz.

    --- eval.c 7 Aug 2003 04:09:56 -0000 1.509
    +++ eval.c 11 Aug 2003 08:40:25 -0000
    -1963,6 +1963,8 copy_node_scope(node, rval)
    struct BLOCK *tmp_block = ruby_block;\
    - if (ruby_iter->iter == ITER_PRE) {\
    + int tmp_iter = ruby_iter->iter;\
    + if (tmp_iter == ITER_PRE) {\
    ruby_block = ruby_block->outer;\
    + tmp_iter = ITER_NOT;\
    }\
    - PUSH_ITER(ITER_NOT)
    + PUSH_ITER(tmp_iter)

    -5241,3 +5243,3 rb_call_super(argc, argv)

    - PUSH_ITER(ruby_iter->iter || rb_block_given_p() ? ITER_PRE : ITER_NOT);
    + PUSH_ITER(ruby_iter->iter ? ITER_PRE : ITER_NOT);
    result = rb_call(RCLASS(klass)->super, self, ruby_frame->orig_func, argc, argv, 3);

    Yukihiro Matsumoto Guest

Similar Threads

  1. ViewStack index change block other events?
    By drkshih in forum Macromedia Flex General Discussion
    Replies: 2
    Last Post: July 19th, 04:43 PM
  2. how to block change event of data grid
    By leimin3113591 in forum Macromedia Flex General Discussion
    Replies: 2
    Last Post: April 11th, 01:59 AM
  3. Replies: 2
    Last Post: August 3rd, 03:04 PM
  4. Bad magic number in super-block (urgent advice needed)
    By Loren Coe in forum Linux Setup, Configuration & Administration
    Replies: 3
    Last Post: July 3rd, 12:35 PM
  5. How to change partition number & block size
    By spagi in forum Linux Setup, Configuration & Administration
    Replies: 8
    Last Post: June 28th, 12:51 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139