diff --git a/parse.y b/parse.y index 35de2cc848..c89b8afc8e 100644 --- a/parse.y +++ b/parse.y @@ -6234,6 +6234,7 @@ parser_heredoc_identifier(struct parser_params *parser) int token = tSTRING_BEG; long len; int newline = 0; + int indent = 0; if (c == '-') { c = nextc(); @@ -6242,8 +6243,7 @@ parser_heredoc_identifier(struct parser_params *parser) else if (c == '~') { c = nextc(); func = STR_FUNC_INDENT; - heredoc_indent = INT_MAX; - heredoc_line_indent = 0; + indent = INT_MAX; } switch (c) { case '\'': @@ -6282,7 +6282,7 @@ parser_heredoc_identifier(struct parser_params *parser) if (!parser_is_identchar()) { pushback(c); if (func & STR_FUNC_INDENT) { - pushback(heredoc_indent > 0 ? '~' : '-'); + pushback(indent > 0 ? '~' : '-'); } return 0; } @@ -6305,6 +6305,8 @@ parser_heredoc_identifier(struct parser_params *parser) lex_lastline); /* nd_orig */ parser_set_line(lex_strterm, ruby_sourceline); ripper_flush(parser); + heredoc_indent = indent; + heredoc_line_indent = 0; return token; } diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index f4358d44a1..5cfc13ec89 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -656,6 +656,10 @@ eom assert_equal(expected, actual, bug7559) end + def test_dedented_heredoc_invalid_identifer + assert_syntax_error('<<~ "#{}"', /unexpected <