rubinius/rubinius — Issue #1369: IRB completion bug
Author: Antti
Created: 2011-10-26 08:34:38+00:00
State: open

Rubinius fails when using irb/completion
This is because it tries to concat symbol to string.
IRB version in rubinius is 0.9.5, while in MRI 1.9.2 - 0.9.6. I think we need to update IRB in rubinius or split it to 18 and 19 versions.

In version 0.9.6 all .methods, .instance_methods, etc. results are converted to strings array:

```diff
--- /Users/andriy/.rvm/rubies/rbx-head/lib/irb/completion.rb	2011-10-26 11:20:49.000000000 +0300
+++ /Users/andriy/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb/completion.rb	2011-10-26 11:20:33.000000000 +0300
@@ -1,8 +1,7 @@
#
# irb/completor.rb -
# $Release Version: 0.9$
-# $Revision: 11708 $
-# $Date: 2007-02-12 15:01:19 -0800 (Mon, 12 Feb 2007) $
+# $Revision: 27327 $
# by Keiju ISHITSUKA(keiju@ishitsuka.com)
# From Original Idea of shugo@ruby-lang.org
#
@@ -12,7 +11,7 @@
module IRB
module InputCompletor

- @RCS_ID='-$Id: completion.rb 11708 2007-02-12 23:01:19Z shyouhei $-'
+ @RCS_ID='-$Id: completion.rb 27327 2010-04-13 05:01:10Z keiju $-'

ReservedWords = [
"BEGIN", "END",
@@ -45,7 +44,7 @@
receiver = $1
message = Regexp.quote($2)

- candidates = Regexp.instance_methods(true)
+ candidates = Regexp.instance_methods.collect{|m| m.to_s}
select_message(receiver, message, candidates)

when /^([^\]]*\])\.([^.]*)$/
@@ -53,7 +52,7 @@
receiver = $1
message = Regexp.quote($2)

- candidates = Array.instance_methods(true)
+ candidates = Array.instance_methods.collect{|m| m.to_s}
select_message(receiver, message, candidates)

when /^([^\}]*\})\.([^.]*)$/
@@ -61,7 +60,8 @@
receiver = $1
message = Regexp.quote($2)

- candidates = Proc.instance_methods(true) | Hash.instance_methods(true)
+ candidates = Proc.instance_methods.collect{|m| m.to_s}
+ candidates |= Hash.instance_methods.collect{|m| m.to_s}
select_message(receiver, message, candidates)

when /^(:[^:.]*)$/
@@ -77,15 +77,17 @@
when /^::([A-Z][^:\.\(]*)$/
# Absolute Constant or class methods
receiver = $1
- candidates = Object.constants
+ candidates = Object.constants.collect{|m| m.to_s}
candidates.grep(/^#{receiver}/).collect{|e| "::" + e}

- when /^(((::)?[A-Z][^:.\(]*)+)::?([^:.]*)$/
+# when /^(((::)?[A-Z][^:.\(]*)+)::?([^:.]*)$/
+ when /^([A-Z].*)::([^:.]*)$/
# Constant or class methods
receiver = $1
- message = Regexp.quote($4)
+ message = Regexp.quote($2)
begin
- candidates = eval("#{receiver}.constants | #{receiver}.methods", bind)
+ candidates = eval("#{receiver}.constants.collect{|m| m.to_s}", bind)
+ candidates |= eval("#{receiver}.methods.collect{|m| m.to_s}", bind)
rescue Exception
candidates = []
end
@@ -96,7 +98,7 @@
receiver = $1
message = Regexp.quote($2)

- candidates = Symbol.instance_methods(true)
+ candidates = Symbol.instance_methods.collect{|m| m.to_s}
select_message(receiver, message, candidates)

when /^(-?(0[dbo])?[0-9_]+(\.[0-9_]+)?([eE]-?[0-9]+)?)\.([^.]*)$/
@@ -105,7 +107,7 @@
message = Regexp.quote($5)

begin
- candidates = eval(receiver, bind).methods
+ candidates = eval(receiver, bind).methods.collect{|m| m.to_s}
rescue Exception
candidates = []
end
@@ -117,32 +119,32 @@
message = Regexp.quote($2)

begin
- candidates = eval(receiver, bind).methods
+ candidates = eval(receiver, bind).methods.collect{|m| m.to_s}
rescue Exception
candidates = []
end
select_message(receiver, message, candidates)

when /^(\$[^.]*)$/
- candidates = global_variables.grep(Regexp.new(Regexp.quote($1)))
+ regmessage = Regexp.new(Regexp.quote($1))
+ candidates = global_variables.collect{|m| m.to_s}.grep(regmessage)

# when /^(\$?(\.?[^.]+)+)\.([^.]*)$/
- when /^((\.?[^.]+)+)\.([^.]*)$/
+# when /^((\.?[^.]+)+)\.([^.]*)$/
+ when /^([^."].*)\.([^.]*)$/
# variable
receiver = $1
- message = Regexp.quote($3)
+ message = Regexp.quote($2)
+
+ gv = eval("global_variables", bind).collect{|m| m.to_s}
+ lv = eval("local_variables", bind).collect{|m| m.to_s}
+ cv = eval("self.class.constants", bind).collect{|m| m.to_s}

- gv = eval("global_variables", bind)
- lv = eval("local_variables", bind)
- cv = eval("self.class.constants", bind)
-
- if (gv | lv | cv).include?(receiver)
- # foo.func and foo is local var.
- candidates = eval("#{receiver}.methods", bind)
- elsif /^[A-Z]/ =~ receiver and /\./ !~ receiver
+ if (gv | lv | cv).include?(receiver) or /^[A-Z]/ =~ receiver && /\./ !~ receiver
+ # foo.func and foo is local var. OR
# Foo::Bar.func
begin
- candidates = eval("#{receiver}.methods", bind)
+ candidates = eval("#{receiver}.methods", bind).collect{|m| m.to_s}
rescue Exception
candidates = []
end
@@ -157,7 +159,7 @@
end
next if name != "IRB::Context" and
/^(IRB|SLex|RubyLex|RubyToken)/ =~ name
- candidates.concat m.instance_methods(false)
+ candidates.concat m.instance_methods(false).collect{|x| x.to_s}
}
candidates.sort!
candidates.uniq!
@@ -170,11 +172,11 @@
receiver = ""
message = Regexp.quote($1)

- candidates = String.instance_methods(true)
+ candidates = String.instance_methods(true).collect{|m| m.to_s}
select_message(receiver, message, candidates)

else
- candidates = eval("methods | private_methods | local_variables | self.class.constants", bind)
+ candidates = eval("methods | private_methods | local_variables | self.class.constants", bind).collect{|m| m.to_s}

(candidates|ReservedWords).grep(/^#{Regexp.quote(input)}/)
end
@@ -182,7 +184,7 @@

Operators = ["%", "&", "*", "**", "+", "-", "/",
"<", "<<", "<=", "<=>", "==", "===", "=~", ">", ">=", ">>",
- "[]", "[]=", "^",]
+ "[]", "[]=", "^", "!", "!=", "!~"]

def self.select_message(receiver, message, candidates)
candidates.grep(/^#{message}/).collect do |e|
```

Original backtrace:

```
rbx-head :001 > a.An exception occurred running irb
Coercion error: :Complex.to_str => String failed (TypeError)

Backtrace:
Rubinius::Type.coerce_to at kernel/common/type.rb:23
Kernel(String)#StringValue at kernel/common/kernel.rb:25
String#+ at kernel/common/string.rb:86
{ } in IRB::InputCompletor.select_message at .rvm/rubies/rbx-head/lib/irb
/completion.rb:191
Array#collect (map) at kernel/bootstrap/array19.rb:16
IRB::InputCompletor.select_message at .rvm/rubies/rbx-head/lib/irb
/completion.rb:188
{ } in IRB::InputCompletor.InputCompletor at .rvm/rubies/rbx-head/lib/irb
/completion.rb:165
Readline.perform_readline at readline.c
Readline(IRB::ReadlineInputMethod)#readline at .rvm/rubies/rbx-head/lib
/c-readline.rb:9
IRB::ReadlineInputMethod#gets at .rvm/rubies/rbx-head/lib/irb
/input-method.rb:97
{ } in IRB::Irb(IRB::IrbRubinius)#eval_input at .rvm/rubies/rbx-head/lib
/irb.rb:138
IRB::Irb(IRB::IrbRubinius)#signal_status at .rvm/rubies/rbx-head/lib/irb.rb:273
{ } in IRB::Irb(IRB::IrbRubinius)#eval_input at .rvm/rubies/rbx-head/lib
/irb.rb:137
RubyLex#buf_input at .rvm/rubies/rbx-head/lib/irb
/ruby-lex.rb:189
RubyLex#getc at .rvm/rubies/rbx-head/lib/irb
/ruby-lex.rb:104
IRB::SLex::Node#match_io at .rvm/rubies/rbx-head/lib/irb
/slex.rb:206
IRB::SLex#match at .rvm/rubies/rbx-head/lib/irb/slex.rb:76
RubyLex#token at .rvm/rubies/rbx-head/lib/irb
/ruby-lex.rb:287
RubyLex#lex at .rvm/rubies/rbx-head/lib/irb
/ruby-lex.rb:263
{ } in RubyLex#each_top_level_statement at .rvm/rubies/rbx-head/lib/irb
/ruby-lex.rb:234
Kernel(RubyLex)#loop at kernel/common/kernel19.rb:15
{ } in RubyLex#each_top_level_statement at .rvm/rubies/rbx-head/lib/irb
/ruby-lex.rb:230
{ } in Kernel(RubyLex)#catch at kernel/common/throw_catch.rb:29
Rubinius::ThrownValue.register at kernel/common/throw_catch.rb:8
Kernel(RubyLex)#catch at kernel/common/throw_catch.rb:28
RubyLex#each_top_level_statement at .rvm/rubies/rbx-head/lib/irb
/ruby-lex.rb:229
IRB::IrbRubinius#process_statements at .rvm/rubies/rbx-head/lib/irb
/rubinius.rb:38
IRB::Irb(IRB::IrbRubinius)#eval_input at .rvm/rubies/rbx-head/lib/irb.rb:152
{ } in IRB.start at .rvm/rubies/rbx-head/lib/irb.rb:76
{ } in Kernel(Module)#catch at kernel/common/throw_catch.rb:29
Rubinius::ThrownValue.register at kernel/common/throw_catch.rb:8
Kernel(Module)#catch at kernel/common/throw_catch.rb:28
IRB.start at .rvm/rubies/rbx-head/lib/irb.rb:75
Object#__script__ at .rvm/rubies/rbx-head/lib/bin/irb.rb:13
Rubinius::CodeLoader#load_script at kernel/delta/codeloader.rb:65
Rubinius::CodeLoader.load_script at kernel/delta/codeloader.rb:107
Rubinius::Loader#script at kernel/loader.rb:626
Rubinius::Loader#main at kernel/loader.rb:780

Caused by: undefined method `to_str' on Complex:Symbol. (NoMethodError)
```