From: Mikael Brockman Date: 2004-06-27T03:11:17+09:00 Subject: Re: 1.8.2: Segfault / Addition Elven writes: > > E> Just run the code: > E> if false begin > E> end > > Sorry, i was being overly stupid; i pasted the wrong code snippet. > It should be: > > return false if begin > end The culprit is that `begin end' creates a begin NODE whose nd_body is 0. All conditionals use expr_value, which replaces the top of the parse stack with the node's nd_body. So you'll see a segfault for any conditional involving an empty begin-end. I'm not sure if this is the proper way to fix things -- this is actually the first time I've looked at the Ruby source -- but this prevents nullary begins being created by setting such bodies to nil instead. --- parse.y 25 May 2004 02:54:21 -0000 1.326 +++ parse.y 26 Jun 2004 18:10:25 -0000 @@ -1448,7 +1448,10 @@ bodystmt kEND { - $$ = NEW_BEGIN($3); + if ($3 == NULL) + $$ = NEW_NIL(); + else + $$ = NEW_BEGIN($3); nd_set_line($$, $1); } | tLPAREN_ARG expr {lex_state = EXPR_ENDARG;} rparen mikael