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

"end" is marked as similar #155

Closed
reedstonefood opened this issue Dec 5, 2016 · 5 comments
Closed

"end" is marked as similar #155

reedstonefood opened this issue Dec 5, 2016 · 5 comments

Comments

@reedstonefood
Copy link

This line
str << '*' * (w+2) << " #{je[4]}"
is showing as being similar to
end

Source

Am I missing something here?

@maxjacobson
Copy link
Contributor

@reedstonefood Hi, thanks for opening this issue. It's really helpful to have a reproduction case when coming across bugs like this.

I can tell you that the engine is mis-reporting the line numbers, and is actually trying to tell you that lines 95 and 96 are similar.

This file reproduces the bug:

# foo.rb
def console_output
  w = 36 # width of "card"
  str = '*' * (w+2) + "\n"
  str << '*' << self.roll_range.center(w) << "* #{je[0]}\n"
  str << '*' << @attribute["name"].capitalize.center(w) << "* #{je[1]}\n"
  str << '*' << " Symbol : #{@attribute["symbol"]} ".center(w) << "* #{je[2]}\n"
  str << '*' << " Cost : #{@attribute["cost"]} ".center(w) << "* #{je[3]}\n"
  str << '*' * (w+2) << " #{je[4]}"
  puts str.colour(ansi_colour)
end

But this one doesn't:

# foo.rb
def console_output
  w = 36 # width of "card"
  str = '*' * (w+2) + ""
  str << '*' << self.roll_range.center(w) << "* #{je[0]}"
  str << '*' << @attribute["name"].capitalize.center(w) << "* #{je[1]}"
  str << '*' << " Symbol : #{@attribute["symbol"]} ".center(w) << "* #{je[2]}"
  str << '*' << " Cost : #{@attribute["cost"]} ".center(w) << "* #{je[3]}"
  str << '*' * (w+2) << " #{je[4]}"
  puts str.colour(ansi_colour)
end

It seems to be thrown off by the newline characters in the string literals when coming up with the line numbers. We'll look into where that's happening and try to have a fix out as soon as we can.

@reedstonefood
Copy link
Author

Happy to help! The explanation makes perfect sense.

@zenspider
Copy link
Contributor

Yes, line numbers and strings (esp w/ heredocs or interpolation) are a mess.

@zenspider
Copy link
Contributor

This should be fixed with a newer version of ruby_parser:

3.8.3 / 2016-10-09

  • 1 minor enhancement:

    • Support Ruby 2.1 number literals. (soutaro)
  • 3 bug fixes:

    • Fixed line numbers for strs with backslash-newlines. (maxjacobson)
    • Improved compatibility on tokenizing number. (soutaro)
    • Refactored and fixed multiline array line numbers. (ptoomey3, with changes)

@dblandin
Copy link
Contributor

@zenspider @maxjacobson Awesome work!

@reedstonefood I'm going to go ahead and close this issue. Feel free to reopen if you're still getting the same similar to end issues.

Thanks!

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

No branches or pull requests

4 participants