Issue #9931 has been updated by jeremyevans0 (Jeremy Evans).

Assignee set to keiju (Keiju Ishitsuka)
Status changed from Open to Assigned

This appears to still be a problem in the master branch, though the details have changed slightly.  You still need Ctrl-C to reset the state after the `x = "#{x\"}"` line:

```
irb(main):001:0> x = "#{x\"}"
irb(main):001:0> ;
irb(main):001:0> 1
irb(main):001:0> nil
irb(main):001:0> # Ctrl-D at this point has no effect
^C
irb(main):001:0> # Ctrl-D after Ctrl-C exits
```

In nested irb, you can end up with deadlock due to this:

```
irb(main):001:0> irb
irb#1(main):001:0> x = "#{x\"}"
irb#1(main):001:0>
^C
irb#1(main):001:0> exit
Traceback (most recent call last):
       16: from /home/jeremy/tmp/irb/lib/irb/ruby-lex.rb:84:in `block in each_top_level_statement'
       15: from /home/jeremy/tmp/irb/lib/irb/ruby-lex.rb:84:in `loop'
       14: from /home/jeremy/tmp/irb/lib/irb/ruby-lex.rb:99:in `block (2 levels) in each_top_level_statement'
       13: from /home/jeremy/tmp/irb/lib/irb.rb:493:in `block in eval_input'
       12: from /home/jeremy/tmp/irb/lib/irb.rb:650:in `signal_status'
       11: from /home/jeremy/tmp/irb/lib/irb.rb:496:in `block (2 levels) in eval_input'
       10: from /home/jeremy/tmp/irb/lib/irb/context.rb:404:in `evaluate'
        9: from /home/jeremy/tmp/irb/lib/irb/workspace.rb:85:in `evaluate'
        8: from /home/jeremy/tmp/irb/lib/irb/workspace.rb:85:in `eval'
        7: from (irb):1:in `irb_binding'
        6: from /home/jeremy/tmp/irb/lib/irb/extend-command.rb:154:in `irb'
        5: from /home/jeremy/tmp/irb/lib/irb/extend-command.rb:151:in `irb'
        4: from /home/jeremy/tmp/irb/lib/irb/cmd/nop.rb:20:in `execute'
        3: from /home/jeremy/tmp/irb/lib/irb/cmd/subirb.rb:20:in `execute'
        2: from /home/jeremy/tmp/irb/lib/irb/ext/multi-irb.rb:229:in `irb'
        1: from /home/jeremy/tmp/irb/lib/irb/ext/multi-irb.rb:229:in `stop'
fatal (No live threads left. Deadlock?)
1 threads, 1 sleeps current:0x000004f3ae7d1e00 main thread:0x000004f3ae7d1e00
* #<Thread:0x000004f39ef17f70 sleep_forever>
   rb_thread_t:0x000004f3ae7d1e00 native:0x000004f3d8a08000 int:0
   /home/jeremy/tmp/irb/lib/irb/ext/multi-irb.rb:229:in `stop'
   /home/jeremy/tmp/irb/lib/irb/ext/multi-irb.rb:229:in `irb'
   /home/jeremy/tmp/irb/lib/irb/cmd/subirb.rb:20:in `execute'
   /home/jeremy/tmp/irb/lib/irb/cmd/nop.rb:20:in `execute'
   /home/jeremy/tmp/irb/lib/irb/extend-command.rb:151:in `irb'
   /home/jeremy/tmp/irb/lib/irb/extend-command.rb:154:in `irb'
   (irb):1:in `irb_binding'
   /home/jeremy/tmp/irb/lib/irb/workspace.rb:85:in `eval'
   /home/jeremy/tmp/irb/lib/irb/workspace.rb:85:in `evaluate'
   /home/jeremy/tmp/irb/lib/irb/context.rb:404:in `evaluate'
   /home/jeremy/tmp/irb/lib/irb.rb:496:in `block (2 levels) in eval_input'
   /home/jeremy/tmp/irb/lib/irb.rb:650:in `signal_status'
   /home/jeremy/tmp/irb/lib/irb.rb:493:in `block in eval_input'
   /home/jeremy/tmp/irb/lib/irb/ruby-lex.rb:99:in `block (2 levels) in each_top_level_statement'
   /home/jeremy/tmp/irb/lib/irb/ruby-lex.rb:84:in `loop'
   /home/jeremy/tmp/irb/lib/irb/ruby-lex.rb:84:in `block in each_top_level_statement'
   /home/jeremy/tmp/irb/lib/irb/ruby-lex.rb:83:in `catch'
   /home/jeremy/tmp/irb/lib/irb/ruby-lex.rb:83:in `each_top_level_statement'
   /home/jeremy/tmp/irb/lib/irb.rb:492:in `eval_input'
   /home/jeremy/tmp/irb/lib/irb.rb:431:in `block in run'
   /home/jeremy/tmp/irb/lib/irb.rb:430:in `catch'
   /home/jeremy/tmp/irb/lib/irb.rb:430:in `run'
   /home/jeremy/tmp/irb/lib/irb.rb:388:in `start'
   /home/jeremy/tmp/irb/exe/irb:11:in `<main>'
Maybe IRB bug!
```

----------------------------------------
Bug #9931: irb: Really weird behavior for x = "#{x\"}" (ex: irb(main:009:-4))
https://bugs.ruby-lang.org/issues/9931#change-79306

* Author: jesserayadkins (Jesse Adkins)
* Status: Assigned
* Priority: Normal
* Assignee: keiju (Keiju Ishitsuka)
* Target version: 
* ruby -v: ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
# Our journey starts off rather simple:
irb(main):001:0> x = "#{x}"
=> ""
# Okay, makes sense.
irb(main):002:0> x = "#{x\"}"
irb(main):003:0" 
# Hmm...Still in a string? That's weird.
irb(main):003:0" "
irb(main):004:0> 
# Things seem back to normal but...
irb(main):004:0> x
# Nothing? But x is defined!
irb(main):005:0> 
# Nothing? Hmm...
irb(main):005:0> end
irb(main):006:-1> end
# Uhh...I don't think that's supposed to do that.
irb(main):007:-2> end
irb(main):008:-3> end
irb(main):009:-4> 
# ...I'm afraid to go deeper.
# Get me out of here!
irb(main):009:-4> quit
irb(main):010:-4> 
# O.O
irb(main):010:-4> ^C
irb(main):010:0> 
# ...Can I go now?
irb(main):010:0> quit
# Success!

# Additionally, if I put this in a file:
x = "#{x\"}"

# I get two syntax errors (ruby 1.9.3):
test.rb:1: syntax error, unexpected $undefined, expecting '}'
x = "#{x\"}"
         ^
test.rb:1: syntax error, unexpected $end, expecting '}'
x = "#{x\"}"
            ^




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>