summaryrefslogtreecommitdiff
path: root/lib/irb/ruby-lex.rb
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2020-11-05 18:08:04 +0100
committeraycabta <aycabta@gmail.com>2020-11-22 21:00:11 +0900
commitafb8aba4af923350cfe0a0ae4b4895d5a837e799 (patch)
treede6c9f3b68e23e9008647e2d28b837700eb49e0c /lib/irb/ruby-lex.rb
parent5218f17737594867ffe5c2cd9c90b19c7378af05 (diff)
[ruby/irb] Add a fallback for check_code_block that does not depend on implementation-private APIs
* Fixes https://github.com/ruby/irb/issues/133 https://github.com/ruby/irb/commit/5eb3ef3293
Diffstat (limited to 'lib/irb/ruby-lex.rb')
-rw-r--r--lib/irb/ruby-lex.rb9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb
index c75d5ebf2e..51efc17433 100644
--- a/lib/irb/ruby-lex.rb
+++ b/lib/irb/ruby-lex.rb
@@ -222,11 +222,16 @@ class RubyLex
begin # check if parser error are available
verbose, $VERBOSE = $VERBOSE, nil
case RUBY_ENGINE
+ when 'ruby'
+ self.class.compile_with_errors_suppressed(code) do |inner_code, line_no|
+ RubyVM::InstructionSequence.compile(inner_code, nil, nil, line_no)
+ end
when 'jruby'
JRuby.compile_ir(code)
else
- self.class.compile_with_errors_suppressed(code) do |inner_code, line_no|
- RubyVM::InstructionSequence.compile(inner_code, nil, nil, line_no)
+ catch(:valid) do
+ eval("BEGIN { throw :valid, true }\n#{code}")
+ false
end
end
rescue EncodingError