Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError on assignment with a string containing special symbols using --readline #360

Closed
stoyanovskiy239 opened this issue Apr 12, 2022 · 2 comments

Comments

@stoyanovskiy239
Copy link

stoyanovskiy239 commented Apr 12, 2022

Description

Launch irb (1.2.6) with --readline option.
Execute the following:

a = '§'

Expected output:

 => "§"

Actual output:

Traceback (most recent call last):
        7: from /Users/sergey.stoyanovsky/.rvm/rubies/ruby-2.7.5/bin/irb:23:in `<main>'
        6: from /Users/sergey.stoyanovsky/.rvm/rubies/ruby-2.7.5/bin/irb:23:in `load'
        5: from /Users/sergey.stoyanovsky/.rvm/rubies/ruby-2.7.5/lib/ruby/gems/2.7.0/gems/irb-1.2.6/exe/irb:11:in `<top (required)>'
        4: from /Users/sergey.stoyanovsky/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/reline/unicode.rb:99:in `calculate_width'
        3: from /Users/sergey.stoyanovsky/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/reline/unicode.rb:99:in `scan'
        2: from /Users/sergey.stoyanovsky/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/reline/unicode.rb:108:in `block in calculate_width'
        1: from /Users/sergey.stoyanovsky/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/reline/unicode.rb:108:in `+'
TypeError (nil can't be coerced into Integer)

I suppose that output length calculation causes this since running the same assignment command after executing IRB.CurrentContext.omit_on_assignment = false before it produces proper output with no errors.

The following chain IRB::Irb#output_value -> Reline::Unicode#calculate_width -> Reline::Unicode#get_mbchar_width -> Reline.ambiguous_width leads to the uninitialized instance var @ambiguous_width, hence nil can't be coerced into Integer.

Result of irb_info

Ruby version: 2.7.5
IRB version: irb 1.2.6 (2020-09-14)
InputMethod: ReadlineInputMethod with ext/readline 8.1
.irbrc path: /Users/sergey.stoyanovsky/.rvm/rubies/ruby-2.7.5/.irbrc

Terminal Emulator

zsh

Setting Files

No ~/.irbrc.
My /Users/sergey.stoyanovsky/.rvm/rubies/ruby-2.7.5/.irbrc:

if ENV["rvm_path"].nil?
  require File.join(ENV["HOME"], "irbrc")
else
  require File.join(ENV["rvm_path"], "scripts", "irbrc")
end
@osyo-manga
Copy link
Contributor

hi.
This problem seems to have been fixed in reline 0.2.0.

reline 0.1.5

$ irb --readline
irb(main):001:0> irb_info
=>
Ruby version: 2.7.5
IRB version: irb 1.2.6 (2020-09-14)
InputMethod: ReadlineInputMethod with ext/readline 8.0 and /home/worker/.inputrc
.irbrc path: /home/worker/_irbrc

irb(main):002:0> Reline::VERSION
=> "0.1.5"
irb(main):003:0> a = '§'
Traceback (most recent call last):
        7: from /home/worker/.rbenv/versions/2.7.5/bin/irb:23:in `<main>'
        6: from /home/worker/.rbenv/versions/2.7.5/bin/irb:23:in `load'
        5: from /home/worker/.rbenv/versions/2.7.5/lib/ruby/gems/2.7.0/gems/irb-1.2.6/exe/irb:11:in `<top (required)>'
        4: from /home/worker/.rbenv/versions/2.7.5/lib/ruby/2.7.0/reline/unicode.rb:99:in `calculate_width'
        3: from /home/worker/.rbenv/versions/2.7.5/lib/ruby/2.7.0/reline/unicode.rb:99:in `scan'
        2: from /home/worker/.rbenv/versions/2.7.5/lib/ruby/2.7.0/reline/unicode.rb:108:in `block in calculate_width'
        1: from /home/worker/.rbenv/versions/2.7.5/lib/ruby/2.7.0/reline/unicode.rb:108:in `+'
TypeError (nil can't be coerced into Integer)

reline 0.2.0

$ gem install reline -v "0.2.0"
$ irb --readline
irb(main):001:0> irb_info
=>
Ruby version: 2.7.5
IRB version: irb 1.2.6 (2020-09-14)
InputMethod: ReadlineInputMethod with ext/readline 8.0 and /home/worker/.inputrc
.irbrc path: /home/worker/_irbrc

irb(main):002:0> Reline::VERSION
=> "0.2.0"
irb(main):003:0> a = '§'
=> "§"
irb(main):004:0>

Can installing reline 0.2.0 solve this problem?

$ gem install reline -v "0.2.0"

@stoyanovskiy239
Copy link
Author

Yep, with reline 0.2.0 problem appears to be solved, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants