Bug #12493


Confusing did_you_mean error

Added by tgxworld (Guo Xiang Tan) over 5 years ago. Updated over 5 years ago.

Third Party's Issue
Target version:
ruby -v:
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]


 irb(main):001:0> test = some_string if (some_string = "test")
(irb):1: warning: found = in conditional, should be ==
NameError: undefined local variable or method `some_string' for main:Object
Did you mean?  some_string
    from (irb):1
    from /home/tgxworld/.rbenv/versions/2.3.1/bin/irb:11:in `<main>'

I think assignment in a one liner if statement isn't encouraged but I found the suggestion to be quite confusing.

Updated by sawa (Tsuyoshi Sawada) over 5 years ago

This is a duplicate of #12037.

Updated by shevegen (Robert A. Heiler) over 5 years ago

I guess the trivial fix would be to:

"if the name would be the same name, do not suggest an alternative name"

(since the alternative name would be == to the reported name)

Has someone reported this on the github issue tracker for the did you mean it gem? Perhaps the gem author has not yet seen this report here.

I think assignment in a one liner if statement isn't encouraged

Yeah it is not encouraged but typos happen :-)

The did-you-mean-it gem even can work via typos like "def intialize", I think I
mentioned this once years ago. It is funny that someone else took the effort to
correct it. :-)

Perhaps we get better fine-tuned control of error or actually warning messages
in ruby 3.x era.

Updated by yuki24 (Yuki Nishijima) over 5 years ago

  • Assignee set to yuki24 (Yuki Nishijima)
  • Status changed from Open to Third Party's Issue

I believe this issue has been fixed:

Could you try installing 1.0.2 of the did_you_mean gem and see if it fixes your issue?

$ gem i did_you_mean -v=1.0.2
$ ruby -e'test = some_string if (some_string = "test")'

Also available in: Atom PDF