Project

General

Profile

Bug #14690 ยป cmdarg_in_command_args_followed_by_tlbrace_arg.patch

ibylich (Ilya Bylich), 04/16/2018 12:31 PM

View differences:

parse.y
2170 2170
		    }
2171 2171
		  call_args
2172 2172
		    {
2173
			/* call_args can be followed by tLBRACE_ARG (that does CMDARG_PUSH(0) in the lexer)
2174
			 * but the push must be done after CMDARG_POP() in the parser.
2175
			 * So this code does CMDARG_POP() to pop 0 pushed by tLBRACE_ARG,
2176
			 * CMDARG_POP() to pop 1 pushed by command_args,
2177
			 * and CMDARG_PUSH(0) to restore back the flag set by tLBRACE_ARG.
2178
			 */
2179
			int lookahead = 0;
2180
			switch(yychar) {
2181
			  case tLBRACE_ARG:
2182
			    lookahead = 1;
2183
			}
2184
			if (lookahead) CMDARG_POP();
2173 2185
			CMDARG_POP();
2186
			if (lookahead) CMDARG_PUSH(0);
2174 2187
			$$ = $2;
2175 2188
		    }
2176 2189
		;
test/ruby/test_parse.rb
1196 1196
    end
1197 1197
  end
1198 1198

  
1199
  def test_cdmarg_after_command_args_and_tlbrace_arg
1200
    assert_valid_syntax('let () { m(a) do; end }')
1201
  end
1202

  
1199 1203
=begin
1200 1204
  def test_past_scope_variable
1201 1205
    assert_warning(/past scope/) {catch {|tag| eval("BEGIN{throw tag}; tap {a = 1}; a")}}