Skip to content

Commit 5eb3ef3

Browse files
committed
Add a fallback for check_code_block that does not depend on implementation-private APIs
* Fixes #133
1 parent 11e58e0 commit 5eb3ef3

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/irb/ruby-lex.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,16 @@ def check_code_block(code)
222222
begin # check if parser error are available
223223
verbose, $VERBOSE = $VERBOSE, nil
224224
case RUBY_ENGINE
225+
when 'ruby'
226+
self.class.compile_with_errors_suppressed(code) do |inner_code, line_no|
227+
RubyVM::InstructionSequence.compile(inner_code, nil, nil, line_no)
228+
end
225229
when 'jruby'
226230
JRuby.compile_ir(code)
227231
else
228-
self.class.compile_with_errors_suppressed(code) do |inner_code, line_no|
229-
RubyVM::InstructionSequence.compile(inner_code, nil, nil, line_no)
232+
catch(:valid) do
233+
eval("BEGIN { throw :valid, true }\n#{code}")
234+
false
230235
end
231236
end
232237
rescue EncodingError

0 commit comments

Comments
 (0)