From: shugo@... Date: 2016-11-06T15:48:38+00:00 Subject: [ruby-core:78016] [Ruby trunk Bug#12905][Rejected] tailcall_optimization not working as expected under certain condition order Issue #12905 has been updated by Shugo Maeda. Status changed from Open to Rejected Kai Sun wrote: > Below code gets stack too deep error: RubyVM::InstructionSequence.compile_option must be set before compilation of the target program, so you need eval, load, etc. ```ruby RubyVM::InstructionSequence.compile_option = { :tailcall_optimization => true, :trace_instruction => false } eval(< true, :trace_instruction => false } def run_forever(current, final) if current < final run_forever(current+1, final) else nil end end run_forever(1, Float::INFINITY) ~~~ However, below code works as expected: ~~~ ruby RubyVM::InstructionSequence.compile_option = { :tailcall_optimization => true, :trace_instruction => false } def run_forever(current, final) if current >= final nil else run_forever(current+1, final) end end run_forever(1, Float::INFINITY) ~~~ Thanks for looking at this :) -- https://bugs.ruby-lang.org/ Unsubscribe: