@@ -698,11 +698,17 @@ void blockBody(Lexer* l, method_generation_context* mgenc, bool seen_period) {
698
698
if (accept (l , Exit ))
699
699
result (l , mgenc );
700
700
else if (l -> sym == EndBlock ) {
701
- if (seen_period )
701
+ if (seen_period ) {
702
702
// a POP has been generated which must be elided (blocks always
703
703
// return the value of the last expression, regardless of whether it
704
704
// was terminated with a . or not)
705
705
mgenc -> bp -- ;
706
+ }
707
+ if (mgenc -> block_method && !method_genc_has_bytecodes (mgenc )) {
708
+ pVMSymbol nilSym = Universe_symbol_for_cstr ("nil" );
709
+ SEND (mgenc -> literals , addIfAbsent , nilSym );
710
+ emit_PUSH_GLOBAL (mgenc , nilSym );
711
+ }
706
712
emit_RETURN_LOCAL (mgenc );
707
713
mgenc -> finished = true;
708
714
} else if (l -> sym == EndTerm ) {
@@ -1118,7 +1124,12 @@ void nestedBlock(Lexer* l, method_generation_context* mgenc) {
1118
1124
1119
1125
// if no return has been generated, we can be sure that the last expression
1120
1126
// in the block was not terminated by ., and can generate a return
1121
- if (!mgenc -> finished ) {
1127
+ if (!mgenc -> finished ) {
1128
+ if (!method_genc_has_bytecodes (mgenc )) {
1129
+ pVMSymbol nilSym = Universe_symbol_for_cstr ("nil" );
1130
+ SEND (mgenc -> literals , addIfAbsent , nilSym );
1131
+ emit_PUSH_GLOBAL (mgenc , nilSym );
1132
+ }
1122
1133
emit_RETURN_LOCAL (mgenc );
1123
1134
mgenc -> finished = true;
1124
1135
}
0 commit comments