diff --git a/ast.c b/ast.c index 2ae738f7aa..ead4344be9 100644 --- a/ast.c +++ b/ast.c @@ -96,7 +96,7 @@ rb_ast_parse_str(VALUE str) { rb_ast_t *ast = 0; - str = rb_check_string_type(str); + StringValue(str); ast = rb_parser_compile_string_path(ast_parse_new(), Qnil, str, 1); return ast_parse_done(ast); } diff --git a/test/ruby/test_ast.rb b/test/ruby/test_ast.rb index ed4bcb37c0..d57b60b3f7 100644 --- a/test/ruby/test_ast.rb +++ b/test/ruby/test_ast.rb @@ -134,6 +134,14 @@ class TestAst < Test::Unit::TestCase assert_raise(TypeError) {RubyVM::AbstractSyntaxTree::Node.allocate} end + def test_parse_argument_error + assert_raise(TypeError) {RubyVM::AbstractSyntaxTree.parse(0)} + assert_raise(TypeError) {RubyVM::AbstractSyntaxTree.parse(nil)} + assert_raise(TypeError) {RubyVM::AbstractSyntaxTree.parse(false)} + assert_raise(TypeError) {RubyVM::AbstractSyntaxTree.parse(true)} + assert_raise(TypeError) {RubyVM::AbstractSyntaxTree.parse(:foo)} + end + def test_column_with_long_heredoc_identifier term = "A"*257 ast = RubyVM::AbstractSyntaxTree.parse("<<-#{term}\n""ddddddd\n#{term}\n")