Project

General

Profile

Actions

Bug #12493

closed

Confusing did_you_mean error

Added by tgxworld (Guo Xiang Tan) almost 8 years ago. Updated over 7 years ago.

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

Description

 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) almost 8 years ago

This is a duplicate of #12037.

Updated by shevegen (Robert A. Heiler) over 7 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 7 years ago

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

I believe this issue has been fixed: https://github.com/yuki24/did_you_mean/commit/1c52c887c62b0921e799f94bcc4a846dc7cbc057

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")'
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0