比较以下场景(它们是相同的,但结果不同):
首先我会在ruby(cruby)
上做~> irb
irb(main):001:0> begin
irb(main):002:1* begin
irb(main):003:2* puts 1
irb(main):004:2> next
irb(main):005:2> end
irb(main):006:1> puts 2
irb(main):007:1> end
SyntaxError: (irb):4: Can't escape from eval with next
现在同样的事情在jruby:
~> jirb
irb(main):001:0> begin
irb(main):002:1* begin
irb(main):003:2* puts 1
irb(main):004:2> next
irb(main):005:2> end
irb(main):006:1> puts 2
irb(main):007:1> end
1
=> nil
为什么这不会像在cruby上那样在jruby上失败?这是一个犹豫不决的虫子吗?
答案 0 :(得分:1)
我将此归档为Bug #13064。
我在各种版本的YARV以及JRuby,MRuby和Rubinius的最新版本中测试了您的代码:
YARV 2.2.0(使用macOS进行构建)
<ion-content>
<ion-list>
<ion-item *ngFor="let item of array">{{item.name}}</ion-item>
</ion-list>
</ion-content>
<ion-footer>
<ion-searchbar (ionInput)="search()"></ion-searchbar>
</ion-footer>
YARV 2.3.1(JRuby声称此版本兼容)
# ruby -v -W -e 'begin; begin puts 1; next end; puts 2 end'
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]
-e:1: warning: statement not reached
-e:1: Invalid next
-e: compile error (SyntaxError)
# irb -f -d -w -W
irb(main):001:0> p RUBY_VERSION
"2.0.0"
=> "2.0.0"
irb(main):002:0> p RUBY_ENGINE
"ruby"
=> "ruby"
irb(main):003:0>
irb(main):004:0* begin
irb(main):005:1* begin
irb(main):006:2* puts 1
irb(main):007:2> next
irb(main):008:2> end
irb(main):009:1> puts 2
irb(main):010:1> end
(irb):9: warning: statement not reached
Exception `SyntaxError' at /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/irb/workspace.rb:86 - (irb):7: Can't escape from eval with next
Exception `SyntaxError' at /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/irb/workspace.rb:86 - (irb):7: Can't escape from eval with next
SyntaxError: (irb):7: Can't escape from eval with next
from (irb)
irb(main):011:0>
irb(main):012:0* exit
YARV 2.3.3
# ruby -v -W -e 'begin; begin puts 1; next end; puts 2 end'
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin16]
-e:1: warning: statement not reached
-e: -e:1: Invalid next (SyntaxError)
# irb -f -d -w -W
irb(main):001:0> p RUBY_VERSION
"2.3.1"
=> "2.3.1"
irb(main):002:0> p RUBY_ENGINE
"ruby"
=> "ruby"
irb(main):003:0>
irb(main):004:0* begin
irb(main):005:1* begin
irb(main):006:2* puts 1
irb(main):007:2> next
irb(main):008:2> end
irb(main):009:1> puts 2
irb(main):010:1> end
(irb):9: warning: statement not reached
Exception `SyntaxError' at /Users/joerg/.rbenv/versions/2.3.1/lib/ruby/2.3.0/irb/workspace.rb:87 - (irb):7: Can't escape from eval with next
Exception `SyntaxError' at /Users/joerg/.rbenv/versions/2.3.1/lib/ruby/2.3.0/irb/workspace.rb:87 - (irb):7: Can't escape from eval with next
Exception `SyntaxError' at /Users/joerg/.rbenv/versions/2.3.1/lib/ruby/2.3.0/irb/workspace.rb:87 - (irb):7: Can't escape from eval with next
SyntaxError: (irb):7: Can't escape from eval with next
from (irb)
irb(main):011:0>
irb(main):012:0* exit
YARV 2.4.0-preview3:
# ruby -v -W -e 'begin; begin puts 1; next end; puts 2 end'
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin16]
-e:1: warning: statement not reached
-e: -e:1: Invalid next (SyntaxError)
# irb -f -d -w -W
irb(main):001:0> p RUBY_VERSION
"2.3.3"
=> "2.3.3"
irb(main):002:0> p RUBY_ENGINE
"ruby"
=> "ruby"
irb(main):003:0>
irb(main):004:0* begin
irb(main):005:1* begin
irb(main):006:2* puts 1
irb(main):007:2> next
irb(main):008:2> end
irb(main):009:1> puts 2
irb(main):010:1> end
(irb):9: warning: statement not reached
Exception `SyntaxError' at /Users/joerg/.rbenv/versions/2.3.3/lib/ruby/2.3.0/irb/workspace.rb:87 - (irb):7: Can't escape from eval with next
Exception `SyntaxError' at /Users/joerg/.rbenv/versions/2.3.3/lib/ruby/2.3.0/irb/workspace.rb:87 - (irb):7: Can't escape from eval with next
Exception `SyntaxError' at /Users/joerg/.rbenv/versions/2.3.3/lib/ruby/2.3.0/irb/workspace.rb:87 - (irb):7: Can't escape from eval with next
SyntaxError: (irb):7: Can't escape from eval with next
from (irb)
irb(main):011:0>
irb(main):012:0* exit
YARV 2.4.0-dev(截至昨天的当前SVN主干):
# ruby -v -W -e 'begin; begin puts 1; next end; puts 2 end'
ruby 2.4.0preview3 (2016-11-07 trunk 56661) [x86_64-darwin16]
-e:1: warning: statement not reached
-e: -e:1: Invalid next (SyntaxError)
# irb -f -d -w -W
irb(main):001:0> p RUBY_VERSION
"2.4.0"
=> "2.4.0"
irb(main):002:0> p RUBY_ENGINE
"ruby"
=> "ruby"
irb(main):003:0>
irb(main):004:0* begin
irb(main):005:1* begin
irb(main):006:2* puts 1
irb(main):007:2> next
irb(main):008:2> end
irb(main):009:1> puts 2
irb(main):010:1> end
(irb):9: warning: statement not reached
Exception `SyntaxError' at /Users/joerg/.rbenv/versions/2.4.0-preview3/lib/ruby/2.4.0/irb/workspace.rb:87 - (irb):7: Can't escape from eval with next
SyntaxError: (irb):7: Can't escape from eval with next
from (irb)
irb(main):011:0>
irb(main):012:0* exit
Rubinius 3.69
# ruby -v -W -e 'begin; begin puts 1; next end; puts 2 end'
ruby 2.4.0dev (2016-12-22 trunk 57151) [x86_64-darwin16]
-e:1: warning: statement not reached
-e: -e:1: Invalid next (SyntaxError)
# irb -f -d -w -W
irb(main):001:0> p RUBY_VERSION
"2.4.0"
=> "2.4.0"
irb(main):002:0> p RUBY_ENGINE
"ruby"
=> "ruby"
irb(main):003:0>
irb(main):004:0* begin
irb(main):005:1* begin
irb(main):006:2* puts 1
irb(main):007:2> next
irb(main):008:2> end
irb(main):009:1> puts 2
irb(main):010:1> end
(irb):9: warning: statement not reached
Exception `SyntaxError' at /Users/joerg/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb/workspace.rb:87 - (irb):7: Can't escape from eval with next
SyntaxError: (irb):7: Can't escape from eval with next
from (irb)
irb(main):011:0>
irb(main):012:0* exit
JRuby 9.1.6.0(最新版本)
# rbx -v -W -e 'begin; begin puts 1; next end; puts 2 end'
rubinius 3.69 (2.3.1 a57071c6 2016-11-17 3.8.1) [x86_64-darwin15.6.0]
1
main # Rubinius::Loader at core/loader.rb:860
evals # Rubinius::Loader at core/loader.rb:646
eval # Kernel(Rubinius::Loader) at core/kernel.rb:1130
call_on_instance # Rubinius::BlockEnvironment at core/block_environment.rb:147
{ } in __script__ # Object at -e:1
jump_error . Rubinius at core/rubinius.rb:279
invalid context for 'next' (LocalJumpError)
An exception occurred evaluating command line code
# irb
irb(main):001:0> p RUBY_VERSION
"2.3.1"
=> "2.3.1"
irb(main):002:0> p RUBY_ENGINE
"rbx"
=> "rbx"
irb(main):003:0>
irb(main):004:0* begin
irb(main):005:1* begin
irb(main):006:2* puts 1
irb(main):007:2> next
irb(main):008:2> end
irb(main):009:1> puts 2
irb(main):010:1> end
1
LocalJumpError: invalid context for 'next'
from core/rubinius.rb:279:in `jump_error'
from (irb):7
from core/block_environment.rb:147:in `call_on_instance'
from core/kernel.rb:1130:in `eval'
from core/kernel.rb:585:in `loop'
from core/proc.rb:20:in `call'
from core/kernel.rb:1067:in `catch'
from core/throw_catch.rb:8:in `register'
from core/kernel.rb:1066:in `catch'
from core/proc.rb:20:in `call'
from core/kernel.rb:1067:in `catch'
from core/throw_catch.rb:8:in `register'
from core/kernel.rb:1066:in `catch'
from core/code_loader.rb:505:in `load_script'
from core/code_loader.rb:590:in `load_script'
from core/loader.rb:679:in `script'
from core/loader.rb:861:in `main'irb(main):011:0>
irb(main):012:0* exit
MRuby 1.2.0(由matz自己编写的最低ISO兼容的Ruby实现)
# jruby -v -W -e 'begin; begin puts 1; next end; puts 2 end'
jruby 9.1.6.0 (2.3.1) 2016-11-09 0150a76 Java HotSpot(TM) 64-Bit Server VM 25.102-b14 on 1.8.0_102-b14 +jit [darwin-x86_64]
1
LocalJumpError: unexpected next
<main> at -e:1
# irb -f -d -w -W
irb(main):001:0> p RUBY_VERSION
"2.3.1"
=> "2.3.1"
irb(main):002:0> p RUBY_ENGINE
"jruby"
=> "jruby"
irb(main):003:0>
irb(main):004:0* begin
irb(main):005:1* begin
irb(main):006:2* puts 1
irb(main):007:2> next
irb(main):008:2> end
irb(main):009:1> puts 2
irb(main):010:1> end
1
=> nil
irb(main):011:0>
irb(main):012:0* exit
最有趣的是,MRuby,JRuby和Rubinius实际上都同意这种行为,但与YARV不同。 YARV或其他所有都是错的。不过,我不能说出哪些。
答案 1 :(得分:1)
在Ruby 1.9时间范围内,MRI开始在分析时检测到一些非法跳转案例,而不是引发LocalJumpError。 JRuby,MRuby和Rubinius可能仍会保留跳转,并在调用时让它失败,而不是立即引发语法错误。
可能值得提交JRuby的错误。我们的解析器基本上是MRI的端口,所以我们应该能够引发相同的错误。除此之外,我们可以在编译时执行此分析,然后提出错误。